Loading toolkit/components/search/SearchService.jsm +5 −1 Original line number Diff line number Diff line Loading @@ -1508,9 +1508,13 @@ SearchService.prototype = { // Capture the current engine state, in case we need to notify below. const prevCurrentEngine = this._currentEngine; const prevPrivateEngine = this._currentPrivateEngine; // Clear cached objects as they may get replaced. this._currentEngine = null; this._currentPrivateEngine = null; // Ensure we generate a new __sortedEngines list instead // of appending new engines to the end and fixing the // engine order. this.__sortedEngines = null; await this._loadEngines(await this._readCacheFile(), true); // Make sure the current list of engines is persisted. await this._buildCache(); Loading toolkit/components/search/tests/xpcshell/head_search.js +25 −0 Original line number Diff line number Diff line Loading @@ -588,6 +588,31 @@ async function setupRemoteSettings() { ]); } /** * Helper function that sets up a server and respnds to region * fetch requests. * @param {string} region * The region that the server will respond with. * @param {Promise|null} waitToRespond * A promise that the server will await on to delay responding * to the request. */ function useCustomGeoServer(region, waitToRespond = Promise.resolve()) { let srv = useHttpServer(); srv.registerPathHandler("/fetch_region", async (req, res) => { res.processAsync(); await waitToRespond; res.setStatusLine("1.1", 200, "OK"); res.write(JSON.stringify({ country_code: region })); res.finish(); }); Services.prefs.setCharPref( "geo.provider-country.network.url", `http://localhost:${srv.identity.primaryPort}/fetch_region` ); } /** * Some tests might trigger initialisation which will trigger the search settings * update. We need to make sure we wait for that to finish before we exit, otherwise Loading toolkit/components/search/tests/xpcshell/test_maybereloadengine_order.js 0 → 100644 +57 −0 Original line number Diff line number Diff line /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; const TEST_CONFIG = [ { webExtension: { id: "plainengine@search.mozilla.org" }, appliesTo: [{ included: { everywhere: true } }], }, { webExtension: { id: "special-engine@search.mozilla.org" }, appliesTo: [{ default: "yes", included: { regions: ["FR"] } }], }, ]; add_task(async function setup() { Services.prefs.setBoolPref("browser.search.gModernConfig", true); Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", true); await useTestEngines("test-extensions", null, TEST_CONFIG); await AddonTestUtils.promiseStartupManager(); registerCleanupFunction(AddonTestUtils.promiseShutdownManager); }); add_task(async function basic_multilocale_test() { let resolver; let initPromise = new Promise(resolve => (resolver = resolve)); useCustomGeoServer("FR", initPromise); await Services.search.init(false); await Services.search.getDefaultEngines(); resolver(); await SearchTestUtils.promiseSearchNotification("ensure-known-region-done"); let engines = await Services.search.getDefaultEngines(); Assert.deepEqual( engines.map(e => e._name), ["Special", "Plain"], "Special engine is default so should be first" ); engines.forEach(engine => { Assert.ok(!engine._metaData.order, "Order is not defined"); }); let useDBForOrder = Services.prefs.getBoolPref( `${SearchUtils.BROWSER_SEARCH_PREF}useDBForOrder`, false ); Assert.ok( !useDBForOrder, "We should not set the engine order during maybeReloadEngines" ); }); toolkit/components/search/tests/xpcshell/test_webextensions_install.js +5 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,11 @@ add_task(async function basic_install_test() { // User installs a new search engine let extension = await installSearchExtension("example", "Example"); Assert.deepEqual(await getEngineNames(), ["Plain", "Special", "Example"]); Assert.deepEqual((await getEngineNames()).sort(), [ "Example", "Plain", "Special", ]); await forceExpiration(); Loading toolkit/components/search/tests/xpcshell/xpcshell.ini +1 −0 Original line number Diff line number Diff line Loading @@ -75,3 +75,4 @@ support-files = [test_webextensions_builtin_upgrade.js] [test_distributions.js] skip-if = appname == "thunderbird" [test_maybereloadengine_order.js] Loading
toolkit/components/search/SearchService.jsm +5 −1 Original line number Diff line number Diff line Loading @@ -1508,9 +1508,13 @@ SearchService.prototype = { // Capture the current engine state, in case we need to notify below. const prevCurrentEngine = this._currentEngine; const prevPrivateEngine = this._currentPrivateEngine; // Clear cached objects as they may get replaced. this._currentEngine = null; this._currentPrivateEngine = null; // Ensure we generate a new __sortedEngines list instead // of appending new engines to the end and fixing the // engine order. this.__sortedEngines = null; await this._loadEngines(await this._readCacheFile(), true); // Make sure the current list of engines is persisted. await this._buildCache(); Loading
toolkit/components/search/tests/xpcshell/head_search.js +25 −0 Original line number Diff line number Diff line Loading @@ -588,6 +588,31 @@ async function setupRemoteSettings() { ]); } /** * Helper function that sets up a server and respnds to region * fetch requests. * @param {string} region * The region that the server will respond with. * @param {Promise|null} waitToRespond * A promise that the server will await on to delay responding * to the request. */ function useCustomGeoServer(region, waitToRespond = Promise.resolve()) { let srv = useHttpServer(); srv.registerPathHandler("/fetch_region", async (req, res) => { res.processAsync(); await waitToRespond; res.setStatusLine("1.1", 200, "OK"); res.write(JSON.stringify({ country_code: region })); res.finish(); }); Services.prefs.setCharPref( "geo.provider-country.network.url", `http://localhost:${srv.identity.primaryPort}/fetch_region` ); } /** * Some tests might trigger initialisation which will trigger the search settings * update. We need to make sure we wait for that to finish before we exit, otherwise Loading
toolkit/components/search/tests/xpcshell/test_maybereloadengine_order.js 0 → 100644 +57 −0 Original line number Diff line number Diff line /* Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/ */ "use strict"; const TEST_CONFIG = [ { webExtension: { id: "plainengine@search.mozilla.org" }, appliesTo: [{ included: { everywhere: true } }], }, { webExtension: { id: "special-engine@search.mozilla.org" }, appliesTo: [{ default: "yes", included: { regions: ["FR"] } }], }, ]; add_task(async function setup() { Services.prefs.setBoolPref("browser.search.gModernConfig", true); Services.prefs.setBoolPref("browser.search.geoSpecificDefaults", true); await useTestEngines("test-extensions", null, TEST_CONFIG); await AddonTestUtils.promiseStartupManager(); registerCleanupFunction(AddonTestUtils.promiseShutdownManager); }); add_task(async function basic_multilocale_test() { let resolver; let initPromise = new Promise(resolve => (resolver = resolve)); useCustomGeoServer("FR", initPromise); await Services.search.init(false); await Services.search.getDefaultEngines(); resolver(); await SearchTestUtils.promiseSearchNotification("ensure-known-region-done"); let engines = await Services.search.getDefaultEngines(); Assert.deepEqual( engines.map(e => e._name), ["Special", "Plain"], "Special engine is default so should be first" ); engines.forEach(engine => { Assert.ok(!engine._metaData.order, "Order is not defined"); }); let useDBForOrder = Services.prefs.getBoolPref( `${SearchUtils.BROWSER_SEARCH_PREF}useDBForOrder`, false ); Assert.ok( !useDBForOrder, "We should not set the engine order during maybeReloadEngines" ); });
toolkit/components/search/tests/xpcshell/test_webextensions_install.js +5 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,11 @@ add_task(async function basic_install_test() { // User installs a new search engine let extension = await installSearchExtension("example", "Example"); Assert.deepEqual(await getEngineNames(), ["Plain", "Special", "Example"]); Assert.deepEqual((await getEngineNames()).sort(), [ "Example", "Plain", "Special", ]); await forceExpiration(); Loading
toolkit/components/search/tests/xpcshell/xpcshell.ini +1 −0 Original line number Diff line number Diff line Loading @@ -75,3 +75,4 @@ support-files = [test_webextensions_builtin_upgrade.js] [test_distributions.js] skip-if = appname == "thunderbird" [test_maybereloadengine_order.js]