Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daleharvey/86331bb0a824ed6fdd903cc62f17eb93 to your computer and use it in GitHub Desktop.
Save daleharvey/86331bb0a824ed6fdd903cc62f17eb93 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";
XPCOMUtils.defineLazyModuleGetters(this, {
AddonManager: "resource://gre/modules/AddonManager.jsm",
});
const {
createAppInfo,
promiseShutdownManager,
promiseStartupManager,
} = AddonTestUtils;
SearchTestUtils.initXPCShellAddonManager(this);
let scopes = AddonManager.SCOPE_PROFILE | AddonManager.SCOPE_APPLICATION;
Services.prefs.setIntPref("extensions.enabledScopes", scopes);
const TEST_CONFIG = [
{
webExtension: { id: "[email protected]" },
appliesTo: [{ included: { everywhere: true } }],
},
];
async function getEngineNames() {
let engines = await Services.search.getEngines();
return engines.map(engine => engine._name);
}
async function installSystemSearchExtension(id) {
let xpi = await AddonTestUtils.createTempWebExtensionFile({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id } },
chrome_settings_overrides: {
search_provider: {
name: "Testing",
search_url: "https://example.com/",
search_url_get_params: "?q={searchTerms}",
},
},
},
background() {
browser.test.sendMessage("started");
},
});
let wrapper = ExtensionTestUtils.expectExtension(id);
const install = await AddonManager.getInstallForURL(`file://${xpi.path}`, {
locationName: "app-system-profile", // KEY_APP_SYSTEM_PROFILE
});
install.install();
await wrapper.awaitStartup();
await wrapper.awaitMessage("started");
return wrapper;
}
add_task(async function setup() {
await useTestEngines("test-extensions", null, TEST_CONFIG);
await promiseStartupManager();
registerCleanupFunction(promiseShutdownManager);
await Services.search.init();
});
add_task(async function basic_test() {
Assert.deepEqual(await getEngineNames(), ["Plain"]);
await installSystemSearchExtension("[email protected]");
Assert.deepEqual(await getEngineNames(), ["Plain"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment