Bug 1550025 - In Quantum Bar the restriction tokens should bypass the restriction prefs. r=adw
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 09 May 2019 15:59:33 +0000
changeset 532067 763d3da981174de750c7caf1d19bdff73c864f25
parent 532066 e925cef1cadfa7dc2dff699ae3d980a11705196c
child 532068 bc29b6ed69e821515c82490a5c2afb5019d8f115
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1550025
milestone68.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 1550025 - In Quantum Bar the restriction tokens should bypass the restriction prefs. r=adw Differential Revision: https://phabricator.services.mozilla.com/D30490
browser/components/urlbar/UrlbarProvidersManager.jsm
browser/components/urlbar/tests/unit/test_providersManager_filtering.js
--- a/browser/components/urlbar/UrlbarProvidersManager.jsm
+++ b/browser/components/urlbar/UrlbarProvidersManager.jsm
@@ -436,41 +436,37 @@ function getAcceptableMatchSources(conte
   for (let source of Object.values(UrlbarUtils.RESULT_SOURCE)) {
     // Skip sources that the context doesn't care about.
     if (context.sources && !context.sources.includes(source)) {
       continue;
     }
     // Check prefs and restriction tokens.
     switch (source) {
       case UrlbarUtils.RESULT_SOURCE.BOOKMARKS:
-        if (UrlbarPrefs.get("suggest.bookmark") &&
-            (!restrictTokenType ||
-             restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK ||
-             restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_TAG)) {
+        if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_BOOKMARK ||
+            restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_TAG ||
+            (!restrictTokenType && UrlbarPrefs.get("suggest.bookmark"))) {
           acceptedSources.push(source);
         }
         break;
       case UrlbarUtils.RESULT_SOURCE.HISTORY:
-        if (UrlbarPrefs.get("suggest.history") &&
-            (!restrictTokenType ||
-             restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_HISTORY)) {
+        if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_HISTORY ||
+            (!restrictTokenType && UrlbarPrefs.get("suggest.history"))) {
           acceptedSources.push(source);
         }
         break;
       case UrlbarUtils.RESULT_SOURCE.SEARCH:
-        if (UrlbarPrefs.get("suggest.searches") &&
-            (!restrictTokenType ||
-             restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_SEARCH)) {
+        if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_SEARCH ||
+            (!restrictTokenType && UrlbarPrefs.get("suggest.searches"))) {
           acceptedSources.push(source);
         }
         break;
       case UrlbarUtils.RESULT_SOURCE.TABS:
-        if (UrlbarPrefs.get("suggest.openpage") &&
-            (!restrictTokenType ||
-             restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE)) {
+        if (restrictTokenType === UrlbarTokenizer.TYPE.RESTRICT_OPENPAGE ||
+            (!restrictTokenType && UrlbarPrefs.get("suggest.openpage"))) {
           acceptedSources.push(source);
         }
         break;
       case UrlbarUtils.RESULT_SOURCE.OTHER_NETWORK:
         if (!context.isPrivate && !restrictTokenType) {
           acceptedSources.push(source);
         }
         break;
--- a/browser/components/urlbar/tests/unit/test_providersManager_filtering.js
+++ b/browser/components/urlbar/tests/unit/test_providersManager_filtering.js
@@ -245,8 +245,90 @@ add_task(async function test_nofilter_im
   let promise = promiseControllerNotification(controller, "onQueryResults");
   await controller.startQuery(context, controller);
   await promise;
   Services.prefs.clearUserPref("browser.urlbar.suggest.openpage");
   Assert.deepEqual(context.results.length, 1, "Should find only one match");
   Assert.deepEqual(context.results[0].source, UrlbarUtils.RESULT_SOURCE.TABS,
                    "Should find only a tab match");
 });
+
+add_task(async function test_nofilter_restrict() {
+  // Checks that even if a pref is disabled, we still return results on a
+  // restriction token.
+  let controller = new UrlbarController({
+    browserWindow: {
+      location: {
+        href: AppConstants.BROWSER_CHROME_URL,
+      },
+    },
+  });
+
+  let matches = [
+    new UrlbarResult(UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
+                     UrlbarUtils.RESULT_SOURCE.TABS,
+                     { url: "http://mozilla.org/foo_tab/" }),
+    new UrlbarResult(UrlbarUtils.RESULT_TYPE.URL,
+                     UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
+                     { url: "http://mozilla.org/foo_bookmark/" }),
+    new UrlbarResult(UrlbarUtils.RESULT_TYPE.URL,
+                     UrlbarUtils.RESULT_SOURCE.HISTORY,
+                     { url: "http://mozilla.org/foo_history/" }),
+    new UrlbarResult(UrlbarUtils.RESULT_TYPE.SEARCH,
+                     UrlbarUtils.RESULT_SOURCE.SEARCH,
+                     { engine: "noengine" }),
+  ];
+
+  /**
+   * A test provider.
+   */
+  class TestProvider extends UrlbarProvider {
+    get name() {
+      return "MyProvider";
+    }
+    get type() {
+      return UrlbarUtils.PROVIDER_TYPE.IMMEDIATE;
+    }
+    get sources() {
+      return [
+        UrlbarUtils.RESULT_SOURCE.TABS,
+        UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
+        UrlbarUtils.RESULT_SOURCE.HISTORY,
+        UrlbarUtils.RESULT_SOURCE.SEARCH,
+      ];
+    }
+    async startQuery(context, add) {
+      Assert.ok(true, "expected provider was invoked");
+      for (let match of matches) {
+        add(this, match);
+      }
+    }
+    cancelQuery(context) {}
+  }
+  UrlbarProvidersManager.registerProvider(new TestProvider());
+
+  let typeToPropertiesMap = new Map([
+    ["HISTORY", {source: "HISTORY", pref: "history"}],
+    ["BOOKMARK", {source: "BOOKMARKS", pref: "bookmark"}],
+    ["OPENPAGE", {source: "TABS", pref: "openpage"}],
+    ["SEARCH", {source: "SEARCH", pref: "searches"}],
+  ]);
+  for (let [type, token] of Object.entries(UrlbarTokenizer.RESTRICT)) {
+    let properties = typeToPropertiesMap.get(type);
+    if (!properties) {
+      continue;
+    }
+    info("Restricting on " + type);
+    let context = createContext(token + " foo", {
+      providers: ["MyProvider"],
+    });
+    // Disable the corresponding pref.
+    const pref = "browser.urlbar.suggest." + properties.pref;
+    info("Disabling " + pref);
+    Services.prefs.setBoolPref(pref, false);
+    await controller.startQuery(context, controller);
+    Assert.equal(context.results.length, 1, "Should find one result");
+    Assert.equal(context.results[0].source,
+                 UrlbarUtils.RESULT_SOURCE[properties.source],
+                 "Check result source");
+    Services.prefs.clearUserPref(pref);
+  }
+});