mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1673870 - [devtools] Fix browser_resources_getAllResources.js intermittent. r=ladybenko.
The test was failing because we were getting cached messages from a worker that were emitted late. To fix this, we create a dedicated document with workers only when we need them and remove workers from fission_document.html. This allows us to cleanup a few tests that were already working around the worker logs issue. Differential Revision: https://phabricator.services.mozilla.com/D122326
This commit is contained in:
parent
0a2e1728a4
commit
fd5c7b5193
@ -12,7 +12,9 @@ support-files =
|
||||
network_document.html
|
||||
early_console_document.html
|
||||
fission_document.html
|
||||
fission_document_workers.html
|
||||
fission_iframe.html
|
||||
fission_iframe_workers.html
|
||||
service-worker-sources.js
|
||||
sources.html
|
||||
sources.js
|
||||
|
@ -47,12 +47,6 @@ async function testTabConsoleMessagesResources(executeInIframe) {
|
||||
const onRuntimeDone = new Promise(resolve => (runtimeDoneResolve = resolve));
|
||||
const onAvailable = resources => {
|
||||
for (const resource of resources) {
|
||||
if (resource.message.arguments?.[0] === "[WORKER] started") {
|
||||
// XXX Ignore message from workers as we can't know when they're logged, and we
|
||||
// have a dedicated test for them (browser_resources_console_messages_workers.js).
|
||||
continue;
|
||||
}
|
||||
|
||||
is(
|
||||
resource.resourceType,
|
||||
resourceCommand.TYPES.CONSOLE_MESSAGE,
|
||||
@ -105,12 +99,6 @@ async function testTabConsoleMessagesResources(executeInIframe) {
|
||||
|
||||
targetCommand.destroy();
|
||||
await client.close();
|
||||
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
|
||||
// registrationPromise is set by the test page.
|
||||
const registration = await content.wrappedJSObject.registrationPromise;
|
||||
registration.unregister();
|
||||
});
|
||||
}
|
||||
|
||||
async function testTabConsoleMessagesResourcesWithIgnoreExistingResources(
|
||||
@ -178,12 +166,6 @@ async function testTabConsoleMessagesResourcesWithIgnoreExistingResources(
|
||||
|
||||
targetCommand.destroy();
|
||||
await client.close();
|
||||
|
||||
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
|
||||
// registrationPromise is set by the test page.
|
||||
const registration = await content.wrappedJSObject.registrationPromise;
|
||||
registration.unregister();
|
||||
});
|
||||
}
|
||||
|
||||
async function logExistingMessages(browser, executeInIframe) {
|
||||
|
@ -35,13 +35,7 @@ async function testCrossProcessTabNavigation(browser, resourceCommand) {
|
||||
const onConsoleLogsComplete = new Promise(resolve => (doneResolve = resolve));
|
||||
|
||||
const onAvailable = resources => {
|
||||
messages.push(
|
||||
// Ignore all unexpected messages from workers as they are not
|
||||
// useful here and they are tested elsewhere.
|
||||
...resources.filter(
|
||||
r => !r.message.arguments[0].startsWith("[WORKER] started")
|
||||
)
|
||||
);
|
||||
messages.push(...resources);
|
||||
if (messages.length == 2) {
|
||||
doneResolve();
|
||||
}
|
||||
|
@ -5,9 +5,9 @@
|
||||
|
||||
// Test the ResourceCommand API around CONSOLE_MESSAGE in workers
|
||||
|
||||
const FISSION_TEST_URL = URL_ROOT_SSL + "fission_document.html";
|
||||
const FISSION_TEST_URL = URL_ROOT_SSL + "fission_document_workers.html";
|
||||
const WORKER_FILE = "test_worker.js";
|
||||
const IFRAME_FILE = `${URL_ROOT_ORG_SSL}fission_iframe.html`;
|
||||
const IFRAME_FILE = `${URL_ROOT_ORG_SSL}fission_iframe_workers.html`;
|
||||
|
||||
add_task(async function() {
|
||||
// Set the following pref to false as it's the one that enables direct connection
|
||||
|
@ -35,7 +35,20 @@ add_task(async function() {
|
||||
info("Check the resources after some resources are available");
|
||||
const messages = ["a", "b", "c"];
|
||||
await logMessages(tab.linkedBrowser, messages);
|
||||
await waitUntil(() => availableResources.length >= messages.length);
|
||||
|
||||
try {
|
||||
await waitFor(() => availableResources.length === messages.length);
|
||||
} catch (e) {
|
||||
ok(
|
||||
false,
|
||||
`Didn't receive the expected number of resources. Got ${
|
||||
availableResources.length
|
||||
}, expected ${messages.length} - ${availableResources
|
||||
.map(r => r.message.arguments[0])
|
||||
.join(" - ")}`
|
||||
);
|
||||
}
|
||||
|
||||
assertResources(
|
||||
resourceCommand.getAllResources(resourceCommand.TYPES.CONSOLE_MESSAGE),
|
||||
availableResources
|
||||
@ -55,12 +68,27 @@ add_task(async function() {
|
||||
);
|
||||
|
||||
info("Append some resources again to test unwatching");
|
||||
const newMessages = ["d", "e", "f"];
|
||||
await logMessages(tab.linkedBrowser, messages);
|
||||
await waitUntil(
|
||||
() =>
|
||||
resourceCommand.getAllResources(resourceCommand.TYPES.CONSOLE_MESSAGE)
|
||||
.length === messages.length
|
||||
);
|
||||
try {
|
||||
await waitFor(
|
||||
() =>
|
||||
resourceCommand.getAllResources(resourceCommand.TYPES.CONSOLE_MESSAGE)
|
||||
.length === newMessages.length
|
||||
);
|
||||
} catch (e) {
|
||||
const resources = resourceCommand.getAllResources(
|
||||
resourceCommand.TYPES.CONSOLE_MESSAGE
|
||||
);
|
||||
ok(
|
||||
false,
|
||||
`Didn't receive the expected number of resources. Got ${
|
||||
resources.length
|
||||
}, expected ${messages.length} - ${resources
|
||||
.map(r => r.message.arguments.join(" | "))
|
||||
.join(" - ")}`
|
||||
);
|
||||
}
|
||||
|
||||
info("Check the resources after unwatching");
|
||||
resourceCommand.unwatchResources([resourceCommand.TYPES.CONSOLE_MESSAGE], {
|
||||
@ -90,8 +118,8 @@ function assertResources(resources, expectedResources) {
|
||||
}
|
||||
|
||||
function logMessages(browser, messages) {
|
||||
return ContentTask.spawn(browser, { messages }, args => {
|
||||
for (const message of args.messages) {
|
||||
return SpecialPowers.spawn(browser, [messages], innerMessages => {
|
||||
for (const message of innerMessages) {
|
||||
content.console.log(message);
|
||||
}
|
||||
});
|
||||
|
@ -28,13 +28,7 @@ add_task(async function() {
|
||||
);
|
||||
const availableResources = [];
|
||||
const onAvailable = resources => {
|
||||
// Ignore message coming from shared worker started by previous tests and
|
||||
// logging late a console message
|
||||
resources
|
||||
.filter(r => {
|
||||
return !r.message.arguments[0].startsWith("[WORKER] started");
|
||||
})
|
||||
.map(r => availableResources.push(r));
|
||||
availableResources.push(...resources);
|
||||
};
|
||||
await resourceCommand.watchResources([CONSOLE_MESSAGE], { onAvailable });
|
||||
|
||||
|
@ -5,30 +5,6 @@
|
||||
<title>Test fission document</title>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
const params = new URLSearchParams(document.location.search);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const worker = new Worker("https://example.com/browser/devtools/shared/commands/resource/tests/test_worker.js#simple-worker");
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const sharedWorker = new SharedWorker("https://example.com/browser/devtools/shared/commands/resource/tests/test_worker.js#shared-worker");
|
||||
|
||||
if (!params.has("noServiceWorker")) {
|
||||
// Expose a reference to the registration so that tests can unregister it.
|
||||
window.registrationPromise = navigator.serviceWorker.register("https://example.com/browser/devtools/shared/commands/resource/tests/test_service_worker.js#service-worker");
|
||||
}
|
||||
|
||||
/* exported logMessageInWorker */
|
||||
function logMessageInWorker(message) {
|
||||
worker.postMessage({
|
||||
type: "log-in-worker",
|
||||
message,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>Test fission iframe</p>
|
||||
|
@ -0,0 +1,47 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>Test fission document</title>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<script>
|
||||
"use strict";
|
||||
|
||||
const params = new URLSearchParams(document.location.search);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const worker = new Worker("https://example.com/browser/devtools/shared/commands/resource/tests/test_worker.js#simple-worker");
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const sharedWorker = new SharedWorker("https://example.com/browser/devtools/shared/commands/resource/tests/test_worker.js#shared-worker");
|
||||
|
||||
if (!params.has("noServiceWorker")) {
|
||||
// Expose a reference to the registration so that tests can unregister it.
|
||||
window.registrationPromise = navigator.serviceWorker.register("https://example.com/browser/devtools/shared/commands/resource/tests/test_service_worker.js#service-worker");
|
||||
}
|
||||
|
||||
/* exported logMessageInWorker */
|
||||
function logMessageInWorker(message) {
|
||||
worker.postMessage({
|
||||
type: "log-in-worker",
|
||||
message,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>Test fission iframe</p>
|
||||
|
||||
<script>
|
||||
"use strict";
|
||||
const iframe = document.createElement("iframe");
|
||||
let iframeUrl = `https://example.org/browser/devtools/shared/commands/resource/tests/fission_iframe_workers.html`;
|
||||
if (document.location.search) {
|
||||
iframeUrl += `?${new URLSearchParams(document.location.search)}`;
|
||||
}
|
||||
iframe.src = iframeUrl;
|
||||
document.body.append(iframe);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -5,23 +5,6 @@
|
||||
<title>Test fission iframe document</title>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<script>
|
||||
"use strict";
|
||||
const params = new URLSearchParams(document.location.search);
|
||||
const hashSuffix = params.get("hashSuffix") || "in-iframe";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const worker = new Worker("test_worker.js#simple-worker-" + hashSuffix);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const sharedWorker = new SharedWorker("test_worker.js#shared-worker-" + hashSuffix);
|
||||
|
||||
/* exported logMessageInWorker */
|
||||
function logMessageInWorker(message) {
|
||||
worker.postMessage({
|
||||
type: "log-in-worker",
|
||||
message,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>remote iframe</p>
|
||||
|
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>Test fission iframe document</title>
|
||||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
- http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<script>
|
||||
"use strict";
|
||||
const params = new URLSearchParams(document.location.search);
|
||||
const hashSuffix = params.get("hashSuffix") || "in-iframe";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const worker = new Worker("test_worker.js#simple-worker-" + hashSuffix);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const sharedWorker = new SharedWorker("test_worker.js#shared-worker-" + hashSuffix);
|
||||
|
||||
/* exported logMessageInWorker */
|
||||
function logMessageInWorker(message) {
|
||||
worker.postMessage({
|
||||
type: "log-in-worker",
|
||||
message,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p>remote iframe</p>
|
||||
</body>
|
||||
</html>
|
@ -3,8 +3,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
console.log("[WORKER] started", globalThis.location.toString(), globalThis);
|
||||
|
||||
globalThis.onmessage = function(e) {
|
||||
const { type, message } = e.data;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user