mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
Bug 1686328 - Add some more tests for duplicate search engines. r=daleharvey
Differential Revision: https://phabricator.services.mozilla.com/D101497
This commit is contained in:
parent
49a9eeaf91
commit
d5e20890a4
@ -0,0 +1,133 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/*
|
||||
* Test initializing with an engine that's a duplicate of an app-provided
|
||||
* engine.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { getAppInfo } = ChromeUtils.import(
|
||||
"resource://testing-common/AppInfo.jsm"
|
||||
);
|
||||
|
||||
const enginesSettings = {
|
||||
version: SearchUtils.SETTINGS_VERSION,
|
||||
buildID: "TBD",
|
||||
appVersion: "TBD",
|
||||
locale: "en-US",
|
||||
metaData: {
|
||||
searchDefault: "Test search engine",
|
||||
searchDefaultHash: "TBD",
|
||||
// Intentionally in the past, but shouldn't actually matter for this test.
|
||||
searchDefaultExpir: 1567694909002,
|
||||
current: "",
|
||||
hash: "TBD",
|
||||
visibleDefaultEngines:
|
||||
"engine,engine-pref,engine-rel-searchform-purpose,engine-chromeicon,engine-resourceicon,engine-reordered",
|
||||
visibleDefaultEnginesHash: "TBD",
|
||||
},
|
||||
engines: [
|
||||
{
|
||||
_metaData: { alias: null },
|
||||
_isAppProvided: true,
|
||||
_name: "engine1",
|
||||
},
|
||||
{
|
||||
_metaData: { alias: null },
|
||||
_isAppProvided: true,
|
||||
_name: "engine2",
|
||||
},
|
||||
// This is a user-installed engine - the only one that was listed due to the
|
||||
// original issue.
|
||||
{
|
||||
_name: "engine1",
|
||||
_shortName: "engine1",
|
||||
_loadPath: "[test]oldduplicateversion",
|
||||
description: "An old near duplicate version of engine1",
|
||||
_iconURL:
|
||||
"data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAEAgQAhIOEAMjHyABIR0gA6ejpAGlqaQCpqKkAKCgoAPz9/AAZGBkAmJiYANjZ2ABXWFcAent6ALm6uQA8OjwAiIiIiIiIiIiIiI4oiL6IiIiIgzuIV4iIiIhndo53KIiIiB/WvXoYiIiIfEZfWBSIiIEGi/foqoiIgzuL84i9iIjpGIoMiEHoiMkos3FojmiLlUipYliEWIF+iDe0GoRa7D6GPbjcu1yIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||||
_iconMapObj: {
|
||||
'{"width":16,"height":16}':
|
||||
"data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAEAgQAhIOEAMjHyABIR0gA6ejpAGlqaQCpqKkAKCgoAPz9/AAZGBkAmJiYANjZ2ABXWFcAent6ALm6uQA8OjwAiIiIiIiIiIiIiI4oiL6IiIiIgzuIV4iIiIhndo53KIiIiB/WvXoYiIiIfEZfWBSIiIEGi/foqoiIgzuL84i9iIjpGIoMiEHoiMkos3FojmiLlUipYliEWIF+iDe0GoRa7D6GPbjcu1yIiIiIiIiIiIiIiIiIiIiIiIiIiIiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||||
},
|
||||
_metaData: {
|
||||
order: 1,
|
||||
},
|
||||
_urls: [
|
||||
{
|
||||
template: "https://example.com/?myquery={searchTerms}",
|
||||
rels: [],
|
||||
resultDomain: "example.com",
|
||||
params: [],
|
||||
},
|
||||
],
|
||||
queryCharset: "UTF-8",
|
||||
filePath: "TBD",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
add_task(async function setup() {
|
||||
await AddonTestUtils.promiseStartupManager();
|
||||
|
||||
// Allow telemetry probes which may otherwise be disabled for some applications (e.g. Thunderbird)
|
||||
Services.prefs.setBoolPref(
|
||||
"toolkit.telemetry.testing.overrideProductsCheck",
|
||||
true
|
||||
);
|
||||
|
||||
await SearchTestUtils.useTestEngines("data1");
|
||||
Services.prefs.setCharPref(SearchUtils.BROWSER_SEARCH_PREF + "region", "US");
|
||||
Services.locale.availableLocales = ["en-US"];
|
||||
Services.locale.requestedLocales = ["en-US"];
|
||||
|
||||
// We dynamically generate the hashes because these depend on the profile.
|
||||
enginesSettings.metaData.searchDefaultHash = SearchUtils.getVerificationHash(
|
||||
enginesSettings.metaData.searchDefault
|
||||
);
|
||||
enginesSettings.metaData.hash = SearchUtils.getVerificationHash(
|
||||
enginesSettings.metaData.current
|
||||
);
|
||||
enginesSettings.metaData.visibleDefaultEnginesHash = SearchUtils.getVerificationHash(
|
||||
enginesSettings.metaData.visibleDefaultEngines
|
||||
);
|
||||
let appInfo = getAppInfo();
|
||||
enginesSettings.buildID = appInfo.platformBuildID;
|
||||
enginesSettings.appVersion = appInfo.version;
|
||||
|
||||
await OS.File.writeAtomic(
|
||||
OS.Path.join(OS.Constants.Path.profileDir, SETTINGS_FILENAME),
|
||||
new TextEncoder().encode(JSON.stringify(enginesSettings)),
|
||||
{ compression: "lz4" }
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_cached_duplicate() {
|
||||
info("init search service");
|
||||
|
||||
let initResult = await Services.search.init();
|
||||
|
||||
info("init'd search service");
|
||||
Assert.ok(
|
||||
Components.isSuccessCode(initResult),
|
||||
"Should have successfully created the search service"
|
||||
);
|
||||
|
||||
let engine = await Services.search.getEngineByName("engine1");
|
||||
let submission = engine.getSubmission("foo");
|
||||
Assert.equal(
|
||||
submission.uri.spec,
|
||||
"https://1.example.com/search?q=foo",
|
||||
"Should have not changed the app provided engine."
|
||||
);
|
||||
|
||||
let engines = await Services.search.getEngines();
|
||||
|
||||
Assert.deepEqual(
|
||||
engines.map(e => e.name),
|
||||
["engine1", "engine2"],
|
||||
"Should have the expected default engines"
|
||||
);
|
||||
});
|
@ -67,6 +67,25 @@ add_task(async function basic_install_test() {
|
||||
Assert.deepEqual(await getEngineNames(), ["Plain", "Special"]);
|
||||
});
|
||||
|
||||
add_task(async function test_install_duplicate_engine() {
|
||||
let extension = await SearchTestUtils.installSearchExtension({
|
||||
name: "Plain",
|
||||
search_url: "https://example.com/plain",
|
||||
});
|
||||
|
||||
let engine = await Services.search.getEngineByName("Plain");
|
||||
let submission = engine.getSubmission("foo");
|
||||
Assert.equal(
|
||||
submission.uri.spec,
|
||||
"https://duckduckgo.com/?q=foo&t=ffsb",
|
||||
"Should have not changed the app provided engine."
|
||||
);
|
||||
|
||||
// User uninstalls their engine
|
||||
await extension.awaitStartup();
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function basic_multilocale_test() {
|
||||
await promiseSetHomeRegion("an");
|
||||
|
||||
|
@ -135,6 +135,7 @@ support-files =
|
||||
[test_selectedEngine.js]
|
||||
[test_sendSubmissionURL.js]
|
||||
[test_settings_broken.js]
|
||||
[test_settings_duplicate.js]
|
||||
[test_settings_good.js]
|
||||
[test_settings_ignorelist.js]
|
||||
support-files = data/search_ignorelist.json
|
||||
|
Loading…
Reference in New Issue
Block a user