Merge lp:~fboucault/webbrowser-app/address_bar_populate_selected_suggestion into lp:webbrowser-app/staging

Proposed by Florian Boucault
Status: Needs review
Proposed branch: lp:~fboucault/webbrowser-app/address_bar_populate_selected_suggestion
Merge into: lp:webbrowser-app/staging
Prerequisite: lp:~osomon/webbrowser-app/qmltests
Diff against target: 349 lines (+125/-47)
4 files modified
src/app/webbrowser/Browser.qml (+47/-3)
src/app/webbrowser/NavigationBar.qml (+1/-1)
src/app/webbrowser/Suggestions.qml (+9/-1)
tests/qmltests/webbrowser-app/tst_Suggestions.qml (+68/-42)
To merge this branch: bzr merge lp:~fboucault/webbrowser-app/address_bar_populate_selected_suggestion
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+321828@code.launchpad.net

Commit message

Address bar suggestions:
* When highlighting a suggestion, copy it to the address bar.
* Preserve search suggestions when going up/down
* Add static search suggestion as first element

Description of the change

Address bar suggestions:
* When highlighting a suggestion, copy it to the address bar.
* Preserve search suggestions when going up/down
* Add static search suggestion as first element

To post a comment you must log in.
1652. By Florian Boucault

Merged qmltests

1653. By Florian Boucault

More reliable test Suggestions::test_list_of_suggestions_limits

1654. By Florian Boucault

Merged qmltests

1655. By Florian Boucault

Removed rev 1653

1656. By Florian Boucault

Merged lp:~osomon/webbrowser-app/qmltests

1657. By Florian Boucault

Fix failing tests

Unmerged revisions

1657. By Florian Boucault

Fix failing tests

1656. By Florian Boucault

Merged lp:~osomon/webbrowser-app/qmltests

1655. By Florian Boucault

Removed rev 1653

1654. By Florian Boucault

Merged qmltests

1653. By Florian Boucault

More reliable test Suggestions::test_list_of_suggestions_limits

1652. By Florian Boucault

Merged qmltests

1651. By Florian Boucault

Add static search suggestion as first element

1650. By Florian Boucault

Cleaner

1649. By Florian Boucault

Preserve search suggestions when going up/down

1648. By Florian Boucault

