Bug 1553067 - Quantum Bar may not return bookmark tags correctly. r=adw a=jcristau
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 29 May 2019 14:34:46 +0000
changeset 536584 49da76e97a0250b8dfee9e1f54c7dac3fb896a56
parent 536583 c1641fab48a0bb6cc656222ecc66e0e7669f9b2d
child 536585 85c9907686ce71f4a72da448d278444acc11b2a2
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, jcristau
bugs1553067
milestone68.0
Bug 1553067 - Quantum Bar may not return bookmark tags correctly. r=adw a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D32684
browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
browser/components/urlbar/tests/browser/browser_autocomplete_tag_star_visibility.js
browser/components/urlbar/tests/unit/test_providerUnifiedComplete.js
toolkit/components/places/UnifiedComplete.jsm
toolkit/components/places/tests/unifiedcomplete/test_special_search.js
--- a/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
+++ b/browser/components/urlbar/UrlbarProviderUnifiedComplete.jsm
@@ -354,17 +354,18 @@ function makeUrlbarResult(tokens, info) 
   if (info.style.includes("bookmark")) {
     source = UrlbarUtils.RESULT_SOURCE.BOOKMARKS;
     if (info.style.includes("tag")) {
       // Split title and tags.
       [comment, tags] = info.comment.split(TITLE_TAGS_SEPARATOR);
       // 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));
+        let lowerCaseTag = tag.toLocaleLowerCase();
+        return tokens.some(token => lowerCaseTag.includes(token.lowerCaseValue));
       }).sort();
     }
   } else if (info.style.includes("preloaded-top-sites")) {
     source = UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL;
   } else {
     source = UrlbarUtils.RESULT_SOURCE.HISTORY;
   }
   return new UrlbarResult(
--- a/browser/components/urlbar/tests/browser/browser_autocomplete_tag_star_visibility.js
+++ b/browser/components/urlbar/tests/browser/browser_autocomplete_tag_star_visibility.js
@@ -73,16 +73,26 @@ add_task(async function() {
     tagName: "tagtest5",
     prefs: {
       "suggest.bookmark": true,
     },
     input: "^ tagtest5",
     expected: {
       typeImageVisible: false,
     },
+  }, {
+      description: "Test partial tag and casing",
+      tagName: "tagtest6",
+      prefs: {
+        "suggest.bookmark": true,
+      },
+      input: "TeSt6",
+      expected: {
+        typeImageVisible: true,
+      },
   }];
 
   for (let testcase of testcases) {
     info(`Test case: ${testcase.description}`);
 
     await addTagItem(testcase.tagName);
     for (let prefName of Object.keys(testcase.prefs)) {
       Services.prefs.setBoolPref(`browser.urlbar.${prefName}`, testcase.prefs[prefName]);
--- a/browser/components/urlbar/tests/unit/test_providerUnifiedComplete.js
+++ b/browser/components/urlbar/tests/unit/test_providerUnifiedComplete.js
@@ -34,17 +34,19 @@ add_task(async function test_unifiedComp
 
   let controller = new UrlbarController({
     browserWindow: {
       location: {
         href: AppConstants.BROWSER_CHROME_URL,
       },
     },
   });
-  let context = createContext("moz org", {isPrivate: false});
+  // Also check case insensitivity.
+  let searchString = "MoZ oRg";
+  let context = createContext(searchString, {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/"),
@@ -65,19 +67,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 org",
-    "moz org foo",
-    "moz org bar",
+    searchString,
+    searchString + " foo",
+    searchString + " 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");
 });
--- a/toolkit/components/places/UnifiedComplete.jsm
+++ b/toolkit/components/places/UnifiedComplete.jsm
@@ -777,16 +777,21 @@ Search.prototype = {
         // set the restrict bit to 1 (to intersect the search results).
         if (!foundToken) {
           foundToken = true;
           // Do not take into account previous behavior (e.g.: history, bookmark)
           this._behavior = 0;
           this.setBehavior("restrict");
         }
         this.setBehavior(behavior);
+        // We return tags only for bookmarks, thus when tags are enforced, we
+        // must also set the bookmark behavior.
+        if (behavior == "tag") {
+          this.setBehavior("bookmark");
+        }
       }
     }
     // Set the right JavaScript behavior based on our preference.  Note that the
     // preference is whether or not we should filter JavaScript, and the
     // behavior is if we should search it or not.
     if (!UrlbarPrefs.get("filter.javascript")) {
       this.setBehavior("javascript");
     }
--- a/toolkit/components/places/tests/unifiedcomplete/test_special_search.js
+++ b/toolkit/components/places/tests/unifiedcomplete/test_special_search.js
@@ -69,20 +69,20 @@ add_task(async function test_special_sea
                { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar"], style: [ "bookmark-tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
   });
 
   info("Tag restrict");
   await check_autocomplete({
     search: UrlbarTokenizer.RESTRICT.TAG,
-    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
+    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
   });
 
   info("Special as first word");
   await check_autocomplete({
     search: `${UrlbarTokenizer.RESTRICT.HISTORY} foo bar`,
     matches: [ { uri: uri2, title: "foo.bar" },
                { uri: uri3, title: "title" },
                { uri: uri4, title: "foo.bar" },
@@ -146,20 +146,20 @@ add_task(async function test_special_sea
                { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
   });
 
   info(`foo ${UrlbarTokenizer.RESTRICT.TAG} -> is tag`);
   await check_autocomplete({
     search: `foo ${UrlbarTokenizer.RESTRICT.TAG}`,
-    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
+    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
   });
 
   // Test various pairs of special searches
 
   info(`foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TITLE} -> history, in title`);
   await check_autocomplete({
     search: `foo ${UrlbarTokenizer.RESTRICT.HISTORY} ${UrlbarTokenizer.RESTRICT.TITLE}`,
     matches: [ { uri: uri2, title: "foo.bar" },
@@ -194,27 +194,27 @@ add_task(async function test_special_sea
                { uri: uri8, title: "foo.bar", style: [ "bookmark" ] },
                { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
                { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
   });
 
   info(`foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.TAG} -> in title, is tag`);
   await check_autocomplete({
     search: `foo ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.TAG}`,
-    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
+    matches: [ { uri: uri9, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri10, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
   });
 
   info(`foo ${UrlbarTokenizer.RESTRICT.URL} ${UrlbarTokenizer.RESTRICT.TAG} -> in url, is tag`);
   await check_autocomplete({
     search: `foo ${UrlbarTokenizer.RESTRICT.URL} ${UrlbarTokenizer.RESTRICT.TAG}`,
-    matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "tag" ] },
-               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "tag" ] } ],
+    matches: [ { uri: uri11, title: "title", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] },
+               { uri: uri12, title: "foo.bar", tags: [ "foo.bar" ], style: [ "bookmark-tag" ] } ],
   });
 
   // Test conflicting restrictions.
 
   info(`conflict ${UrlbarTokenizer.RESTRICT.TITLE} ${UrlbarTokenizer.RESTRICT.URL} -> url wins`);
   await PlacesTestUtils.addVisits([
     { uri: `http://conflict.com/${UrlbarTokenizer.RESTRICT.TITLE}`, title: "test" },
     { uri: "http://conflict.com/", title: `test${UrlbarTokenizer.RESTRICT.TITLE}` },
@@ -236,17 +236,17 @@ add_task(async function test_special_sea
   });
 
   info(`conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG} -> tag wins`);
   await addBookmark( { uri: "http://tag.conflict.com/", title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`, tags: [ "one" ] } );
   await addBookmark( { uri: "http://nontag.conflict.com/", title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}` } );
   await check_autocomplete({
     search: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK} ${UrlbarTokenizer.RESTRICT.TAG}`,
     matches: [
-      { uri: "http://tag.conflict.com/", title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`, tags: [ "one" ], style: [ "tag" ] },
+      { uri: "http://tag.conflict.com/", title: `conflict ${UrlbarTokenizer.RESTRICT.BOOKMARK}`, tags: [ "one" ], style: [ "bookmark-tag" ] },
     ],
   });
 
   // Disable autoFill for the next tests, see test_autoFill_default_behavior.js
   // for specific tests.
   Services.prefs.setBoolPref("browser.urlbar.autoFill", false);
 
   // Test default usage by setting certain browser.urlbar.suggest.* prefs