Merge lp:~rpadovani/webbrowser-app/no-duplicates-address-bar into lp:webbrowser-app

Proposed by Riccardo Padovani
Status: Needs review
Proposed branch: lp:~rpadovani/webbrowser-app/no-duplicates-address-bar
Merge into: lp:webbrowser-app
Diff against target: 60 lines (+12/-7)
3 files modified
src/app/webbrowser/Browser.qml (+1/-1)
src/app/webbrowser/Suggestions.qml (+8/-2)
tests/autopilot/webbrowser_app/tests/test_suggestions.py (+3/-4)
To merge this branch: bzr merge lp:~rpadovani/webbrowser-app/no-duplicates-address-bar
Reviewer Review Type Date Requested Status
Olivier Tilloy Needs Fixing
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+262586@code.launchpad.net

Commit message

Avoid to have duplicate entries in the address bar. Fix #1467078

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

Thanks for the bug report, and for working on a fix, Riccardo!

While the patch kind of works, the approach isn’t right, as it special-cases bookmarks in a component (Suggestions.qml) that is generic (it doesn’t know anything about the models populating it).

The approach to remove doublons is ok, but the code should remain generic. Not sure what the best approach for that would be. Maybe add a "displayLimit" parameter to the models, so that e.g. a LimitProxyModel would fetch 4 (or 5, or 10) items, but then only the first 2 that are not doublons would be displayed?

review: Needs Fixing
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Sorry, I'm not sure I understand how to create a generic approach. We have 3 model to merge here: bookmarks, history, and suggestions on google. We want to limit bookmarks and history to two elements, suggestions on google to 5. I need to pass more elements to be sure the aren't doublons (4 is perfect for history, because at least two are different from the two of bookmarks), but how can I limit how many of them I display without counting how many I've already added in that section?

Maybe I've to do a more generic approach creating an array of how many of each section I added? But again, how could I choose if I have to display 5 or 2 without verifing which model it is?

Revision history for this message
Olivier Tilloy (osomon) wrote :

Counting how many items you’ve added from one given model is okay. What’s not ok is to check that with hardcoded assertions such as:

    model.icon !== 'non-starred'

because you make assumptions on the models used to populate the suggestions.

1073. By Riccardo Padovani

Merge with trunk and resolve conflicts

1074. By Riccardo Padovani

Avoid hardcoding model name

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Fixed, thanks for the explanation

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

I’m reliably getting 3 autopilot failures when running the tests on my desktop:

  webbrowser_app.tests.test_suggestions.TestSuggestions.test_keyboard_navigation
  webbrowser_app.tests.test_suggestions.TestSuggestions.test_list_of_suggestions_order
  webbrowser_app.tests.test_suggestions.TestSuggestions.test_list_of_suggestions_bookmark_limits

review: Needs Fixing
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

I don't understand the failures: the first and the third are the same: it says there are 4 suggestions, but it expects only 2 suggestions. The strange is there are only two suggestions, so I don't understand why it fails.

The second one expects 5 results, but I think it's right it shows 4, because the first and the second are the same, am I right?

Revision history for this message
Olivier Tilloy (osomon) wrote :

Without looking further into the failures, my guess is that with your changes the suggestions are instantiated but not displayed. Autopilot, if not explicitly instructed to do so, will return all matching objects, regardless of whether they are visible or not.

If my guess is correct, there are two possible approaches here:
 - ensure that only exactly the required number of suggestions is instantiated
 - modify the autopilot emulator to query for only *visible* suggestions (have a look at tests/autopilot/webbrowser_app/emulators/browser.py around line 350)

1075. By Riccardo Padovani

Merge with upstream

1076. By Riccardo Padovani

Update test to don't expect duplicate suggestion in the address bar

1077. By Riccardo Padovani

Fix test_list_of_suggestions_order

1078. By Riccardo Padovani

Fix all the tests

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Actually, the problem was in the way Suggestions count property was calculated, I fixed it.
I ran all the suggestion's tests and they still work, so I think my fix is ok.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Olivier Tilloy (osomon) wrote :