First step: when highlighting a suggestion, copy it to the address bar.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/app/webbrowser/Browser.qml'
--- src/app/webbrowser/Browser.qml 2017-04-05 08:33:43 +0000
+++ src/app/webbrowser/Browser.qml 2017-04-05 08:33:45 +0000
@@ -671,13 +671,57 @@
671 width: chrome.width - units.gu(5)671 width: chrome.width - units.gu(5)
672 height: enabled ? Math.min(contentHeight, tabContainer.height - chrome.height - units.gu(2)) : 0672 height: enabled ? Math.min(contentHeight, tabContainer.height - chrome.height - units.gu(2)) : 0
673673
674 searchTerms: chrome.text.split(/\s+/g).filter(function(term) { return term.length > 0 })674 property string searchText
675 searchTerms: searchText.split(/\s+/g).filter(function(term) { return term.length > 0 })
676
677 // Use text input in the address bar as search terms
678 Connections {
679 target: chrome
680 onTextChanged: {
681 if (!suggestionsList.activeFocus) {
682 suggestionsList.searchText = chrome.text;
683 }
684 }
685 }
686
687 // When navigating the suggestion list, fill in the address bar
688 // with the selected suggestion
689 Connections {
690 target: suggestionsList
691 onActiveFocusChanged: {
692 if (suggestionsList.activeFocus) {
693 chrome.text = suggestionsList.selectedSuggestionText;
694 }
695 }
696 onSelectedSuggestionTextChanged: {
697 if (suggestionsList.activeFocus) {
698 chrome.text = suggestionsList.selectedSuggestionText;
699 }
700 }
701 }
675702
676 Keys.onUpPressed: chrome.focus = true703 Keys.onUpPressed: chrome.focus = true
677 Keys.onEscapePressed: internal.resetFocus()704 Keys.onEscapePressed: internal.resetFocus()
678705
706 function escapeHtmlEntities(query) {
707 return query.replace(/\W/g, encodeURIComponent)
708 }
709
710 function buildSearchUrl(query) {
711 var terms = query.split(/\s/).map(escapeHtmlEntities);
712 return chrome.searchUrl.replace("{searchTerms}", terms.join("+"));
713 }
714
715 property var searchTextModel: {
716 var model = [{"title": suggestionsList.searchText,
717 "url": suggestionsList.buildSearchUrl(suggestionsList.searchText)}];
718 model.icon = 'search';
719 return model;
720 }
721
679 models: searchTerms && searchTerms.length > 0 ?722 models: searchTerms && searchTerms.length > 0 ?
680 [historySuggestions,723 [searchTextModel,
724 historySuggestions,
681 bookmarksSuggestions,725 bookmarksSuggestions,
682 searchSuggestions.limit(4)] : []726 searchSuggestions.limit(4)] : []
683727
@@ -711,7 +755,7 @@
711 searchEngine: currentSearchEngine755 searchEngine: currentSearchEngine
712 active: (chrome.activeFocus || suggestionsList.activeFocus) &&756 active: (chrome.activeFocus || suggestionsList.activeFocus) &&
713 !browser.incognito && !chrome.findInPageMode &&757 !browser.incognito && !chrome.findInPageMode &&
714 !UrlUtils.looksLikeAUrl(chrome.text.replace(/ /g, "+"))758 !UrlUtils.looksLikeAUrl(suggestionsList.searchText.replace(/ /g, "+"))
715759
716 function limit(number) {760 function limit(number) {
717 var slice = results.slice(0, number)761 var slice = results.slice(0, number)
718762
=== modified file 'src/app/webbrowser/NavigationBar.qml'
--- src/app/webbrowser/NavigationBar.qml 2017-02-03 15:11:00 +0000
+++ src/app/webbrowser/NavigationBar.qml 2017-04-05 08:33:45 +0000
@@ -26,7 +26,7 @@
26 property var tab26 property var tab
27 property alias loading: addressbar.loading27 property alias loading: addressbar.loading
28 property alias searchUrl: addressbar.searchUrl28 property alias searchUrl: addressbar.searchUrl
29 readonly property string text: addressbar.text29 property alias text: addressbar.text
30 property alias bookmarked: addressbar.bookmarked30 property alias bookmarked: addressbar.bookmarked
31 signal toggleBookmark()31 signal toggleBookmark()
32 property list<Action> drawerActions32 property list<Action> drawerActions
3333
=== modified file 'src/app/webbrowser/Suggestions.qml'
--- src/app/webbrowser/Suggestions.qml 2016-11-18 15:10:47 +0000
+++ src/app/webbrowser/Suggestions.qml 2017-04-05 08:33:45 +0000
@@ -23,8 +23,9 @@
23FocusScope {23FocusScope {
24 id: suggestions24 id: suggestions
2525
26 property var searchTerms26 property var searchTerms: []
27 property var models27 property var models
28 property string selectedSuggestionText
2829
29 readonly property int count: models.reduce(internal.countItems, 0)30 readonly property int count: models.reduce(internal.countItems, 0)
30 readonly property alias contentHeight: suggestionsList.contentHeight31 readonly property alias contentHeight: suggestionsList.contentHeight
@@ -77,6 +78,13 @@
77 Highlight.highlightTerms(modelData.url, searchTerms)) : ""78 Highlight.highlightTerms(modelData.url, searchTerms)) : ""
78 icon: modelData.icon || ""79 icon: modelData.icon || ""
79 selected: suggestionsList.activeFocus && ListView.isCurrentItem80 selected: suggestionsList.activeFocus && ListView.isCurrentItem
81 onSelectedChanged: {
82 if (modelData.displayUrl) {
83 suggestions.selectedSuggestionText = modelData.url;
84 } else {
85 suggestions.selectedSuggestionText = modelData.title;
86 }
87 }
8088
81 onActivated: suggestions.activated(modelData.url)89 onActivated: suggestions.activated(modelData.url)
82 }90 }
8391
=== modified file 'tests/qmltests/webbrowser-app/tst_Suggestions.qml'
--- tests/qmltests/webbrowser-app/tst_Suggestions.qml 2017-04-05 08:33:43 +0000
+++ tests/qmltests/webbrowser-app/tst_Suggestions.qml 2017-04-05 08:33:45 +0000
@@ -42,7 +42,6 @@
42 function get_suggestion(index) {42 function get_suggestion(index) {
43 var suggestion =43 var suggestion =
44 expectChild(get_suggestions(), "suggestionDelegate_%1".arg(index));44 expectChild(get_suggestions(), "suggestionDelegate_%1".arg(index));
45 waitForRendering(suggestion);
46 return suggestion;45 return suggestion;
47 }46 }
4847
@@ -56,7 +55,7 @@
56 assert_suggestions_eventually_hidden();55 assert_suggestions_eventually_hidden();
57 focus_address_bar(false);56 focus_address_bar(false);
58 assert_suggestions_eventually_shown();57 assert_suggestions_eventually_shown();
59 tryCompare(suggestions, "count", 1);58 tryCompare(suggestions, "count", 2);
60 clear_address_bar();59 clear_address_bar();
61 assert_suggestions_eventually_hidden();60 assert_suggestions_eventually_hidden();
62 }61 }
@@ -66,7 +65,7 @@
66 var addressbar = focus_address_bar(true);65 var addressbar = focus_address_bar(true);
67 typeString("SpEciAl");66 typeString("SpEciAl");
68 tryCompare(addressbar, "text", "SpEciAl");67 tryCompare(addressbar, "text", "SpEciAl");
69 tryCompare(suggestions, "count", 1);68 tryCompare(suggestions, "count", 2);
70 }69 }
7170
72 function test_list_of_suggestions_limits_data() {71 function test_list_of_suggestions_limits_data() {
@@ -82,14 +81,14 @@
82 typeString(data.strings[0]);81 typeString(data.strings[0]);
83 tryCompare(addressbar, "text", data.strings[0]);82 tryCompare(addressbar, "text", data.strings[0]);
84 assert_suggestions_eventually_shown();83 assert_suggestions_eventually_shown();
85 tryCompare(suggestions, "count", 2);84 tryCompare(suggestions, "count", 3);
86 typeString(data.strings[1]);85 typeString(data.strings[1]);
87 tryCompare(addressbar, "text", data.strings[0] + data.strings[1]);86 tryCompare(addressbar, "text", data.strings[0] + data.strings[1]);
88 tryCompare(suggestions, "count", 0);87 tryCompare(suggestions, "count", 1);
89 clear_address_bar();88 clear_address_bar();
90 typeString(data.strings[2]);89 typeString(data.strings[2]);
91 tryCompare(addressbar, "text", data.strings[2]);90 tryCompare(addressbar, "text", data.strings[2]);
92 tryCompare(suggestions, "count", 1);91 tryCompare(suggestions, "count", 2);
93 }92 }
9493
95 function test_list_of_suggestions_search_limits() {94 function test_list_of_suggestions_search_limits() {
@@ -98,10 +97,10 @@
98 typeString("foo");97 typeString("foo");
99 tryCompare(addressbar, "text", "foo");98 tryCompare(addressbar, "text", "foo");
100 assert_suggestions_eventually_shown();99 assert_suggestions_eventually_shown();
101 tryCompare(suggestions, "count", 4);100 tryCompare(suggestions, "count", 5);
102 typeString("bleh");101 typeString("bleh");
103 tryCompare(addressbar, "text", "foobleh");102 tryCompare(addressbar, "text", "foobleh");
104 tryCompare(suggestions, "count", 0);103 tryCompare(suggestions, "count", 1);
105 }104 }
106105
107 function test_list_of_suggestions_order() {106 function test_list_of_suggestions_order() {
@@ -110,10 +109,11 @@
110 typeString("QML");109 typeString("QML");
111 tryCompare(addressbar, "text", "QML");110 tryCompare(addressbar, "text", "QML");
112 assert_suggestions_eventually_shown();111 assert_suggestions_eventually_shown();
113 tryCompare(suggestions, "count", 5);112 tryCompare(suggestions, "count", 6);
114 compare(get_suggestion(0).icon, "history");113 compare(get_suggestion(0).icon, "search");
115 compare(get_suggestion(1).icon, "non-starred");114 compare(get_suggestion(1).icon, "history");
116 compare(get_suggestion(2).icon, "search");115 compare(get_suggestion(2).icon, "non-starred");
116 compare(get_suggestion(3).icon, "search");
117 }117 }
118118
119 function test_clear_address_bar_dismisses_suggestions() {119 function test_clear_address_bar_dismisses_suggestions() {
@@ -145,14 +145,25 @@
145 assert_suggestions_eventually_shown();145 assert_suggestions_eventually_shown();
146 }146 }
147147
148 function test_select_raw_search() {
149 var suggestions = get_suggestions();
150 focus_address_bar(true);
151 typeString("high");
152 assert_suggestions_eventually_shown();
153 tryCompare(suggestions, "count", 2);
154 clickItem(get_suggestion(0));
155 assert_suggestions_eventually_hidden();
156 tryCompare(window.currentWebview, "url", "http://aserver.somewhere/search?q=high");
157 }
158
148 function test_select_suggestion() {159 function test_select_suggestion() {
149 var suggestions = get_suggestions();160 var suggestions = get_suggestions();
150 var addressbar = focus_address_bar(true);161 var addressbar = focus_address_bar(true);
151 typeString("linux");162 typeString("linux");
152 tryCompare(addressbar, "text", "linux");163 tryCompare(addressbar, "text", "linux");
153 assert_suggestions_eventually_shown();164 assert_suggestions_eventually_shown();
154 tryCompare(suggestions, "count", 1);165 tryCompare(suggestions, "count", 2);
155 clickItem(get_suggestion(0));166 clickItem(get_suggestion(1));
156 assert_suggestions_eventually_hidden();167 assert_suggestions_eventually_hidden();
157 tryCompare(window.currentWebview, "url", "http://test/wiki/Linux");168 tryCompare(window.currentWebview, "url", "http://test/wiki/Linux");
158 }169 }
@@ -163,8 +174,8 @@
163 typeString("high");174 typeString("high");
164 tryCompare(addressbar, "text", "high");175 tryCompare(addressbar, "text", "high");
165 assert_suggestions_eventually_shown();176 assert_suggestions_eventually_shown();
166 tryCompare(suggestions, "count", 1);177 tryCompare(suggestions, "count", 2);
167 clickItem(get_suggestion(0));178 clickItem(get_suggestion(1));
168 assert_suggestions_eventually_hidden();179 assert_suggestions_eventually_hidden();
169 tryCompare(window.currentWebview, "url", "http://aserver.somewhere/search?q=highlight");180 tryCompare(window.currentWebview, "url", "http://aserver.somewhere/search?q=highlight");
170 }181 }
@@ -175,8 +186,8 @@
175 typeString("(phil");186 typeString("(phil");
176 tryCompare(addressbar, "text", "(phil");187 tryCompare(addressbar, "text", "(phil");
177 assert_suggestions_eventually_shown();188 assert_suggestions_eventually_shown();
178 tryCompare(suggestions, "count", 1);189 tryCompare(suggestions, "count", 2);
179 var suggestion = get_suggestion(0);190 var suggestion = get_suggestion(1);
180 compare(unhighlight(suggestion.title),191 compare(unhighlight(suggestion.title),
181 "Ubuntu (philosophy) - Wikipedia, the free encyclopedia");192 "Ubuntu (philosophy) - Wikipedia, the free encyclopedia");
182 compare(unhighlight(suggestion.subtitle),193 compare(unhighlight(suggestion.subtitle),
@@ -189,10 +200,13 @@
189 typeString("high");200 typeString("high");
190 tryCompare(addressbar, "text", "high");201 tryCompare(addressbar, "text", "high");
191 assert_suggestions_eventually_shown();202 assert_suggestions_eventually_shown();
192 tryCompare(suggestions, "count", 1);203 tryCompare(suggestions, "count", 2);
193 var suggestion = get_suggestion(0);204 var suggestion1 = get_suggestion(0);
194 compare(unhighlight(suggestion.title), "highlight");205 compare(unhighlight(suggestion1.title), "high");
195 compare(suggestion.subtitle, "");206 compare(suggestion1.subtitle, "");
207 var suggestion2 = get_suggestion(1);
208 compare(unhighlight(suggestion2.title), "highlight");
209 compare(suggestion2.subtitle, "");
196 }210 }
197211
198 function test_keyboard_navigation() {212 function test_keyboard_navigation() {
@@ -201,36 +215,45 @@
201 typeString("element");215 typeString("element");
202 tryCompare(addressbar, "text", "element");216 tryCompare(addressbar, "text", "element");
203 assert_suggestions_eventually_shown();217 assert_suggestions_eventually_shown();
204 tryCompare(suggestions, "count", 2);218 tryCompare(suggestions, "count", 3);
205 var suggestion1 = get_suggestion(0);219 var suggestion1 = get_suggestion(0);
206 var suggestion2 = get_suggestion(1);220 var suggestion2 = get_suggestion(1);
207 verify(!suggestion1.selected);221 verify(!suggestion1.selected);
208 verify(!suggestion2.selected);222 verify(!suggestion2.selected);
209223
210 keyClick(Qt.Key_Down);224 keyClick(Qt.Key_Down);
225 tryCompare(get_suggestions(), "count", 3);
211 tryCompare(addressbar, "activeFocus", false);226 tryCompare(addressbar, "activeFocus", false);
212 tryCompare(suggestions, "activeFocus", true);227 tryCompare(get_suggestions(), "activeFocus", true);
213 tryCompare(suggestion1, "selected", true);228 tryCompare(get_suggestion(0), "selected", true);
214 verify(!suggestion2.selected);229 tryCompare(addressbar, "text", get_suggestion(0).title);
230 verify(!get_suggestion(1).selected);
215231
216 keyClick(Qt.Key_Down);232 keyClick(Qt.Key_Down);
217 tryCompare(suggestion1, "selected", false);233 tryCompare(get_suggestions(), "count", 3);
218 tryCompare(suggestion2, "selected", true);234 tryCompare(get_suggestion(0), "selected", false);
235 tryCompare(get_suggestion(1), "selected", true);
236 tryCompare(addressbar, "text", get_suggestion(1).subtitle);
219237
220 // Verify that selection does not wrap around238 // Verify that selection does not wrap around
221 keyClick(Qt.Key_Down);239 keyClick(Qt.Key_Down);
222 verify(!suggestion1.selected);240 keyClick(Qt.Key_Down);
223 verify(suggestion2.selected);241 verify(!get_suggestion(0).selected);
224242 verify(!get_suggestion(1).selected);
225 keyClick(Qt.Key_Up);243 verify(get_suggestion(2).selected);
226 tryCompare(suggestion1, "selected", true);244
227 tryCompare(suggestion2, "selected", false);245 keyClick(Qt.Key_Up);
228246 keyClick(Qt.Key_Up);
229 keyClick(Qt.Key_Up);247 tryCompare(get_suggestions(), "count", 3);
248 tryCompare(get_suggestion(0), "selected", false);
249 tryCompare(get_suggestion(1), "selected", false);
250
251 keyClick(Qt.Key_Up);
252 tryCompare(get_suggestions(), "count", 3);
230 tryCompare(addressbar, "activeFocus", true);253 tryCompare(addressbar, "activeFocus", true);
231 tryCompare(suggestions, "activeFocus", false);254 tryCompare(get_suggestions(), "activeFocus", false);
232 tryCompare(suggestion1, "selected", false);255 tryCompare(get_suggestion(0), "selected", false);
233 tryCompare(suggestion2, "selected", false);256 tryCompare(get_suggestion(1), "selected", false);
234 }257 }
235258
236 function test_suggestions_escape() {259 function test_suggestions_escape() {
@@ -242,10 +265,11 @@
242 typeString("element");265 typeString("element");
243 tryCompare(addressbar, "text", "element");266 tryCompare(addressbar, "text", "element");
244 assert_suggestions_eventually_shown();267 assert_suggestions_eventually_shown();
245 tryCompare(suggestions, "count", 2);268 tryCompare(suggestions, "count", 3);
246 keyClick(Qt.Key_Down);269 keyClick(Qt.Key_Down);
247 tryCompare(suggestions, "activeFocus", true);270 tryCompare(suggestions, "activeFocus", true);
248 tryCompare(addressbar, "text", "element");271 var suggestion1 = get_suggestion(0);
272 tryCompare(addressbar, "text", suggestion1.title);
249 keyClick(Qt.Key_Escape);273 keyClick(Qt.Key_Escape);
250 assert_suggestions_eventually_hidden();274 assert_suggestions_eventually_hidden();
251 tryCompare(addressbar, "text", text);275 tryCompare(addressbar, "text", text);
@@ -260,9 +284,11 @@
260 typeString("element");284 typeString("element");
261 tryCompare(addressbar, "text", "element");285 tryCompare(addressbar, "text", "element");
262 assert_suggestions_eventually_shown();286 assert_suggestions_eventually_shown();
263 tryCompare(suggestions, "count", 2);287 tryCompare(suggestions, "count", 3);
264 keyClick(Qt.Key_Down);288 keyClick(Qt.Key_Down);
265 tryCompare(suggestions, "activeFocus", true);289 tryCompare(suggestions, "activeFocus", true);
290 var suggestion1 = get_suggestion(0);
291 tryCompare(addressbar, "text", suggestion1.title);
266 keyClick(Qt.Key_Up);292 keyClick(Qt.Key_Up);
267 tryCompare(addressbar, "activeFocus", true);293 tryCompare(addressbar, "activeFocus", true);
268 keyClick(Qt.Key_Escape);294 keyClick(Qt.Key_Escape);

Subscribers

People subscribed via source and target branches