Bug 1522226 - Quantum bar should show only matching bookmark tags. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 25 Jan 2019 21:49:17 +0000
changeset 515525 539995d20747edf340c4ef77a8660636f88112d4
parent 515524 f83934422518dcba917afb08e9b103aa702cf772
child 515526 2fb0d69739bddfb334c483f7f1054c2b6be735d3
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1522226
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1522226 - Quantum bar should show only matching bookmark tags. r=adw Differential Revision: https://phabricator.services.mozilla.com/D17635
browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
browser/components/urlbar/tests/unit/test_providerUnifiedComplete.js
--- a/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
+++ b/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
@@ -309,17 +309,21 @@ function makeUrlbarResult(tokens, info) 
   let tags = [];
   let comment = info.comment;
   let hasTags = info.style.includes("tag");
   if (info.style.includes("bookmark") || hasTags) {
     source = UrlbarUtils.MATCH_SOURCE.BOOKMARKS;
     if (hasTags) {
       // Split title and tags.
       [comment, tags] = info.comment.split(TITLE_TAGS_SEPARATOR);
-      tags = tags.split(",").map(t => t.trim());
+      // Tags are separated by a comma and in a random order.
+      // We should also just include tags that match the searchString.
+      tags = tags.split(",").map(t => t.trim()).filter(tag => {
+        return tokens.some(token => tag.includes(token.value));
+      }).sort();
     }
   } else if (info.style.includes("preloaded-top-sites")) {
     source = UrlbarUtils.MATCH_SOURCE.OTHER_LOCAL;
   } else {
     source = UrlbarUtils.MATCH_SOURCE.HISTORY;
   }
   return new UrlbarResult(
     UrlbarUtils.RESULT_TYPE.URL,
--- a/browser/components/urlbar/tests/unit/test_providerUnifiedComplete.js
+++ b/browser/components/urlbar/tests/unit/test_providerUnifiedComplete.js
@@ -24,24 +24,26 @@ add_task(async function test_unifiedComp
 
   let controller = new UrlbarController({
     browserWindow: {
       location: {
         href: AppConstants.BROWSER_CHROME_URL,
       },
     },
   });
-  let context = createContext("moz", {isPrivate: false});
+  let context = createContext("moz org", {isPrivate: false});
 
   // Add entries from multiple sources.
   await PlacesUtils.bookmarks.insert({
     url: "https://bookmark.mozilla.org/",
     title: "Test bookmark",
     parentGuid: PlacesUtils.bookmarks.unfiledGuid,
   });
+  PlacesUtils.tagging.tagURI(Services.io.newURI("https://bookmark.mozilla.org/"),
+                             ["mozilla", "org", "ham", "moz", "bacon"]);
   await PlacesTestUtils.addVisits([
     {uri: "https://history.mozilla.org/", title: "Test history"},
     {uri: "https://tab.mozilla.org/", title: "Test tab"},
   ]);
   UrlbarProviderOpenTabs.registerOpenTab("https://tab.mozilla.org/", 0);
 
   await controller.startQuery(context);
 
@@ -53,16 +55,19 @@ add_task(async function test_unifiedComp
     UrlbarUtils.RESULT_TYPE.SEARCH,
     UrlbarUtils.RESULT_TYPE.SEARCH,
     UrlbarUtils.RESULT_TYPE.URL,
     UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
     UrlbarUtils.RESULT_TYPE.URL,
   ], context.results.map(m => m.type), "Check result types");
 
   Assert.deepEqual([
-    "moz",
-    "moz foo",
-    "moz bar",
+    "moz org",
+    "moz org foo",
+    "moz org bar",
     "Test bookmark",
     "Test tab",
     "Test history",
   ], context.results.map(m => m.title), "Check match titles");
+
+  Assert.deepEqual(context.results[3].payload.tags, ["moz", "mozilla", "org"],
+                   "Check tags");
 });