Bug 1458805 Make abort/serviceworker-intercepted.https.html WPT cases use unique scopes. r=baku
authorBen Kelly <ben@wanderview.com>
Thu, 03 May 2018 09:33:57 -0700
changeset 791188 f127f18d19a92a96a4d24eca336b1ef6839983e2
parent 791187 ad6447a9e9cec3caffc8addabca3898ee34ae947
child 791189 22adcf8598ed82665bf95ea7f15867ec743d63b4
push id108726
push userbmo:gl@mozilla.com
push dateThu, 03 May 2018 17:54:32 +0000
reviewersbaku
bugs1458805
milestone61.0a1
Bug 1458805 Make abort/serviceworker-intercepted.https.html WPT cases use unique scopes. r=baku
testing/web-platform/tests/fetch/api/abort/serviceworker-intercepted.https.html
--- 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();