Bug 1458805 Make abort/serviceworker-intercepted.https.html WPT cases use unique scopes. r=baku
--- a/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html
+++ b/testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html
@@ -8,35 +8,28 @@
<script src="../../../service-workers/service-worker/resources/test-helpers.sub.js"></script>
</head>
<body>
<script>
// Duplicating this resource to make service worker scoping simpler.
const SCOPE = '../resources/basic.html';
const BODY_METHODS = ['arrayBuffer', 'blob', 'formData', 'json', 'text'];
- async function cleanup() {
- for (const iframe of document.querySelectorAll('.test-iframe')) {
- iframe.parentNode.removeChild(iframe);
- }
-
- const reg = await navigator.serviceWorker.getRegistration(SCOPE);
- if (reg) await reg.unregister();
- }
-
- async function setupRegistration(t) {
- await cleanup();
- const reg = await navigator.serviceWorker.register('../resources/sw-intercept.js', { scope: SCOPE });
+ async function setupRegistration(t, scope) {
+ const reg = await navigator.serviceWorker.register('../resources/sw-intercept.js', { scope });
await wait_for_state(t, reg.installing, 'activated');
+ add_completion_callback(_ => reg.unregister());
return reg;
}
promise_test(async t => {
- await setupRegistration(t);
- const iframe = await with_iframe(SCOPE);
+ const scope = SCOPE + "?q=aborted-not-intercepted";
+ await setupRegistration(t, scope);
+ const iframe = await with_iframe(scope);
+ add_completion_callback(_ => iframe.remove());
const w = iframe.contentWindow;
const controller = new w.AbortController();
const signal = controller.signal;
controller.abort();
const nextData = new Promise(resolve => {
w.navigator.serviceWorker.addEventListener('message', function once(event) {
@@ -51,18 +44,20 @@
await w.fetch('data.json?no-abort');
assert_true((await nextData).endsWith('?no-abort'), "Aborted request does not go through service worker");
}, "Already aborted request does not land in service worker");
for (const bodyMethod of BODY_METHODS) {
promise_test(async t => {
- await setupRegistration(t);
- const iframe = await with_iframe(SCOPE);
+ const scope = SCOPE + "?q=aborted-" + bodyMethod + "-rejects";
+ await setupRegistration(t, scope);
+ const iframe = await with_iframe(scope);
+ add_completion_callback(_ => iframe.remove());
const w = iframe.contentWindow;
const controller = new w.AbortController();
const signal = controller.signal;
const log = [];
const response = await w.fetch('data.json', { signal });
@@ -77,18 +72,20 @@
await promise_rejects(t, "AbortError", bodyPromise);
assert_array_equals(log, [`${bodyMethod}-reject`, 'next-microtask']);
}, `response.${bodyMethod}() rejects if already aborted`);
}
promise_test(async t => {
- await setupRegistration(t);
- const iframe = await with_iframe(SCOPE);
+ const scope = SCOPE + "?q=aborted-stream-errors";
+ await setupRegistration(t, scope);
+ const iframe = await with_iframe(scope);
+ add_completion_callback(_ => iframe.remove());
const w = iframe.contentWindow;
const controller = new w.AbortController();
const signal = controller.signal;
const response = await w.fetch('data.json', { signal });
const reader = response.body.getReader();