summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/search/tests/xpcshell')
-rw-r--r--toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js36
-rw-r--r--toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml7
-rw-r--r--toolkit/components/search/tests/xpcshell/test_appProvided_engine.js90
-rw-r--r--toolkit/components/search/tests/xpcshell/test_missing_engine.js59
-rw-r--r--toolkit/components/search/tests/xpcshell/test_webextensions_startup.js111
-rw-r--r--toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js6
-rw-r--r--toolkit/components/search/tests/xpcshell/xpcshell.toml3
7 files changed, 249 insertions, 63 deletions
diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js b/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
index ed8e5147ee..8162fffae8 100644
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_ebay.js
@@ -56,6 +56,9 @@ const test = new SearchConfigTest({
],
},
{
+ regions: ["pl"],
+ },
+ {
regions: ["au", "be", "ca", "ch", "gb", "ie", "nl", "us"],
locales: ["en-US"],
},
@@ -79,6 +82,7 @@ const test = new SearchConfigTest({
locales: ["br", "unknown", "en-US", "fr", "fy-NL", "nl", "wo"],
},
],
+ excluded: [{ regions: ["pl"] }],
searchUrlCode: "mkrid=1553-53471-19255-0",
suggestUrlCode: "sId=23",
},
@@ -91,6 +95,7 @@ const test = new SearchConfigTest({
locales: ["de", "dsb", "hsb"],
},
],
+ excluded: [{ regions: ["pl"] }],
searchUrlCode: "mkrid=5221-53469-19255-0",
suggestUrlCode: "sId=16",
},
@@ -117,6 +122,9 @@ const test = new SearchConfigTest({
...DOMAIN_LOCALES["ebay-uk"],
],
},
+ {
+ regions: ["pl"],
+ },
],
searchUrlCode: "mkrid=706-53473-19255-0",
suggestUrlCode: "sId=2",
@@ -143,6 +151,9 @@ const test = new SearchConfigTest({
...DOMAIN_LOCALES["ebay-uk"],
],
},
+ {
+ regions: ["pl"],
+ },
],
searchUrlCode: "mkrid=5222-53480-19255-0",
suggestUrlCode: "sId=193",
@@ -155,7 +166,7 @@ const test = new SearchConfigTest({
locales: ["unknown", "en-US"],
},
],
- excluded: [{ regions: ["au", "be", "ca", "ch", "gb", "ie", "nl"] }],
+ excluded: [{ regions: ["au", "be", "ca", "ch", "gb", "ie", "nl", "pl"] }],
searchUrlCode: "mkrid=711-53200-19255-0",
suggestUrlCode: "sId=0",
},
@@ -168,6 +179,7 @@ const test = new SearchConfigTest({
locales: ["cy", "unknown", "en-GB", "en-US", "gd"],
},
],
+ excluded: [{ regions: ["pl"] }],
searchUrlCode: "mkrid=705-53470-19255-0",
suggestUrlCode: "sId=15",
},
@@ -183,6 +195,7 @@ const test = new SearchConfigTest({
locales: ["cy", "unknown", "en-GB", "en-US", "gd"],
},
],
+ excluded: [{ regions: ["pl"] }],
searchUrlCode: "mkrid=5282-53468-19255-0",
suggestUrlCode: "sId=205",
},
@@ -198,7 +211,7 @@ const test = new SearchConfigTest({
regions: ["gb"],
},
],
- excluded: [{ regions: ["au", "ie"] }],
+ excluded: [{ regions: ["au", "ie", "pl"] }],
searchUrlCode: "mkrid=710-53481-19255-0",
suggestUrlCode: "sId=3",
},
@@ -210,7 +223,7 @@ const test = new SearchConfigTest({
locales: DOMAIN_LOCALES["ebay-de"],
},
],
- excluded: [{ regions: ["at", "ch"] }],
+ excluded: [{ regions: ["at", "ch", "pl"] }],
searchUrlCode: "mkrid=707-53477-19255-0",
suggestUrlCode: "sId=77",
},
@@ -222,6 +235,7 @@ const test = new SearchConfigTest({
locales: DOMAIN_LOCALES["ebay-es"],
},
],
+ excluded: [{ regions: ["pl"] }],
searchUrlCode: "mkrid=1185-53479-19255-0",
suggestUrlCode: "sId=186",
},
@@ -233,7 +247,7 @@ const test = new SearchConfigTest({
locales: ["br", "fr", "wo"],
},
],
- excluded: [{ regions: ["be", "ca", "ch"] }],
+ excluded: [{ regions: ["be", "ca", "ch", "pl"] }],
searchUrlCode: "mkrid=709-53476-19255-0",
suggestUrlCode: "sId=71",
},
@@ -245,6 +259,7 @@ const test = new SearchConfigTest({
locales: DOMAIN_LOCALES["ebay-it"],
},
],
+ excluded: [{ regions: ["pl"] }],
searchUrlCode: "mkrid=724-53478-19255-0",
suggestUrlCode: "sId=101",
},
@@ -260,10 +275,21 @@ const test = new SearchConfigTest({
regions: ["nl"],
},
],
- excluded: [{ regions: ["be"] }],
+ excluded: [{ regions: ["be", "pl"] }],
searchUrlCode: "mkrid=1346-53482-19255-0",
suggestUrlCode: "sId=146",
},
+ {
+ domain: "www.ebay.pl",
+ telemetryId: "ebay-pl",
+ included: [
+ {
+ regions: ["pl"],
+ },
+ ],
+ searchUrlCode: "mkrid=4908-226936-19255-0",
+ suggestUrlCode: "sId=212",
+ },
],
});
diff --git a/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml b/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml
index 07567005d6..3bd896173c 100644
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.toml
@@ -28,7 +28,14 @@ requesttimeoutfactor = 2
["test_duckduckgo.js"]
+# The test_ebay needs newSearchConfig.enabled=true because there
+# are changes to ebay and locale pl for search-config-v2.
+# We have rolled out search-config-v2 100% to Beta 126 and the next Beta 127
+# will pick up newSearchConfig.enabled=true from Nimbus Settings but not
+# immediately, we need to turn the PREF on for this test to prevent failures
+# in the merge from central to Beta 127.
["test_ebay.js"]
+prefs = ["browser.search.newSearchConfig.enabled=true"]
["test_ecosia.js"]
diff --git a/toolkit/components/search/tests/xpcshell/test_appProvided_engine.js b/toolkit/components/search/tests/xpcshell/test_appProvided_engine.js
index 56297a9d2c..c983bdd666 100644
--- a/toolkit/components/search/tests/xpcshell/test_appProvided_engine.js
+++ b/toolkit/components/search/tests/xpcshell/test_appProvided_engine.js
@@ -68,6 +68,33 @@ let CONFIG = [
variants: [{ environment: { allRegionsAndLocales: true } }],
},
{
+ identifier: "override",
+ recordType: "engine",
+ base: {
+ classification: "unknown",
+ name: "override name",
+ urls: {
+ search: {
+ base: "https://www.example.com/search",
+ params: [
+ {
+ name: "old_param",
+ value: "old_value",
+ },
+ ],
+ searchTermParamName: "q",
+ },
+ },
+ },
+ variants: [
+ {
+ environment: {
+ locales: ["en-US"],
+ },
+ },
+ ],
+ },
+ {
recordType: "defaultEngines",
globalDefault: "engine_no_initial_icon",
specificDefaults: [],
@@ -78,6 +105,19 @@ let CONFIG = [
},
];
+const TEST_CONFIG_OVERRIDE = [
+ {
+ identifier: "override",
+ urls: {
+ search: {
+ params: [{ name: "new_param", value: "new_value" }],
+ },
+ },
+ telemetrySuffix: "tsfx",
+ clickUrl: "https://example.org/somewhere",
+ },
+];
+
add_setup(async function () {
await SearchTestUtils.useTestEngines("simple-engines", null, CONFIG);
await Services.search.init();
@@ -180,3 +220,53 @@ add_task(async function test_engine_with_some_params_set() {
"Should not have a trending URL"
);
});
+
+add_task(async function test_engine_remote_override() {
+ // First check the existing engine doesn't have the overrides.
+ let engine = Services.search.getEngineById(
+ "override@search.mozilla.orgdefault"
+ );
+ Assert.ok(engine, "Should have found the override engine");
+
+ Assert.equal(engine.name, "override name", "Should have the expected name");
+ Assert.equal(
+ engine.telemetryId,
+ "override",
+ "Should have the overridden telemetry suffix"
+ );
+ Assert.equal(
+ engine.getSubmission("test").uri.spec,
+ "https://www.example.com/search?old_param=old_value&q=test",
+ "Should have the overridden URL"
+ );
+ Assert.equal(engine.clickUrl, null, "Should not have a click URL");
+
+ // Now apply and test the overrides.
+ const overrides = await RemoteSettings(
+ SearchUtils.NEW_SETTINGS_OVERRIDES_KEY
+ );
+ sinon.stub(overrides, "get").returns(TEST_CONFIG_OVERRIDE);
+
+ await Services.search.wrappedJSObject.reset();
+ await Services.search.init();
+
+ engine = Services.search.getEngineById("override@search.mozilla.orgdefault");
+ Assert.ok(engine, "Should have found the override engine");
+
+ Assert.equal(engine.name, "override name", "Should have the expected name");
+ Assert.equal(
+ engine.telemetryId,
+ "override-tsfx",
+ "Should have the overridden telemetry suffix"
+ );
+ Assert.equal(
+ engine.getSubmission("test").uri.spec,
+ "https://www.example.com/search?new_param=new_value&q=test",
+ "Should have the overridden URL"
+ );
+ Assert.equal(
+ engine.clickUrl,
+ "https://example.org/somewhere",
+ "Should have the click URL specified by the override"
+ );
+});
diff --git a/toolkit/components/search/tests/xpcshell/test_missing_engine.js b/toolkit/components/search/tests/xpcshell/test_missing_engine.js
index 259baf9c1a..496397790e 100644
--- a/toolkit/components/search/tests/xpcshell/test_missing_engine.js
+++ b/toolkit/components/search/tests/xpcshell/test_missing_engine.js
@@ -2,7 +2,8 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
// This test is designed to check the search service keeps working if there's
-// a built-in engine missing from the configuration.
+// an application provided WebExtension missing that is referenced from the
+// configuration. Only applies to the old search configuration.
"use strict";
@@ -55,64 +56,16 @@ const BAD_CONFIG = [
},
];
-const CONFIG_V2 = [
- {
- recordType: "engine",
- identifier: "engine",
- base: {
- name: "Test search engine",
- urls: {
- search: {
- base: "https://www.google.com/search",
- params: [
- {
- name: "channel",
- searchAccessPoint: {
- addressbar: "fflb",
- contextmenu: "rcs",
- },
- },
- ],
- searchTermParamName: "q",
- },
- suggestions: {
- base: "https://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl={moz:locale}",
- searchTermParamName: "q",
- },
- },
- },
- variants: [
- {
- environment: { allRegionsAndLocales: true },
- },
- ],
- },
- {
- recordType: "defaultEngines",
- specificDefaults: [],
- },
- {
- recordType: "engineOrders",
- orders: [],
- },
-];
-
add_setup(async function () {
SearchTestUtils.useMockIdleService();
await AddonTestUtils.promiseStartupManager();
// This test purposely attempts to load a missing engine.
- consoleAllowList.push(
- "Could not load engine engine-missing@search.mozilla.org"
- );
+ consoleAllowList.push("Could not load engine");
});
add_task(async function test_startup_with_missing() {
- await SearchTestUtils.useTestEngines(
- "data",
- null,
- SearchUtils.newSearchConfigEnabled ? CONFIG_V2 : BAD_CONFIG
- );
+ await SearchTestUtils.useTestEngines("data", null, BAD_CONFIG);
const result = await Services.search.init();
Assert.ok(
@@ -135,7 +88,7 @@ add_task(async function test_update_with_missing() {
await RemoteSettings(SearchUtils.SETTINGS_KEY).emit("sync", {
data: {
- current: SearchUtils.newSearchConfigEnabled ? CONFIG_V2 : GOOD_CONFIG,
+ current: GOOD_CONFIG,
},
});
@@ -156,7 +109,7 @@ add_task(async function test_update_with_missing() {
await RemoteSettings(SearchUtils.SETTINGS_KEY).emit("sync", {
data: {
- current: SearchUtils.newSearchConfigEnabled ? CONFIG_V2 : BAD_CONFIG,
+ current: BAD_CONFIG,
},
});
diff --git a/toolkit/components/search/tests/xpcshell/test_webextensions_startup.js b/toolkit/components/search/tests/xpcshell/test_webextensions_startup.js
new file mode 100644
index 0000000000..0f106a2495
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_webextensions_startup.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests to ensure that WebExtensions correctly load on startup without errors.
+ */
+
+"use strict";
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ ExtensionTestUtils:
+ "resource://testing-common/ExtensionXPCShellUtils.sys.mjs",
+});
+
+const { promiseShutdownManager, promiseStartupManager } = AddonTestUtils;
+
+let extension;
+
+add_setup(async function () {
+ let server = useHttpServer();
+ server.registerContentType("sjs", "sjs");
+ await SearchTestUtils.useTestEngines("test-extensions");
+ await promiseStartupManager();
+
+ registerCleanupFunction(async () => {
+ await promiseShutdownManager();
+ });
+});
+
+add_task(async function test_startup_with_new_addon() {
+ // Although rare, handling loading an add-on on startup should work.
+ // Additionally, this sub-test allows us to pre-fill the search settings
+ // for the subsequent tests.
+
+ // Do not use SearchTestUtils.installSearchExtension, as we need to manually
+ // start the search service after installing the extension.
+ let extensionInfo = {
+ useAddonManager: "permanent",
+ files: {},
+ manifest: SearchTestUtils.createEngineManifest({
+ name: "startup",
+ search_url: "https://example.com/",
+ }),
+ };
+
+ extension = lazy.ExtensionTestUtils.loadExtension(extensionInfo);
+ await extension.startup();
+
+ let settingsWritten = promiseAfterSettings();
+ await Services.search.init();
+
+ await AddonTestUtils.waitForSearchProviderStartup(extension);
+ await settingsWritten;
+
+ let engine = await Services.search.getEngineByName("startup");
+ Assert.ok(engine, "Should have loaded the engine");
+ let submission = engine.getSubmission("foo");
+ Assert.equal(
+ submission.uri.spec,
+ "https://example.com/?q=foo",
+ "Should have the expected search url."
+ );
+});
+
+add_task(async function test_startup_with_existing_addon_from_settings() {
+ Services.search.wrappedJSObject.reset();
+
+ let settingsWritten = promiseAfterSettings();
+ await Services.search.init();
+ await settingsWritten;
+
+ let engine = await Services.search.getEngineByName("startup");
+ Assert.ok(engine, "Should have loaded the engine");
+ let submission = engine.getSubmission("foo");
+ Assert.equal(
+ submission.uri.spec,
+ "https://example.com/?q=foo",
+ "Should have the expected search url."
+ );
+});
+
+add_task(
+ async function test_startup_with_existing_addon_with_startup_notification() {
+ // Checks that we correctly load the add-on on startup when we are notified
+ // about it from the add-on manager before search has initialised. Also
+ // ensures that we don't raise an error when loading it from settings
+ // when the add-on is already there. The console check is handled by
+ // TestUtils.listenForConsoleMessages() in head_search.js.
+
+ Services.search.wrappedJSObject.reset();
+
+ await Services.search.addEnginesFromExtension(extension.extension);
+
+ let settingsWritten = promiseAfterSettings();
+ await Services.search.init();
+ await settingsWritten;
+
+ let engine = await Services.search.getEngineByName("startup");
+ Assert.ok(engine, "Should have loaded the engine");
+ let submission = engine.getSubmission("foo");
+ Assert.equal(
+ submission.uri.spec,
+ "https://example.com/?q=foo",
+ "Should have the expected search url."
+ );
+
+ await extension.unload();
+ }
+);
diff --git a/toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js b/toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js
index eb7e67e66e..cb7394d996 100644
--- a/toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js
+++ b/toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js
@@ -25,11 +25,7 @@ add_setup(async function () {
add_task(async function test_install_duplicate_engine_startup() {
let name = "Plain";
- let id = "plain@tests.mozilla.org";
- consoleAllowList.push(
- `#createAndAddAddonEngine failed for ${id}`,
- `An engine called ${name} already exists`
- );
+ consoleAllowList.push("#createAndAddAddonEngine failed for");
// Do not use SearchTestUtils.installSearchExtension, as we need to manually
// start the search service after installing the extension.
let extensionInfo = {
diff --git a/toolkit/components/search/tests/xpcshell/xpcshell.toml b/toolkit/components/search/tests/xpcshell/xpcshell.toml
index 899ac2d711..c21b98dffc 100644
--- a/toolkit/components/search/tests/xpcshell/xpcshell.toml
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.toml
@@ -180,6 +180,7 @@ tags = "remotesettings searchmain"
["test_migrateWebExtensionEngine.js"]
["test_missing_engine.js"]
+prefs = ["browser.search.newSearchConfig.enabled=false"]
["test_nodb_pluschanges.js"]
@@ -323,6 +324,8 @@ support-files = ["data/search-migration.json"]
["test_webextensions_startup_remove.js"]
+["test_webextensions_startup.js"]
+
["test_webextensions_upgrade.js"]
["test_webextensions_valid.js"]