Bug 1641735 - Replace unnecessary uses of useAddonManager of ExtensionTestUtils.loadExtension r=zombie,agi,extension-reviewers

In mochitests on Android, ExtensionTestUtils.loadExtension defaults to
`useAddonManager: "android-only"` to allow Android tests to correctly
register with the AddonManager without unnecessarily forcing this
registration on desktop.

This patch removes all unnecessary uses of useAddonManager, to make it
obvious when a test really depends on the AddonManager (on desktop),
opposed to only depending on it indirectly as part of the GeckoView
implementation.

Differential Revision: https://phabricator.services.mozilla.com/D124088
This commit is contained in:
Rob Wu 2021-09-27 13:34:54 +00:00
Родитель 21328a3a9e
Коммит 8c0d686282
31 изменённых файлов: 15 добавлений и 180 удалений

Просмотреть файл

@ -18,9 +18,7 @@ add_task(async function() {
set: [["privacy.userContext.enabled", true]],
});
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
"applications": { "gecko": { "id": "tabs-create@tests.mozilla.org" } },
"permissions": ["tabs", "cookies"],
"background": {"page": "bg/background.html"},

Просмотреть файл

@ -93,13 +93,7 @@ add_task(async function testTabEvents() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
applications: {
gecko: {
id: "test_tabs_events@tests.mozilla.org",
},
},
},
useAddonManager: "permanent",
background,
});
@ -146,13 +140,7 @@ add_task(async function testTabRemovalEvent() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
applications: {
gecko: {
id: "test_tabs_removal@tests.mozilla.org",
},
},
},
useAddonManager: "permanent",
background,
});

Просмотреть файл

