fune/toolkit/components/extensions/test/xpcshell/test_ext_test_wrapper.js
William Durand 64e8f3272d Bug 1797050 - Part 3 - Use browser_specific_settings instead of applications in existing WebExt tests. r=rpl,geckoview-reviewers,extension-reviewers,owlish
We want to encourage extension developers to use `browser_specific_settings` instead of `applications`,
which will be unsupported in Manifest Version 3+. This patch prepares the introduction of a new warning
(that is usually converted into an error in the test environment).

Differential Revision: https://phabricator.services.mozilla.com/D160059
2022-10-28 09:53:09 +00:00

62 lines
2 KiB
JavaScript

"use strict";
Services.prefs.setBoolPref("extensions.blocklist.enabled", false);
ChromeUtils.defineModuleGetter(
this,
"AddonManager",
"resource://gre/modules/AddonManager.jsm"
);
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",
"XPCShell",
"1",
"43"
);
const TEST_ADDON_ID = "@some-permanent-test-addon";
// Load a permanent extension that eventually unloads the extension immediately
// after add-on startup, to set the stage as a regression test for bug 1575190.
add_task(async function setup_wrapper() {
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
browser_specific_settings: { gecko: { id: TEST_ADDON_ID } },
},
background() {
browser.test.sendMessage("started_up");
},
});
await AddonTestUtils.promiseStartupManager();
await extension.startup();
await extension.awaitBackgroundStarted();
await AddonTestUtils.promiseShutdownManager();
// Check message because it is expected to be received while `startup()` was
// pending resolution.
info("Awaiting expected started_up message 1");
await extension.awaitMessage("started_up");
// Load AddonManager, and unload the extension as soon as it has started.
await AddonTestUtils.promiseStartupManager();
await extension.awaitBackgroundStarted();
await extension.unload();
await AddonTestUtils.promiseShutdownManager();
// Confirm that the extension has started when promiseStartupManager returned.
info("Awaiting expected started_up message 2");
await extension.awaitMessage("started_up");
});
// Check that the add-on from the previous test has indeed been uninstalled.
add_task(async function restart_addon_manager_after_extension_unload() {
await AddonTestUtils.promiseStartupManager();
let addon = await AddonManager.getAddonByID(TEST_ADDON_ID);
equal(addon, null, "Test add-on should have been removed");
await AddonTestUtils.promiseShutdownManager();
});