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
1=== modified file 'src/app/webbrowser/Browser.qml'
2--- src/app/webbrowser/Browser.qml 2017-04-05 08:33:43 +0000
3+++ src/app/webbrowser/Browser.qml 2017-04-05 08:33:45 +0000
4@@ -671,13 +671,57 @@
5 width: chrome.width - units.gu(5)
6 height: enabled ? Math.min(contentHeight, tabContainer.height - chrome.height - units.gu(2)) : 0
7
8- searchTerms: chrome.text.split(/\s+/g).filter(function(term) { return term.length > 0 })
9+ property string searchText
10+ searchTerms: searchText.split(/\s+/g).filter(function(term) { return term.length > 0 })
11+
12+ // Use text input in the address bar as search terms
13+ Connections {
14+ target: chrome
15+ onTextChanged: {
16+ if (!suggestionsList.activeFocus) {
17+ suggestionsList.searchText = chrome.text;
18+ }
19+ }
20+ }
21+
22+ // When navigating the suggestion list, fill in the address bar
23+ // with the selected suggestion
24+ Connections {
25+ target: suggestionsList
26+ onActiveFocusChanged: {
27+ if (suggestionsList.activeFocus) {
28+ chrome.text = suggestionsList.selectedSuggestionText;
29+ }
30+ }
31+ onSelectedSuggestionTextChanged: {
32+ if (suggestionsList.activeFocus) {
33+ chrome.text = suggestionsList.selectedSuggestionText;
34+ }
35+ }
36+ }
37
38 Keys.onUpPressed: chrome.focus = true
39 Keys.onEscapePressed: internal.resetFocus()
40
41+ function escapeHtmlEntities(query) {
42+ return query.replace(/\W/g, encodeURIComponent)
43+ }
44+
45+ function buildSearchUrl(query) {
46+ var terms = query.split(/\s/).map(escapeHtmlEntities);
47+ return chrome.searchUrl.replace("{searchTerms}", terms.join("+"));
48+ }
49+
50+ property var searchTextModel: {
51+ var model = [{"title": suggestionsList.searchText,
52+ "url": suggestionsList.buildSearchUrl(suggestionsList.searchText)}];
53+ model.icon = 'search';
54+ return model;
55+ }
56+
57 models: searchTerms && searchTerms.length > 0 ?
58- [historySuggestions,
59+ [searchTextModel,
60+ historySuggestions,
61 bookmarksSuggestions,
62 searchSuggestions.limit(4)] : []
63
64@@ -711,7 +755,7 @@
65 searchEngine: currentSearchEngine
66 active: (chrome.activeFocus || suggestionsList.activeFocus) &&
67 !browser.incognito && !chrome.findInPageMode &&
68- !UrlUtils.looksLikeAUrl(chrome.text.replace(/ /g, "+"))
69+ !UrlUtils.looksLikeAUrl(suggestionsList.searchText.replace(/ /g, "+"))
70
71 function limit(number) {
72 var slice = results.slice(0, number)
73
74=== modified file 'src/app/webbrowser/NavigationBar.qml'
75--- src/app/webbrowser/NavigationBar.qml 2017-02-03 15:11:00 +0000
76+++ src/app/webbrowser/NavigationBar.qml 2017-04-05 08:33:45 +0000
77@@ -26,7 +26,7 @@
78 property var tab
79 property alias loading: addressbar.loading
80 property alias searchUrl: addressbar.searchUrl
81- readonly property string text: addressbar.text
82+ property alias text: addressbar.text
83 property alias bookmarked: addressbar.bookmarked
84 signal toggleBookmark()
85 property list<Action> drawerActions
86
87=== modified file 'src/app/webbrowser/Suggestions.qml'
88--- src/app/webbrowser/Suggestions.qml 2016-11-18 15:10:47 +0000
89+++ src/app/webbrowser/Suggestions.qml 2017-04-05 08:33:45 +0000
90@@ -23,8 +23,9 @@
91 FocusScope {
92 id: suggestions
93
94- property var searchTerms
95+ property var searchTerms: []
96 property var models
97+ property string selectedSuggestionText
98
99 readonly property int count: models.reduce(internal.countItems, 0)
100 readonly property alias contentHeight: suggestionsList.contentHeight
101@@ -77,6 +78,13 @@
102 Highlight.highlightTerms(modelData.url, searchTerms)) : ""
103 icon: modelData.icon || ""
104 selected: suggestionsList.activeFocus && ListView.isCurrentItem
105+ onSelectedChanged: {
106+ if (modelData.displayUrl) {
107+ suggestions.selectedSuggestionText = modelData.url;
108+ } else {
109+ suggestions.selectedSuggestionText = modelData.title;
110+ }
111+ }
112
113 onActivated: suggestions.activated(modelData.url)
114 }
115
116=== modified file 'tests/qmltests/webbrowser-app/tst_Suggestions.qml'
117--- tests/qmltests/webbrowser-app/tst_Suggestions.qml 2017-04-05 08:33:43 +0000
118+++ tests/qmltests/webbrowser-app/tst_Suggestions.qml 2017-04-05 08:33:45 +0000
119@@ -42,7 +42,6 @@
120 function get_suggestion(index) {
121 var suggestion =
122 expectChild(get_suggestions(), "suggestionDelegate_%1".arg(index));
123- waitForRendering(suggestion);
124 return suggestion;
125 }
126
127@@ -56,7 +55,7 @@
128 assert_suggestions_eventually_hidden();
129 focus_address_bar(false);
130 assert_suggestions_eventually_shown();
131- tryCompare(suggestions, "count", 1);
132+ tryCompare(suggestions, "count", 2);
133 clear_address_bar();
134 assert_suggestions_eventually_hidden();
135 }
136@@ -66,7 +65,7 @@
137 var addressbar = focus_address_bar(true);
138 typeString("SpEciAl");
139 tryCompare(addressbar, "text", "SpEciAl");
140- tryCompare(suggestions, "count", 1);
141+ tryCompare(suggestions, "count", 2);
142 }
143
144 function test_list_of_suggestions_limits_data() {
145@@ -82,14 +81,14 @@
146 typeString(data.strings[0]);
147 tryCompare(addressbar, "text", data.strings[0]);
148 assert_suggestions_eventually_shown();
149- tryCompare(suggestions, "count", 2);
150+ tryCompare(suggestions, "count", 3);
151 typeString(data.strings[1]);
152 tryCompare(addressbar, "text", data.strings[0] + data.strings[1]);
153- tryCompare(suggestions, "count", 0);
154+ tryCompare(suggestions, "count", 1);
155 clear_address_bar();
156 typeString(data.strings[2]);
157 tryCompare(addressbar, "text", data.strings[2]);
158- tryCompare(suggestions, "count", 1);
159+ tryCompare(suggestions, "count", 2);
160 }
161
162 function test_list_of_suggestions_search_limits() {
163@@ -98,10 +97,10 @@
164 typeString("foo");
165 tryCompare(addressbar, "text", "foo");
166 assert_suggestions_eventually_shown();
167- tryCompare(suggestions, "count", 4);
168+ tryCompare(suggestions, "count", 5);
169 typeString("bleh");
170 tryCompare(addressbar, "text", "foobleh");
171- tryCompare(suggestions, "count", 0);
172+ tryCompare(suggestions, "count", 1);
173 }
174
175 function test_list_of_suggestions_order() {
176@@ -110,10 +109,11 @@
177 typeString("QML");
178 tryCompare(addressbar, "text", "QML");
179 assert_suggestions_eventually_shown();
180- tryCompare(suggestions, "count", 5);
181- compare(get_suggestion(0).icon, "history");
182- compare(get_suggestion(1).icon, "non-starred");
183- compare(get_suggestion(2).icon, "search");
184+ tryCompare(suggestions, "count", 6);
185+ compare(get_suggestion(0).icon, "search");
186+ compare(get_suggestion(1).icon, "history");
187+ compare(get_suggestion(2).icon, "non-starred");
188+ compare(get_suggestion(3).icon, "search");
189 }
190
191 function test_clear_address_bar_dismisses_suggestions() {
192@@ -145,14 +145,25 @@
193 assert_suggestions_eventually_shown();
194 }
195
196+ function test_select_raw_search() {
197+ var suggestions = get_suggestions();
198+ focus_address_bar(true);
199+ typeString("high");
200+ assert_suggestions_eventually_shown();
201+ tryCompare(suggestions, "count", 2);
202+ clickItem(get_suggestion(0));
203+ assert_suggestions_eventually_hidden();
204+ tryCompare(window.currentWebview, "url", "http://aserver.somewhere/search?q=high");
205+ }
206+
207 function test_select_suggestion() {
208 var suggestions = get_suggestions();
209 var addressbar = focus_address_bar(true);
210 typeString("linux");
211 tryCompare(addressbar, "text", "linux");
212 assert_suggestions_eventually_shown();
213- tryCompare(suggestions, "count", 1);
214- clickItem(get_suggestion(0));
215+ tryCompare(suggestions, "count", 2);
216+ clickItem(get_suggestion(1));
217 assert_suggestions_eventually_hidden();
218 tryCompare(window.currentWebview, "url", "http://test/wiki/Linux");
219 }
220@@ -163,8 +174,8 @@
221 typeString("high");
222 tryCompare(addressbar, "text", "high");
223 assert_suggestions_eventually_shown();
224- tryCompare(suggestions, "count", 1);
225- clickItem(get_suggestion(0));
226+ tryCompare(suggestions, "count", 2);
227+ clickItem(get_suggestion(1));
228 assert_suggestions_eventually_hidden();
229 tryCompare(window.currentWebview, "url", "http://aserver.somewhere/search?q=highlight");
230 }
231@@ -175,8 +186,8 @@
232 typeString("(phil");
233 tryCompare(addressbar, "text", "(phil");
234 assert_suggestions_eventually_shown();
235- tryCompare(suggestions, "count", 1);
236- var suggestion = get_suggestion(0);
237+ tryCompare(suggestions, "count", 2);
238+ var suggestion = get_suggestion(1);
239 compare(unhighlight(suggestion.title),
240 "Ubuntu (philosophy) - Wikipedia, the free encyclopedia");
241 compare(unhighlight(suggestion.subtitle),
242@@ -189,10 +200,13 @@
243 typeString("high");
244 tryCompare(addressbar, "text", "high");
245 assert_suggestions_eventually_shown();
246- tryCompare(suggestions, "count", 1);
247- var suggestion = get_suggestion(0);
248- compare(unhighlight(suggestion.title), "highlight");
249- compare(suggestion.subtitle, "");
250+ tryCompare(suggestions, "count", 2);
251+ var suggestion1 = get_suggestion(0);
252+ compare(unhighlight(suggestion1.title), "high");
253+ compare(suggestion1.subtitle, "");
254+ var suggestion2 = get_suggestion(1);
255+ compare(unhighlight(suggestion2.title), "highlight");
256+ compare(suggestion2.subtitle, "");
257 }
258
259 function test_keyboard_navigation() {
260@@ -201,36 +215,45 @@
261 typeString("element");
262 tryCompare(addressbar, "text", "element");
263 assert_suggestions_eventually_shown();
264- tryCompare(suggestions, "count", 2);
265+ tryCompare(suggestions, "count", 3);
266 var suggestion1 = get_suggestion(0);
267 var suggestion2 = get_suggestion(1);
268 verify(!suggestion1.selected);
269 verify(!suggestion2.selected);
270
271 keyClick(Qt.Key_Down);
272+ tryCompare(get_suggestions(), "count", 3);
273 tryCompare(addressbar, "activeFocus", false);
274- tryCompare(suggestions, "activeFocus", true);
275- tryCompare(suggestion1, "selected", true);
276- verify(!suggestion2.selected);
277+ tryCompare(get_suggestions(), "activeFocus", true);
278+ tryCompare(get_suggestion(0), "selected", true);
279+ tryCompare(addressbar, "text", get_suggestion(0).title);
280+ verify(!get_suggestion(1).selected);
281
282 keyClick(Qt.Key_Down);
283- tryCompare(suggestion1, "selected", false);
284- tryCompare(suggestion2, "selected", true);
285+ tryCompare(get_suggestions(), "count", 3);
286+ tryCompare(get_suggestion(0), "selected", false);
287+ tryCompare(get_suggestion(1), "selected", true);
288+ tryCompare(addressbar, "text", get_suggestion(1).subtitle);
289
290 // Verify that selection does not wrap around
291 keyClick(Qt.Key_Down);
292- verify(!suggestion1.selected);
293- verify(suggestion2.selected);
294-
295- keyClick(Qt.Key_Up);
296- tryCompare(suggestion1, "selected", true);
297- tryCompare(suggestion2, "selected", false);
298-
299- keyClick(Qt.Key_Up);
300+ keyClick(Qt.Key_Down);
301+ verify(!get_suggestion(0).selected);
302+ verify(!get_suggestion(1).selected);
303+ verify(get_suggestion(2).selected);
304+
305+ keyClick(Qt.Key_Up);
306+ keyClick(Qt.Key_Up);
307+ tryCompare(get_suggestions(), "count", 3);
308+ tryCompare(get_suggestion(0), "selected", false);
309+ tryCompare(get_suggestion(1), "selected", false);
310+
311+ keyClick(Qt.Key_Up);
312+ tryCompare(get_suggestions(), "count", 3);
313 tryCompare(addressbar, "activeFocus", true);
314- tryCompare(suggestions, "activeFocus", false);
315- tryCompare(suggestion1, "selected", false);
316- tryCompare(suggestion2, "selected", false);
317+ tryCompare(get_suggestions(), "activeFocus", false);
318+ tryCompare(get_suggestion(0), "selected", false);
319+ tryCompare(get_suggestion(1), "selected", false);
320 }
321
322 function test_suggestions_escape() {
323@@ -242,10 +265,11 @@
324 typeString("element");
325 tryCompare(addressbar, "text", "element");
326 assert_suggestions_eventually_shown();
327- tryCompare(suggestions, "count", 2);
328+ tryCompare(suggestions, "count", 3);
329 keyClick(Qt.Key_Down);
330 tryCompare(suggestions, "activeFocus", true);
331- tryCompare(addressbar, "text", "element");
332+ var suggestion1 = get_suggestion(0);
333+ tryCompare(addressbar, "text", suggestion1.title);
334 keyClick(Qt.Key_Escape);
335 assert_suggestions_eventually_hidden();
336 tryCompare(addressbar, "text", text);
337@@ -260,9 +284,11 @@
338 typeString("element");
339 tryCompare(addressbar, "text", "element");
340 assert_suggestions_eventually_shown();
341- tryCompare(suggestions, "count", 2);
342+ tryCompare(suggestions, "count", 3);
343 keyClick(Qt.Key_Down);
344 tryCompare(suggestions, "activeFocus", true);
345+ var suggestion1 = get_suggestion(0);
346+ tryCompare(addressbar, "text", suggestion1.title);
347 keyClick(Qt.Key_Up);
348 tryCompare(addressbar, "activeFocus", true);
349 keyClick(Qt.Key_Escape);

Subscribers

People subscribed via source and target branches