@ -217,15 +217,9 @@ add_task(async function testExecuteScript() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["http://mochi.test/", "http://example.com/", "webNavigation"],
applications: {
gecko: {
id: "test_execute_script@tests.mozilla.org",
},
},
},
background,
useAddonManager: "permanent",
files: {
"script.js": function() {

Просмотреть файл

@ -108,13 +108,7 @@ add_task(async function testExecuteScript() {
}
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
"applications": {
"gecko": {
"id": "execute-script-run-at@tests.mozilla.org",
}
},
"permissions": ["http://mochi.test/", "tabs"],
},
background: `(${background})(${AppConstants.DEBUG})`,

Просмотреть файл

@ -17,13 +17,7 @@ add_task(async function() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["tabs"],
applications: {
gecko: {
id: "test_ext_tabs_get@tests.mozilla.org",
},
}
},
useAddonManager: "permanent",
async background() {
const tab1 = await browser.tabs.create({});
const tab2 = await browser.tabs.create({});

Просмотреть файл

@ -15,9 +15,7 @@
add_task(async function() {
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
"applications": { "gecko": { "id": "get-current@tests.mozilla.org" } },
"permissions": ["tabs"],
},

Просмотреть файл

@ -20,11 +20,7 @@
add_task(async function test_tabs_goBack_goForward() {
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: {
gecko: { id: "goBack-goForward@tests.mozilla.org" },
},
permissions: ["tabs"],
},

Просмотреть файл

@ -16,11 +16,6 @@
add_task(async function test_onUpdated() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"applications": {
"gecko": {
"id": "test_on_updated@tests.mozilla.org",
},
},
"permissions": ["tabs"],
"content_scripts": [{
"matches": ["http://mochi.test/*/context_tabs_onUpdated_page.html"],
@ -29,7 +24,6 @@ add_task(async function test_onUpdated() {
}],
},
useAddonManager: "permanent",
background: function() {
const pageURL = "http://mochi.test:8888/tests/mobile/android/components/extensions/test/mochitest/context_tabs_onUpdated_page.html";
@ -101,21 +95,14 @@ add_task(async function test_onUpdated() {
await extension.unload();
});
function* do_test_update(name, background, withPermissions = true) {
const manifest = {
applications: {
gecko: {
id: "test_update_" + name + "@tests.mozilla.org",
},
},
};
function* do_test_update(background, withPermissions = true) {
const manifest = {};
if (withPermissions) {
manifest.permissions = ["tabs", "http://mochi.test/"];
}
const extension = ExtensionTestUtils.loadExtension({
manifest,
background,
useAddonManager: "permanent",
});
yield Promise.all([
@ -127,7 +114,7 @@ function* do_test_update(name, background, withPermissions = true) {
}
add_task(async function test_url() {
await do_test_update("url", function background() {
await do_test_update(function background() {
// Create a new tab for testing update.
browser.tabs.create({}, function(tab) {
browser.tabs.onUpdated.addListener(async function onUpdated(tabId, changeInfo) {
@ -149,7 +136,7 @@ add_task(async function test_url() {
});
add_task(async function test_title() {
await do_test_update("title", async function background() {
await do_test_update(async function background() {
const url = "http://mochi.test:8888/tests/mobile/android/components/extensions/test/mochitest/context_tabs_onUpdated_page.html";
const tab = await browser.tabs.create({url});
@ -169,7 +156,7 @@ add_task(async function test_title() {
});
add_task(async function test_without_tabs_permission() {
await do_test_update("tabs_permission", async function background() {
await do_test_update(async function background() {
const url = "http://mochi.test:8888/tests/mobile/android/components/extensions/test/mochitest/context_tabs_onUpdated_page.html";
const tab = await browser.tabs.create({url});
let count = 0;

Просмотреть файл

@ -17,11 +17,6 @@ add_task(async function tabsSendMessageReply() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
"applications": {
"gecko": {
"id": "test_send_message_reply@tests.mozilla.org",
},
},
"content_scripts": [{
"matches": ["http://example.com/"],
"js": ["content-script.js"],
@ -29,8 +24,6 @@ add_task(async function tabsSendMessageReply() {
}],
},
useAddonManager: "permanent",
background: async function() {
// eslint-disable-next-line prefer-const
let firstTab;
@ -162,11 +155,6 @@ add_task(async function tabsSendHidden() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
"applications": {
"gecko": {
"id": "test_send_hidden@tests.mozilla.org",
},
},
"content_scripts": [{
"matches": ["http://example.com/content*"],
"js": ["content-script.js"],
@ -174,8 +162,6 @@ add_task(async function tabsSendHidden() {
}],
},
useAddonManager: "permanent",
background: async function() {
let resolveContent;
browser.runtime.onMessage.addListener((msg, sender) => {
@ -251,15 +237,8 @@ add_task(async function tabsSendMessageNoExceptionOnNonExistentTab() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
"applications": {
"gecko": {
"id": "test_send_hidden@tests.mozilla.org",
},
},
},
useAddonManager: "permanent",
async background() {
const url = "http://example.com/mochitest/tests/mobile/android/components/extensions/test/mochitest/file_dummy.html";
const tab = await browser.tabs.create({url});

Просмотреть файл

@ -15,9 +15,7 @@
async function testTabsUpdateURL(existentTabURL, tabsUpdateURL, isErrorExpected) {
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
"applications": { "gecko": { "id": "tabs-update-url@tests.mozilla.org" } },
"permissions": ["tabs"],
},

Просмотреть файл

@ -17,13 +17,7 @@ add_task(async function() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["webNavigation", "tabs"],
applications: {
gecko: {
id: "test_ext_webNavigation_onCommitted@tests.mozilla.org",
},
},
},
useAddonManager: "permanent",
async background() {
const url = "http://mochi.test:8888/";
const [tab, tabDetails] = await Promise.all([

Просмотреть файл

@ -30,15 +30,7 @@ add_task(async function test_background_canvas() {
}
}
let extensionData = {
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "background_canvas@tests.mozilla.org" } },
},
background,
};
let extension = ExtensionTestUtils.loadExtension(extensionData);
let extension = ExtensionTestUtils.loadExtension({ background });
await extension.startup();
await extension.awaitFinish("background-canvas");

Просмотреть файл

@ -60,10 +60,8 @@ add_task(async function testIndexedDB() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
background,
manifest: {
applications: { gecko: { id: "indexedDb@tests.mozilla.org" } },
permissions: ["browsingData", "tabs", "cookies"],
content_scripts: [
{

Просмотреть файл

@ -48,10 +48,8 @@ add_task(async function testPluginData() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
background,
manifest: {
applications: { gecko: { id: "remove-plugin@tests.mozilla.org" } },
permissions: ["tabs", "browsingData"],
},
});

Просмотреть файл

@ -73,10 +73,8 @@ add_task(async function testServiceWorkers() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
background,
manifest: {
applications: { gecko: { id: "service-workers@tests.mozilla.org" } },
permissions: ["browsingData", "tabs"],
content_scripts: [
{

Просмотреть файл

@ -30,10 +30,8 @@ add_task(async function testSettings() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
background,
manifest: {
applications: { gecko: { id: "browsingData-settings@tests.mozilla.org" } },
permissions: ["browsingData"],
},
});

Просмотреть файл

@ -46,9 +46,7 @@ function makeExtension(background) {
}
return ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: `active-tab@tests.mozilla.org` } },
permissions: ["activeTab", "webNavigation"],
},
background: `${awaitLoad}\n${gatherFrameSources}\n${ExtensionTestCommon.serializeScript(background)}`,

Просмотреть файл

@ -35,18 +35,14 @@ add_task(async function test_drawWindow() {
};
const first = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "draw_window_first@tests.mozilla.org" } },
permissions,
content_scripts
},
files
});
const second = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "draw_window_second@tests.mozilla.org" } },
content_scripts
},
files
@ -105,18 +101,14 @@ add_task(async function test_tainted_canvas() {
};
const first = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "draw_window_first@tests.mozilla.org" } },
permissions,
content_scripts
},
files
});
const second = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "draw_window_second@tests.mozilla.org" } },
content_scripts
},
files

Просмотреть файл

@ -30,9 +30,7 @@ add_task(async function test_contentscript() {
}
let extensionData = {
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "contentscript@tests.mozilla.org" } },
permissions: ["<all_urls>"],
},
background,

Просмотреть файл

@ -346,11 +346,9 @@ add_task(async function test_cookies() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
incognitoOverride: "spanning",
background,
manifest: {
applications: { gecko: { id: "cookies@tests.mozilla.org" } },
permissions: ["cookies", "*://example.org/", "*://[2a03:4000:6:310e:216:3eff:fe53:99b]/", "*://192.168.1.1/", "webNavigation", "browsingData"],
},
});

Просмотреть файл

@ -39,9 +39,7 @@ add_task(async function test_target_blank_link_no_opener_from_privileged() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "target_blank_link@tests.mozilla.org" } },
content_scripts: [{
js: ["content_script.js"],
matches: ["http://example.com/*"],

Просмотреть файл

@ -28,9 +28,7 @@ add_task(async function setup() {
add_task(async function test_urlClassification() {
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: {gecko: {id: "classification@mochi.test"}},
permissions: ["webRequest", "webRequestBlocking", "proxy", "<all_urls>"],
},
background() {

Просмотреть файл

@ -13,10 +13,6 @@ add_task(async function test_sendMessage_frameId() {
const html = `<!doctype html><meta charset="utf-8"><script src="script.js"><\/script>`;
const extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "send_message_frame_id@tests.mozilla.org" } },
},
background() {
browser.runtime.onMessage.addListener((msg, sender) => {
browser.test.sendMessage(msg, sender);

Просмотреть файл

@ -133,14 +133,12 @@ function makeExtension(id, otherId) {
let args = `${token}, ${JSON.stringify(id)}, ${JSON.stringify(otherId)}`;
let extensionData = {
useAddonManager: "permanent",
background: `(${backgroundScript})(${args})`,
manifest: {
"applications": {"gecko": {id}},
"permissions": ["tabs"],
"content_scripts": [{
"matches": ["http://mochi.test/*/file_sample.html"],
"js": ["content_script.js"],

Просмотреть файл

@ -92,8 +92,6 @@ add_task(async function test_storage_smoke_test() {
browser.test.sendMessage("done");
},
// Note: when Android supports sync on the java layer we will need to add
// useAddonManager: "permanent" here. Bug 1625257
manifest: {
permissions: ["storage"],
},

Просмотреть файл

@ -191,10 +191,8 @@ add_task(async function valid_cookieStoreId() {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
permissions: ["tabs", "cookies"],
applications: { gecko: { id: "cookiestoreid@tests.mozilla.org" } },
},
files: {
"blank.html": `<html><head><meta charset="utf-8"></head></html>`,

Просмотреть файл

@ -35,11 +35,7 @@ async function testHasPermission(params) {
}
let extension = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "executeScript@tests.mozilla.org" } },
...params.manifest,
},
manifest: params.manifest,
background: `(${background})(${contentSetup})`,

Просмотреть файл

@ -19,16 +19,9 @@ const URL2 =
const helperExtensionDef = {
manifest: {
applications: {
gecko: {
id: "helper@tests.mozilla.org",
},
},
permissions: ["webNavigation", "<all_urls>"],
},
useAddonManager: "permanent",
async background() {
browser.test.onMessage.addListener(async message => {
switch (message.subject) {
@ -125,16 +118,9 @@ async function test_query(testCases, permissions) {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
applications: {
gecko: {
id: "permissions@tests.mozilla.org",
},
},
permissions,
},
useAddonManager: "permanent",
async background() {
// wait for start message
const [testCases, tabIdFromURL1, tabIdFromURL2] = await new Promise(
@ -409,16 +395,9 @@ async function test_restricted_properties(
const extension = ExtensionTestUtils.loadExtension({
manifest: {
applications: {
gecko: {
id: "permissions@tests.mozilla.org",
},
},
permissions,
},
useAddonManager: "permanent",
async background() {
// wait for test start signal and data
const [
@ -566,16 +545,9 @@ async function test_onUpdateFilter(testCases, permissions) {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
applications: {
gecko: {
id: "permissions@tests.mozilla.org",
},
},
permissions,
},
useAddonManager: "permanent",
async background() {
let listenerGotCalled = false;
function onUpdateListener(tabId, changeInfo, tab) {

Просмотреть файл

@ -83,7 +83,7 @@ add_task(async function test_filter_tabId_and_windowId() {
} catch (e) {
browser.test.fail(`Unexpected test failure: ${e} :: ${e.stack}`);
}
browser.test.sendMessage("testCompleted");
browser.runtime.sendMessage("testCompleted");
}
function background() {
@ -94,6 +94,13 @@ add_task(async function test_filter_tabId_and_windowId() {
if (msg === "triggerBackgroundRequest") {
await fetch("http://example.com/?bg");
}
if (msg === "testCompleted") {
await browser.tabs.remove(sender.tab.id);
browser.test.sendMessage("testCompleted");
}
});
browser.tabs.create({
url: browser.runtime.getURL("tab.html"),
});
}
@ -105,7 +112,6 @@ add_task(async function test_filter_tabId_and_windowId() {
"webRequestBlocking",
"http://example.com/*",
],
web_accessible_resources: ["tab.html"],
},
background,
files: {
@ -115,15 +121,6 @@ add_task(async function test_filter_tabId_and_windowId() {
});
await extension.startup();
// bug 1641735: tabs.create / tabs.remove does not work in GeckoView unless
// `useAddonManager: "permanent"` is used, so use window.open() instead.
//
// Note that somehow window.open() unexpectedly runs null when extensions
// run in-process, i.e. extensions.webextensions.remote=false. Fortunately,
// extension tabs are automatically closed as part of extension.unload()
// below (provided that extension APIs are used in the tab - bug 1399655).
window.open(`moz-extension://${extension.uuid}/tab.html`);
await extension.awaitMessage("testCompleted");
await extension.unload();
});

Просмотреть файл

@ -260,9 +260,7 @@ add_task(async function test_webRequest_tabId() {
}
let tabExt = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "web_request_tab_id@tests.mozilla.org" } },
permissions: [
"tabs",
],
@ -318,9 +316,7 @@ add_task(async function test_webRequest_tabId_browser() {
let pageUrl = `${SimpleTest.getTestFileURL("file_sample.html")}?nocache=${Math.random()}`;
let tabExt = ExtensionTestUtils.loadExtension({
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "tab_id_browser@tests.mozilla.org" } },
permissions: [
"tabs",
],

Просмотреть файл

@ -33,9 +33,7 @@ async function test_connection_refused(url, expectedError) {
}
let extensionData = {
useAddonManager: "permanent",
manifest: {
applications: { gecko: { id: "connection_refused@tests.mozilla.org" } },
permissions: ["webRequest", "tabs", "*://badchain.include-subdomains.pinning.example.com/*"],
},
background: `(${background})("${url}", "${expectedError}")`,