зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1563607 Part 5 - Add test for windowless service worker debugging, r=jdescottes.
Depends on D47544 Differential Revision: https://phabricator.services.mozilla.com/D47545 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
5fa2446c5e
Коммит
d673356e69
|
@ -159,6 +159,7 @@ skip-if = os == "win"
|
|||
[browser_dbg-windowless-workers.js]
|
||||
[browser_dbg-windowless-workers-early-breakpoint.js]
|
||||
[browser_dbg-worker-exception.js]
|
||||
[browser_dbg-windowless-service-workers.js]
|
||||
[browser_dbg-worker-scopes.js]
|
||||
skip-if = (os == 'linux' && debug) || (os == 'linux' && asan) || ccov #Bug 1456013, Bug 1559547
|
||||
[browser_dbg-event-handler.js]
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
|
||||
|
||||
// Test that we can detect a new service worker and hit breakpoints that we've
|
||||
// set in it.
|
||||
add_task(async function() {
|
||||
await pushPref("devtools.debugger.features.windowless-service-workers", true);
|
||||
await pushPref("devtools.debugger.workers-visible", true);
|
||||
await pushPref("dom.serviceWorkers.enabled", true);
|
||||
await pushPref("dom.serviceWorkers.testing.enabled", true);
|
||||
|
||||
let dbg = await initDebugger("doc-service-workers.html");
|
||||
|
||||
invokeInTab("registerWorker");
|
||||
|
||||
await waitForSource(dbg, "service-worker.js");
|
||||
const workerSource = findSource(dbg, "service-worker.js");
|
||||
|
||||
await addBreakpoint(dbg, "service-worker.js", 14);
|
||||
|
||||
invokeInTab("fetchFromWorker");
|
||||
|
||||
await waitForPaused(dbg);
|
||||
assertPausedAtSourceAndLine(dbg, workerSource.id, 14);
|
||||
|
||||
await dbg.actions.removeAllBreakpoints(getContext(dbg));
|
||||
|
||||
await resume(dbg);
|
||||
|
||||
// Leave the worker registration in place for the next task.
|
||||
|
||||
// Set startup breakpoint for the next test.
|
||||
//await addBreakpoint(dbg, "service-worker.js", 6);
|
||||
});
|
||||
|
||||
async function checkWorkerThreads(dbg, count) {
|
||||
await waitUntil(() => dbg.selectors.getThreads().length == count);
|
||||
ok(true, `Have ${count} threads`);
|
||||
}
|
||||
|
||||
// Test that service workers remain after reloading.
|
||||
add_task(async function() {
|
||||
const toolbox = await openNewTabAndToolbox(EXAMPLE_URL + "doc-service-workers.html", "jsdebugger");
|
||||
const dbg = createDebuggerContext(toolbox);
|
||||
|
||||
await checkWorkerThreads(dbg, 1);
|
||||
|
||||
await reload(dbg);
|
||||
|
||||
await waitForSource(dbg, "service-worker.js");
|
||||
const workerSource = findSource(dbg, "service-worker.js");
|
||||
|
||||
await addBreakpoint(dbg, "service-worker.js", 14);
|
||||
|
||||
invokeInTab("fetchFromWorker");
|
||||
|
||||
await waitForPaused(dbg);
|
||||
assertPausedAtSourceAndLine(dbg, workerSource.id, 14);
|
||||
await checkWorkerThreads(dbg, 1);
|
||||
|
||||
await resume(dbg);
|
||||
|
||||
invokeInTab("unregisterWorker");
|
||||
|
||||
await dbg.actions.removeAllBreakpoints(getContext(dbg));
|
||||
await checkWorkerThreads(dbg, 0);
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
<script>
|
||||
async function registerWorker() {
|
||||
const sw = navigator.serviceWorker;
|
||||
const swr = await sw.register("service-worker.js", { scope: "" });
|
||||
dump(`Registered, scope is: ${swr.scope}\n`);
|
||||
|
||||
await new Promise(resolve => {
|
||||
const worker = swr.installing || swr.waiting || swr.active;
|
||||
if (worker.state === 'activated') {
|
||||
return resolve();
|
||||
}
|
||||
|
||||
worker.addEventListener('statechange', () => {
|
||||
if (worker.state === 'activated') {
|
||||
return resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function unregisterWorker() {
|
||||
const sw = navigator.serviceWorker;
|
||||
const swr = await sw.register("service-worker.js", { scope: "" });
|
||||
return swr.unregister();
|
||||
}
|
||||
|
||||
async function fetchFromWorker() {
|
||||
const response = await fetch("whatever");
|
||||
const text = await response.text();
|
||||
console.log(`Response ${text}`);
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,20 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
dump("Starting\n");
|
||||
|
||||
self.addEventListener("activate", event => {
|
||||
dump("Activate\n");
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", event => {
|
||||
const url = event.request.url;
|
||||
dump(`Fetch: ${url}\n`);
|
||||
if (url.includes("whatever")) {
|
||||
const response = new Response("Service worker response", { statusText: "OK" });
|
||||
event.respondWith(response);
|
||||
}
|
||||
});
|
Загрузка…
Ссылка в новой задаче