Skip to content

Instantly share code, notes, and snippets.

@daleharvey
Created April 11, 2020 21:44
Show Gist options
  • Save daleharvey/d5bf7257da6552aaf82d9f894fbc1bf5 to your computer and use it in GitHub Desktop.
Save daleharvey/d5bf7257da6552aaf82d9f894fbc1bf5 to your computer and use it in GitHub Desktop.
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { ExtensionTestUtils } = ChromeUtils.import(
"resource://testing-common/ExtensionXPCShellUtils.jsm"
);
const {
createAppInfo,
promiseShutdownManager,
promiseStartupManager,
} = AddonTestUtils;
ExtensionTestUtils.init(this);
AddonTestUtils.usePrivilegedSignatures = false;
AddonTestUtils.overrideCertDB();
const TEST_CONFIG = [
{
webExtension: {
id: "[email protected]",
locales: ["af", "an"]
},
appliesTo: [{ included: { everywhere: true } }],
},
];
async function getEngineNames() {
let engines = await Services.search.getEngines();
return engines.map(engine => engine._name);
}
function createManifest(id, name, version, keyword) {
return {
useAddonManager: "permanent",
manifest: {
version,
applications: {
gecko: { id: `${id}@tests.mozilla.org` },
},
chrome_settings_overrides: {
search_provider: {
name,
keyword,
search_url: `https://example.com/?q={searchTerms}&version=${version}`,
},
},
},
};
}
add_task(async function setup() {
Services.prefs.setBoolPref("browser.search.gModernConfig", true);
await useTestEngines("test-extensions", null, TEST_CONFIG);
await promiseStartupManager();
registerCleanupFunction(promiseShutdownManager);
await Services.search.init();
});
add_task(async function basic_multilocale_test() {
Assert.deepEqual(await getEngineNames(), [
"Multilocale AF",
"Multilocale AN",
]);
let manifest = createManifest("multilocale", "Multilocale AF", "2.0", "bar");
const policy = WebExtensionPolicy.getByID("[email protected]");
await policy.extension.upgrade(manifest);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment