Bug 1644188 - [devtools] Unregister service worker in all resourceWatcher/targetList tests. r=jdescottes

Not doing that, makes the browser_resources_sources.js test to fail because
of pending SW's target which comes with unexpected sources.

Differential Revision: https://phabricator.services.mozilla.com/D98460
This commit is contained in:
Alexandre Poirot 2020-12-08 13:12:11 +00:00
Родитель 53d3715f45
Коммит 1a154de122
11 изменённых файлов: 57 добавлений и 20 удалений

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

@ -102,6 +102,12 @@ async function testTabConsoleMessagesResources(executeInIframe) {
targetList.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(
@ -163,6 +169,12 @@ async function testTabConsoleMessagesResourcesWithIgnoreExistingResources(
await targetList.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) {

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

@ -213,6 +213,12 @@ add_task(async function() {
targetList.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();
});
});
function checkStartWorkerLogMessage(resource, expectedUrl) {

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

@ -130,6 +130,12 @@ add_task(async function() {
await targetList.stopListening();
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 assertResources(resources, expected) {

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

@ -23,7 +23,7 @@ add_task(async function() {
const client = await createLocalClient();
const mainRoot = client.mainRoot;
await addTab(FISSION_TEST_URL);
const tab = await addTab(FISSION_TEST_URL);
info("Test TargetList against workers via the parent process target");
@ -182,6 +182,12 @@ add_task(async function() {
await unregisterAllServiceWorkers(client);
await client.close();
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
// registrationPromise is set by the test page.
const registration = await content.wrappedJSObject.registrationPromise;
registration.unregister();
});
});
function sortFronts(f1, f2) {

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

@ -159,5 +159,10 @@ async function testTabFrames(mainRoot) {
targetList.destroy();
await waitForAllTargetsToBeAttached(targetList);
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
// registrationPromise is set by the test page.
const registration = await content.wrappedJSObject.registrationPromise;
registration.unregister();
});
BrowserTestUtils.removeTab(tab);
}

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

@ -23,7 +23,7 @@ add_task(async function() {
const client = await createLocalClient();
const mainRoot = client.mainRoot;
await addTab(FISSION_TEST_URL);
const tab = await addTab(FISSION_TEST_URL);
// Instantiate a worker in the parent process
// eslint-disable-next-line no-unused-vars
@ -100,4 +100,9 @@ add_task(async function() {
await waitForAllTargetsToBeAttached(targetList);
await client.close();
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
// registrationPromise is set by the test page.
const registration = await content.wrappedJSObject.registrationPromise;
registration.unregister();
});
});

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

@ -63,10 +63,10 @@ add_task(async function() {
);
info("Unregister the worker and wait until onDestroyed is called.");
SpecialPowers.spawn(tab.linkedBrowser, [], function() {
const win = content.wrappedJSObject;
// win.registration is set by the test page.
win.registration.unregister();
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
// registrationPromise is set by the test page.
const registration = await content.wrappedJSObject.registrationPromise;
registration.unregister();
});
await waitUntil(() => targets.length === 0);

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

@ -348,10 +348,11 @@ async function watchServiceWorkerTargets({
async function unregisterServiceWorker(tab, expectedPageUrl) {
await waitForRegistrationReady(tab, expectedPageUrl);
await SpecialPowers.spawn(tab.linkedBrowser, [], () =>
// win.registration is set by the test page.
content.wrappedJSObject.registration.unregister()
);
await SpecialPowers.spawn(tab.linkedBrowser, [], async () => {
// registrationPromise is set by the test page.
const registration = await content.wrappedJSObject.registrationPromise;
registration.unregister();
});
}
/**
@ -363,7 +364,7 @@ async function waitForRegistrationReady(tab, expectedPageUrl) {
try {
const win = content.wrappedJSObject;
const isExpectedUrl = win.location.href === _url;
const hasRegistration = !!win.registration;
const hasRegistration = !!win.registrationPromise;
return isExpectedUrl && hasRegistration;
} catch (e) {
return false;

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

@ -17,10 +17,8 @@
const sharedWorker = new SharedWorker("https://example.com/browser/devtools/shared/resources/tests/test_worker.js#shared-worker");
if (!params.has("noServiceWorker")) {
(async function () {
// Expose a reference to the registration so that tests can unregister it.
window.registration = await navigator.serviceWorker.register("https://example.com/browser/devtools/shared/resources/tests/test_service_worker.js#service-worker");
})();
// Expose a reference to the registration so that tests can unregister it.
window.registrationPromise = navigator.serviceWorker.register("https://example.com/browser/devtools/shared/resources/tests/test_service_worker.js#service-worker");
}
/* exported logMessageInWorker */

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

@ -15,7 +15,7 @@
// Assign the worker to a global variable in order to avoid
// having it be GCed.
this.worker = new Worker("worker-sources.js");
navigator.serviceWorker.register("service-worker-sources.js");
window.registrationPromise = navigator.serviceWorker.register("service-worker-sources.js");
</script>
<script src="sources.js"></script>
</body>

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

@ -12,10 +12,8 @@
<script>
"use strict";
(async function () {
// Expose a reference to the registration so that tests can unregister it.
window.registration = await navigator.serviceWorker.register("test_sw_page_worker.js");
})();
// Expose a reference to the registration so that tests can unregister it.
window.registrationPromise = navigator.serviceWorker.register("test_sw_page_worker.js");
</script>
</body>
</html>