Bug 1551179 - Use SearchUtils.BROWSER_SEARCH_PREF in search tests r=Standard8
authorpremk <prem.kumar.krishnan@live.com>
Thu, 06 Jun 2019 09:53:40 +0000
changeset 477588 d8cc60b60e8267d7026846c4898aa86afd91fb4d
parent 477587 236ca3d1f3d31d8aaa860693bdf3d26b861ac24d
child 477589 f9ee0e2203e5026250ba295313c7e82a95d1da44
push id36119
push userncsoregi@mozilla.com
push dateThu, 06 Jun 2019 21:52:09 +0000
treeherdermozilla-central@6a81efd823db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1551179
milestone69.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 1551179 - Use SearchUtils.BROWSER_SEARCH_PREF in search tests r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D33801
browser/components/search/test/browser/browser_amazon.js
browser/components/search/test/browser/browser_bing.js
browser/components/search/test/browser/browser_ddg.js
browser/components/search/test/browser/browser_eBay.js
browser/components/search/test/browser/head.js
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/components/search/tests/xpcshell/test_async_disthidden.js
toolkit/components/search/tests/xpcshell/test_hidden.js
toolkit/components/search/tests/xpcshell/test_list_json_locale.js
toolkit/components/search/tests/xpcshell/test_pref.js
--- a/browser/components/search/test/browser/browser_amazon.js
+++ b/browser/components/search/test/browser/browser_amazon.js
@@ -2,18 +2,16 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Test Amazon search plugin URLs
  */
 
 "use strict";
 