In Suggestions.qml:

 - Function countItems() isn’t used any longer, please remove it.

 - For consistency with the rest of the codebase, please remove trailing semi-colons in JS code

 - The forEach branch of the conditional on the type of model needs to be updated to filter out duplicates as well. This works correctly as it is, but it will break if we reshuffle the order of the models, or add new models to the suggestions.

 - Instead of hardcoding the upper limit for j to 2, you should add a 'displayLimit' property on the models.

Also, would you mind taking advantage of this change to add QML unit tests for the Suggestions.qml component? That would allow verifying that your implementation works well in all cases.

review: Needs Fixing

Unmerged revisions

1078. By Riccardo Padovani

Fix all the tests

1077. By Riccardo Padovani

Fix test_list_of_suggestions_order

1076. By Riccardo Padovani

Update test to don't expect duplicate suggestion in the address bar

1075. By Riccardo Padovani

Merge with upstream

1074. By Riccardo Padovani

Avoid hardcoding model name

1073. By Riccardo Padovani

Merge with trunk and resolve conflicts

1072. By Riccardo Padovani

Avoid to have duplicate entries in the address bar. Fix #1467078

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 2015-10-13 12:57:33 +0000
3+++ src/app/webbrowser/Browser.qml 2015-10-19 08:33:27 +0000
4@@ -496,7 +496,7 @@
5
6 LimitProxyModel {
7 id: bookmarksSuggestions
8- limit: 2
9+ limit: 4 // To be sure they aren't the same of historySuggestions
10 readonly property string icon: "non-starred"
11 readonly property bool displayUrl: true
12 sourceModel: TextSearchFilterModel {
13
14=== modified file 'src/app/webbrowser/Suggestions.qml'
15--- src/app/webbrowser/Suggestions.qml 2015-08-24 16:51:47 +0000
16+++ src/app/webbrowser/Suggestions.qml 2015-10-19 08:33:27 +0000
17@@ -26,7 +26,7 @@
18 property var searchTerms
19 property var models
20
21- readonly property int count: models.reduce(internal.countItems, 0)
22+ readonly property int count: suggestionsList.model.length
23 readonly property alias contentHeight: suggestionsList.contentHeight
24
25 signal activated(url url)
26@@ -56,7 +56,13 @@
27 if (model.forEach) {
28 model.forEach(function(item) { modelItems.push(item) })
29 } else {
30- for (var i = 0; i < model.count; i++) modelItems.push(model.get(i))
31+ for (var i = 0, j = 0; i < model.count && j < 2; i++) {
32+ var item = model.get(i);
33+ if (!list.some(function(elem){return elem["url"] === item.url})) {
34+ modelItems.push(model.get(i));
35+ j++;
36+ }
37+ }
38 }
39
40 modelItems.forEach(function(item) {
41
42=== modified file 'tests/autopilot/webbrowser_app/tests/test_suggestions.py'
43--- tests/autopilot/webbrowser_app/tests/test_suggestions.py 2015-07-09 07:44:48 +0000
44+++ tests/autopilot/webbrowser_app/tests/test_suggestions.py 2015-10-19 08:33:27 +0000
45@@ -213,12 +213,11 @@
46 suggestions = self.main_window.get_suggestions()
47 self.address_bar.write('QML')
48 self.assert_suggestions_eventually_shown()
49- self.assertThat(suggestions.count, Eventually(Equals(5)))
50+ self.assertThat(suggestions.count, Eventually(Equals(4)))
51 entries = suggestions.get_ordered_entries()
52- self.assertThat(len(entries), Equals(5))
53+ self.assertThat(len(entries), Equals(4))
54 self.assertThat(entries[0].icon, Equals("history"))
55- self.assertThat(entries[1].icon, Equals("non-starred"))
56- self.assertThat(entries[2].icon, Equals("search"))
57+ self.assertThat(entries[1].icon, Equals("search"))
58
59 def test_clear_address_bar_dismisses_suggestions(self):
60 self.address_bar.focus()

Subscribers

People subscribed via source and target branches

to status/vote changes: