Backed out 2 changesets (bug 1766615, bug 1760451) for causing mochitest failures on test_ext_scripting_permissions.html. CLOSED TREE

Backed out changeset 4db3945f4fcb (bug 1760451)
Backed out changeset 74cf7a839ea5 (bug 1766615)
This commit is contained in:
Iulian Moraru 2022-05-06 17:43:46 +03:00
Родитель cf08170d87
Коммит ba4edef826
7 изменённых файлов: 29 добавлений и 195 удалений

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

@ -5,9 +5,7 @@
Services.prefs.setBoolPref("extensions.manifestV3.enabled", true);
async function testManifest(manifest, expectedError) {
ExtensionTestUtils.failOnSchemaWarnings(false);
let normalized = await ExtensionTestUtils.normalizeManifest(manifest);
ExtensionTestUtils.failOnSchemaWarnings(true);
if (expectedError) {
ok(
@ -77,6 +75,10 @@ add_task(async function test_manifest() {
});
add_task(async function test_action_version() {
// The above test validates these work with the correct version,
// here we verify they fail with the incorrect version for MV3.
ExtensionTestUtils.failOnSchemaWarnings(false);
let warnings = await testManifest({
manifest_version: 3,
browser_action: {
@ -102,22 +104,33 @@ add_task(async function test_action_version() {
[`Property "action" is unsupported in Manifest Version 2`],
`Manifest v2 with "action" key first warning is clear.`
);
ExtensionTestUtils.failOnSchemaWarnings(true);
});
add_task(async function test_mv2_scripting_permission_always_enabled() {
let warnings = await testManifest({
manifest_version: 2,
permissions: ["scripting"],
});
add_task(async function test_scripting_permission() {
ExtensionTestUtils.failOnSchemaWarnings(false);
Assert.deepEqual(warnings, [], "Got no warnings");
});
add_task(async function test_mv3_scripting_permission_always_enabled() {
// The "scripting" permission is only available in MV3.
let warnings = await testManifest({
manifest_version: 3,
permissions: ["scripting"],
});
Assert.deepEqual(warnings, [], "Got no warnings");
warnings = await testManifest({
manifest_version: 2,
permissions: ["scripting"],
});
equal(warnings.length, 1, "Got exactly one warning");
ok(
warnings[0]?.startsWith(
`Warning processing permissions: Error processing permissions.0: Value "scripting" must either:`
),
`Got the expected warning message: ${warnings[0]}`
);
ExtensionTestUtils.failOnSchemaWarnings(true);
});

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

@ -117,18 +117,14 @@ const makeInternalContentScript = details => {
scriptId: getUniqueId(),
options: {
allFrames: details.allFrames || false,
// Although this flag defaults to true with MV3, it is not with MV2.
// Check permissions at runtime since we aren't checking permissions
// upfront.
checkPermissions: true,
cssPaths: details.css || [],
excludeMatches: details.excludeMatches,
jsPaths: details.js || [],
matchAboutBlank: true,
matches: details.matches,
originAttributesPatterns: null,
persistAcrossSessions: details.persistAcrossSessions,
runAt: details.runAt || "document_idle",
persistAcrossSessions: details.persistAcrossSessions,
},
};
};

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

@ -10,7 +10,8 @@
"$extend": "OptionalPermissionNoPrompt",
"choices": [{
"type": "string",
"enum": ["scripting"]
"enum": ["scripting"],
"min_manifest_version": 3
}]
}
]
@ -19,6 +20,7 @@
"namespace": "scripting",
"description": "Use the scripting API to execute script in different contexts.",
"permissions": ["scripting"],
"min_manifest_version": 3,
"types": [
{
"id": "ScriptInjection",

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

@ -154,8 +154,6 @@ skip-if = os == 'android' # Bug 1615427
[test_ext_scripting_executeScript.html]
[test_ext_scripting_executeScript_injectImmediately.html]
[test_ext_scripting_insertCSS.html]
[test_ext_scripting_permissions.html]
skip-if = os == 'android' # Bug 1766852
[test_ext_scripting_removeCSS.html]
[test_ext_sendmessage_doublereply.html]
[test_ext_sendmessage_frameId.html]

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

@ -1,151 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests scripting APIs and permissions</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
const verifyRegisterContentScripts = async ({ manifest_version }) => {
let extension = ExtensionTestUtils.loadExtension({
manifest: {
manifest_version,
permissions: ["scripting"],
host_permissions: ["*://example.com/*"],
optional_permissions: ["*://example.org/*"],
},
async background() {
browser.test.onMessage.addListener(async (msg, value) => {
switch (msg) {
case "grant-permission":
let granted = await new Promise(resolve => {
browser.test.withHandlingUserInput(() => {
resolve(browser.permissions.request(value));
});
});
browser.test.assertTrue(granted, "permission request succeeded");
browser.test.sendMessage("permission-granted");
break;
default:
browser.test.fail(`invalid message received: ${msg}`);
}
});
await browser.scripting.registerContentScripts([
{
id: "script",
js: ["script.js"],
matches: [
"*://example.com/*",
"*://example.net/*",
"*://example.org/*",
],
persistAcrossSessions: false,
},
]);
browser.test.sendMessage("background-ready");
},
files: {
"script.js": () => {
browser.test.sendMessage(
"script-ran",
window.location.host + window.location.search
);
},
},
});
await extension.startup();
await extension.awaitMessage("background-ready");
if (manifest_version > 2) {
extension.sendMessage("grant-permission", {
origins: ["*://example.com/*"],
});
await extension.awaitMessage("permission-granted");
}
// `example.net` is not declared in the list of `permissions`.
let tabExampleNet = await AppTestDelegate.openNewForegroundTab(
window,
"https://example.net/",
true
);
// `example.org` is listed in `optional_permissions`.
let tabExampleOrg = await AppTestDelegate.openNewForegroundTab(
window,
"https://example.org/",
true
);
// `example.com` is listed in `permissions`.
let tabExampleCom = await AppTestDelegate.openNewForegroundTab(
window,
"https://example.com/",
true
);
let value = await extension.awaitMessage("script-ran");
ok(
value === "example.com",
`expected: example.com, received: ${value}`
);
extension.sendMessage("grant-permission", {
origins: ["*://example.org/*"],
});
await extension.awaitMessage("permission-granted");
let tabExampleOrg2 = await AppTestDelegate.openNewForegroundTab(
window,
"https://example.org/?2",
true
);
value = await extension.awaitMessage("script-ran");
ok(
value === "example.org?2",
`expected: example.org?2, received: ${value}`
);
await AppTestDelegate.removeTab(window, tabExampleNet);
await AppTestDelegate.removeTab(window, tabExampleOrg);
await AppTestDelegate.removeTab(window, tabExampleCom);
await AppTestDelegate.removeTab(window, tabExampleOrg2);
await extension.unload();
};
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [
// TODO: remove the pref below when Bug 1766822 has been fixed.
["dom.ipc.processPrelaunch.enabled", false],
["extensions.manifestV3.enabled", true],
["extensions.webextOptionalPermissionPrompts", false],
],
});
});
add_task(async function test_scripting_registerContentScripts_mv2() {
await verifyRegisterContentScripts({ manifest_version: 2 });
});
add_task(async function test_scripting_registerContentScripts_mv3() {
await verifyRegisterContentScripts({ manifest_version: 3 });
});
</script>
</body>
</html>

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

@ -1,23 +0,0 @@
"use strict";
add_task(async function test_scripting_enabled_in_mv2() {
const extension = ExtensionTestUtils.loadExtension({
manifest: {
manifest_version: 2,
permissions: ["scripting"],
},
background() {
browser.test.assertEq(
"object",
typeof browser.scripting,
"expected scripting namespace to be defined"
);
browser.test.sendMessage("background-done");
},
});
await extension.startup();
await extension.awaitMessage("background-done");
await extension.unload();
});

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

@ -38,7 +38,7 @@ skip-if = appname == "thunderbird" || os == "android"
[test_ext_cache_api.js]
[test_ext_captivePortal.js]
# As with test_captive_portal_service.js, we use the same limits here.
skip-if =
skip-if =
appname == "thunderbird"
os == "android" # CP service is disabled on Android
(os == "mac" && debug) # macosx1014/debug due to 1564534
@ -213,7 +213,6 @@ skip-if =
os == "linux" && debug && fission # Bug 1762638
os == "mac" && debug && fission # Bug 1762638
[test_ext_scripting_contentScripts_file.js]
[test_ext_scripting_mv2.js]
[test_ext_scripting_updateContentScripts.js]
[test_ext_shared_workers.js]
[test_ext_shutdown_cleanup.js]