-const BROWSER_SEARCH_PREF = "browser.search.";
-
 add_task(async function test() {
   await Services.search.init();
 
   let engine = Services.search.getEngineByName("Amazon.com");
   ok(engine, "Amazon.com");
 
   let base = "https://www.amazon.com/exec/obidos/external-search/?field-keywords=foo&ie=UTF-8&mode=blended&tag=mozilla-20&sourceid=Mozilla-search";
   let url;
--- a/browser/components/search/test/browser/browser_bing.js
+++ b/browser/components/search/test/browser/browser_bing.js
@@ -2,18 +2,16 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Test Bing search plugin URLs
  */
 
 "use strict";
 
-const BROWSER_SEARCH_PREF = "browser.search.";
-
 add_task(async function test() {
   await Services.search.init();
 
   let engine = Services.search.getEngineByName("Bing");
   ok(engine, "Bing");
 
   let base = "https://www.bing.com/search?q=foo&pc=MOZI";
   let url;
--- a/browser/components/search/test/browser/browser_ddg.js
+++ b/browser/components/search/test/browser/browser_ddg.js
@@ -2,18 +2,16 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Test DuckDuckGo search plugin URLs
  */
 
 "use strict";
 
-const BROWSER_SEARCH_PREF = "browser.search.";
-
 add_task(async function test() {
   await Services.search.init();
 
   let engine = Services.search.getEngineByName("DuckDuckGo");
   ok(engine, "DuckDuckGo");
 
   let base = "https://duckduckgo.com/?q=foo";
   let url;
--- a/browser/components/search/test/browser/browser_eBay.js
+++ b/browser/components/search/test/browser/browser_eBay.js
@@ -2,18 +2,16 @@
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Test eBay search plugin URLs
  */
 
 "use strict";
 
-const BROWSER_SEARCH_PREF = "browser.search.";
-
 add_task(async function test() {
   await Services.search.init();
 
   let engine = Services.search.getEngineByName("eBay");
   ok(engine, "eBay");
 
   let base = "https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=4&toolid=20004&campid=5338192028&customid=&mpre=https://www.ebay.com/sch/foo";
   let url;
--- a/browser/components/search/test/browser/head.js
+++ b/browser/components/search/test/browser/head.js
@@ -1,12 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-ChromeUtils.import("resource://testing-common/CustomizableUITestUtils.jsm", this);
+XPCOMUtils.defineLazyModuleGetters(this, {
+  CustomizableUITestUtils: "resource://testing-common/CustomizableUITestUtils.jsm",
+  SearchUtils: "resource://gre/modules/SearchUtils.jsm",
+});
+
 let gCUITestUtils = new CustomizableUITestUtils(window);
 
 /**
  * Recursively compare two objects and check that every property of expectedObj has the same value
  * on actualObj.
  *
  * @param {object} expectedObj
  *        The expected object to find.
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -6,23 +6,23 @@ const {XPCOMUtils} = ChromeUtils.import(
 XPCOMUtils.defineLazyModuleGetters(this, {
   FileUtils: "resource://gre/modules/FileUtils.jsm",
   NetUtil: "resource://gre/modules/NetUtil.jsm",
   RemoteSettings: "resource://services-settings/remote-settings.js",
   SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
   Services: "resource://gre/modules/Services.jsm",
   setTimeout: "resource://gre/modules/Timer.jsm",
   TestUtils: "resource://testing-common/TestUtils.jsm",
+  SearchUtils: "resource://gre/modules/SearchUtils.jsm",
 });
 
 var {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm");
 var {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
 var {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
 
-const BROWSER_SEARCH_PREF = "browser.search.";
 const PREF_SEARCH_URL = "geoSpecificDefaults.url";
 const NS_APP_SEARCH_DIR = "SrchPlugns";
 
 const MODE_RDONLY = FileUtils.MODE_RDONLY;
 const MODE_WRONLY = FileUtils.MODE_WRONLY;
 const MODE_CREATE = FileUtils.MODE_CREATE;
 const MODE_TRUNCATE = FileUtils.MODE_TRUNCATE;
 
@@ -37,17 +37,17 @@ Services.prefs.setBoolPref("browser.sear
 
 // The geo-specific search tests assume certain prefs are already setup, which
 // might not be true when run in comm-central etc.  So create them here.
 Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", true);
 Services.prefs.setIntPref("browser.search.geoip.timeout", 3000);
 // But still disable geoip lookups - tests that need it will re-configure this.
 Services.prefs.setCharPref("browser.search.geoip.url", "");
 // Also disable region defaults - tests using it will also re-configure it.
-Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).setCharPref("geoSpecificDefaults.url", "");
+Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF).setCharPref("geoSpecificDefaults.url", "");
 
 AddonTestUtils.init(this, false);
 AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "42", "42");
 
 /**
  * Configure preferences to load engines from
  * chrome://testsearchplugin/locale/searchplugins/
  */
@@ -322,32 +322,32 @@ async function withGeoServer(testFn, {
       response.finish();
       gRequests.push(metadata);
     }, delay);
   });
 
   srv.start(-1);
 
   let url = `http://localhost:${srv.identity.primaryPort}/${path}?`;
-  let defaultBranch = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
+  let defaultBranch = Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF);
   let originalURL = defaultBranch.getCharPref(PREF_SEARCH_URL);
   defaultBranch.setCharPref(PREF_SEARCH_URL, url);
   // Set a bogus user value so that running the test ensures we ignore it.
-  Services.prefs.setCharPref(BROWSER_SEARCH_PREF + PREF_SEARCH_URL, "about:blank");
+  Services.prefs.setCharPref(SearchUtils.BROWSER_SEARCH_PREF + PREF_SEARCH_URL, "about:blank");
   Services.prefs.setCharPref("browser.search.geoip.url",
                              'data:application/json,{"country_code": "FR"}');
 
   try {
     await testFn(gRequests);
   } catch (ex) {
     throw ex;
   } finally {
     srv.stop(() => {});
     defaultBranch.setCharPref(PREF_SEARCH_URL, originalURL);
-    Services.prefs.clearUserPref(BROWSER_SEARCH_PREF + PREF_SEARCH_URL);
+    Services.prefs.clearUserPref(SearchUtils.BROWSER_SEARCH_PREF + PREF_SEARCH_URL);
     Services.prefs.clearUserPref("browser.search.geoip.url");
   }
 }
 
 function checkNoRequest(requests) {
   Assert.equal(requests.length, 0);
 }
 
--- a/toolkit/components/search/tests/xpcshell/test_async_disthidden.js
+++ b/toolkit/components/search/tests/xpcshell/test_async_disthidden.js
@@ -1,17 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /* Test that the ignoredJAREngines pref hides search engines  */
 
 "use strict";
 
 function run_test() {
-  let defaultBranch = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
+  let defaultBranch = Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF);
   defaultBranch.setCharPref("ignoredJAREngines", "engine");
   Services.prefs.getDefaultBranch("").setCharPref("distribution.id", "partner-1");
 
   // The test engines used in this test need to be recognized as 'default'
   // engines or the resource URL won't be used
   let url = "resource://test/data/";
   let resProt = Services.io.getProtocolHandler("resource")
                         .QueryInterface(Ci.nsIResProtocolHandler);
--- a/toolkit/components/search/tests/xpcshell/test_hidden.js
+++ b/toolkit/components/search/tests/xpcshell/test_hidden.js
@@ -13,17 +13,17 @@ add_task(async function setup() {
   // Make 'hidden' the only visible engine.
   let url = "data:application/json," + JSON.stringify({
     "interval": 31536000,
     "settings": {
       "searchDefault": "hidden",
       "visibleDefaultEngines": ["hidden"],
     },
   });
-  Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).setCharPref(kUrlPref, url);
+  Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF).setCharPref(kUrlPref, url);
 
   Assert.ok(!Services.search.isInitialized);
 
   await AddonTestUtils.promiseStartupManager();
 });
 
 add_task(async function async_init() {
   let commitPromise = promiseAfterCache();
@@ -54,17 +54,17 @@ add_task(async function invalid_engine()
   // local defaults.
   let url = "data:application/json," + JSON.stringify({
     "interval": 31536000,
     "settings": {
       "searchDefault": "hidden",
       "visibleDefaultEngines": ["hidden", "bogus"],
     },
   });
-  Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF).setCharPref(kUrlPref, url);
+  Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF).setCharPref(kUrlPref, url);
 
   await asyncReInit({ waitForRegionFetch: true });
 
   let engines = await Services.search.getEngines();
   Assert.equal(engines.length, 1);
 
   // The default test jar engine is visible.
   let engine = Services.search.getEngineByName("bug645970");
--- a/toolkit/components/search/tests/xpcshell/test_list_json_locale.js
+++ b/toolkit/components/search/tests/xpcshell/test_list_json_locale.js
@@ -25,17 +25,17 @@ add_task(async function test_listJSONloc
   Assert.equal(sortedEngines.length, 1, "Should have only one engine");
 });
 
 
 // Check that switching locale switches search engines
 add_task(async function test_listJSONlocaleSwitch() {
   let promise = SearchTestUtils.promiseSearchNotification("reinit-complete");
 
-  let defaultBranch = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
+  let defaultBranch = Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF);
   defaultBranch.setCharPref("param.code", "good&id=unique");
 
   Services.locale.availableLocales = ["fr"];
   Services.locale.requestedLocales = ["fr"];
 
   await promise;
 
   Assert.ok(Services.search.isInitialized, "search initialized");
--- a/toolkit/components/search/tests/xpcshell/test_pref.js
+++ b/toolkit/components/search/tests/xpcshell/test_pref.js
@@ -14,19 +14,19 @@ function run_test() {
                         .QueryInterface(Ci.nsIResProtocolHandler);
   resProt.setSubstitution("search-extensions",
                           Services.io.newURI(url));
 
   run_next_test();
 }
 
 add_task(async function test_pref() {
-  let defaultBranch = Services.prefs.getDefaultBranch(BROWSER_SEARCH_PREF);
+  let defaultBranch = Services.prefs.getDefaultBranch(SearchUtils.BROWSER_SEARCH_PREF);
   defaultBranch.setCharPref("param.code", "good&id=unique");
-  Services.prefs.setCharPref(BROWSER_SEARCH_PREF + "param.code", "bad");
+  Services.prefs.setCharPref(SearchUtils.BROWSER_SEARCH_PREF + "param.code", "bad");
 
   await AddonTestUtils.promiseStartupManager();
   await Services.search.init();
 
   let engine = Services.search.getEngineByName("engine-pref");
   let base = "https://www.google.com/search?q=foo&code=";
   Assert.equal(engine.getSubmission("foo").uri.spec,
                base + "good%26id%3Dunique");