Backed out changeset 64a0fc3e1e44 (bug 1762366) for causing failures on test_ext_scripting_executeScript_injectImmediately.html. CLOSED TREE

This commit is contained in:
Csoregi Natalia 2022-04-26 14:57:22 +03:00
parent a5d99bb713
commit 368001bc1d
5 changed files with 1 additions and 274 deletions

View file

@ -85,9 +85,7 @@ const execute = (context, details, kind, method) => {
options.frameIds = [0];
}
options.runAt = details.injectImmediately
? "document_start"
: "document_idle";
options.runAt = "document_idle";
options.matchAboutBlank = true;
options.wantReturnValue = true;
// With this option set to `true`, we'll receive executeScript() results with

View file

@ -52,11 +52,6 @@
"world": {
"$ref": "ExecutionWorld",
"optional": true
},
"injectImmediately": {
"type": "boolean",
"optional": true,
"description": "Whether the injection should be triggered in the target as soon as possible (but not necessarily prior to page load)."
}
}
},

View file

@ -1,49 +0,0 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80 ft=javascript: */
"use strict";
// This script slows the load of an HTML document so that we can reliably test
// all phases of the load cycle supported by the extension API.
/* eslint-disable no-unused-vars */
const URL = "file_slowed_document.sjs";
const DELAY = 2 * 1000; // Delay two seconds before completing the request.
let nsTimer = Components.Constructor(
"@mozilla.org/timer;1",
"nsITimer",
"initWithCallback"
);
let timer;
function handleRequest(request, response) {
response.processAsync();
response.setHeader("Content-Type", "text/html", false);
response.setHeader("Cache-Control", "no-cache", false);
response.write(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
`);
// Note: We need to store a reference to the timer to prevent it from being
// canceled when it's GCed.
timer = new nsTimer(
() => {
if (request.queryString.includes("with-iframe")) {
response.write(`<iframe src="${URL}?r=${Math.random()}"></iframe>`);
}
response.write(`</body></html>`);
response.finish();
},
DELAY,
Ci.nsITimer.TYPE_ONE_SHOT
);
}

View file

@ -32,7 +32,6 @@ support-files =
file_simple_xhr.html
file_simple_xhr_frame.html
file_simple_xhr_frame2.html
file_slowed_document.sjs
file_streamfilter.txt
file_style_bad.css
file_style_good.css
@ -152,7 +151,6 @@ skip-if = os == 'android' # Bug 1615427
[test_ext_script_filenames.html]
[test_ext_scripting_contentScripts.html]
[test_ext_scripting_executeScript.html]
[test_ext_scripting_executeScript_injectImmediately.html]
[test_ext_scripting_insertCSS.html]
[test_ext_scripting_removeCSS.html]
[test_ext_sendmessage_doublereply.html]

View file

@ -1,215 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tests scripting.executeScript() and injectImmediately</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 MOCHITEST_HOST_PERMISSIONS = [
"*://mochi.test/",
"*://mochi.xorigin-test/",
"*://test1.example.com/",
];
const makeExtension = ({ manifest: manifestProps, ...otherProps }) => {
return ExtensionTestUtils.loadExtension({
manifest: {
manifest_version: 3,
permissions: ["scripting"],
host_permissions: [
...MOCHITEST_HOST_PERMISSIONS,
// Used in `file_contains_iframe.html`
"https://example.org/",
],
granted_host_permissions: true,
...manifestProps,
},
useAddonManager: "temporary",
...otherProps,
});
};
add_task(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.manifestV3.enabled", true]],
});
});
add_task(async function test_executeScript_injectImmediately() {
let extension = makeExtension({
async background() {
const tabs = await browser.tabs.query({ active: true });
const tabId = tabs[0].id;
let onUpdatedPromise = (tabId, url, status) => {
return new Promise(resolve => {
browser.tabs.onUpdated.addListener(function listener(_, changed, tab) {
if (tabId == tab.id && changed.status == status && tab.url == url) {
browser.tabs.onUpdated.removeListener(listener);
resolve();
}
});
});
};
const url = [
"https://test1.example.com/tests/toolkit/components/extensions/test/mochitest/",
`file_slowed_document.sjs?with-iframe&r=${Math.random()}`,
].join("");
const loadingPromise = onUpdatedPromise(tabId, url, "loading");
const completePromise = onUpdatedPromise(tabId, url, "complete");
await browser.tabs.update(tabId, { url });
await loadingPromise;
const func = () => {
window.counter = (window.counter || 0) + 1;
return window.counter;
};
let results = await Promise.all([
// counter = 1
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: true,
}),
// counter = 3
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: false,
}),
// counter = 4
browser.scripting.executeScript({
target: { tabId },
func,
// `injectImmediately` is `false` by default
}),
// counter = 2
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: true,
}),
// counter = 5
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: false,
}),
]);
browser.test.assertEq(
5,
results.length,
"got expected number of results"
);
browser.test.assertEq(
"1 3 4 2 5",
results.map(res => res[0].result).join(" "),
`got expected results: ${JSON.stringify(results)}`
);
await completePromise;
browser.test.notifyPass("execute-script");
},
});
let tab = await AppTestDelegate.openNewForegroundTab(
window,
"about:blank",
true
);
await extension.startup();
await extension.awaitFinish("execute-script");
await extension.unload();
await AppTestDelegate.removeTab(window, tab);
});
add_task(async function test_executeScript_injectImmediately_after_document_idle() {
let extension = makeExtension({
async background() {
const tabs = await browser.tabs.query({ active: true });
browser.test.assertEq(1, tabs.length, "expected 1 tab");
const tabId = tabs[0].id;
const func = () => {
window.counter = (window.counter || 0) + 1;
return window.counter;
};
let results = await Promise.all([
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: true,
}),
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: false,
}),
browser.scripting.executeScript({
target: { tabId },
func,
// `injectImmediately` is `false` by default
}),
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: true,
}),
browser.scripting.executeScript({
target: { tabId },
func,
injectImmediately: false,
}),
]);
browser.test.assertEq(
5,
results.length,
"got expected number of results"
);
browser.test.assertEq(
"1 2 3 4 5",
results.map(res => res[0].result).join(" "),
`got expected results: ${JSON.stringify(results)}`
);
browser.test.notifyPass("execute-script");
},
});
let tab = await AppTestDelegate.openNewForegroundTab(
window,
"https://test1.example.com/tests/toolkit/components/extensions/test/mochitest/file_contains_iframe.html",
true
);
await extension.startup();
await extension.awaitFinish("execute-script");
await extension.unload();
await AppTestDelegate.removeTab(window, tab);
});
</script>
</body>
</html>