Bug 1447040 [wpt PR 10096] - Correctly reject in-progress body methods with AbortError, a=testonly
authorAdam Rice <ricea@chromium.org>
Mon, 09 Apr 2018 17:24:13 +0000
changeset 467123 ca3375f6ba920ab96ad871db9eced0fb59c78d68
parent 467122 ea8086bdff4a225922f2c710dc440a46f2295c93
child 467124 ef900452e4c1c5f6b39c8679c716155a88295745
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1447040, 10096, 817687, 954765, 544335
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1447040 [wpt PR 10096] - Correctly reject in-progress body methods with AbortError, a=testonly Automatic update from web-platform-testsCorrectly reject in-progress body methods with AbortError Prior to this change, response body methods such as response.body.arrayBuffer() would reject with a TypeError if the fetch was aborted. This change makes them correctly reject with an AbortError instead. This implements stage #3 of the "Body Cancellation" section of the design doc: https://docs.google.com/document/d/1OuoCG2uiijbAwbCw9jaS7tHEO0LBO_4gMNio1ox0qlY/edit#heading=h.fvc7d7q07oio Bug: 817687 Change-Id: Ifde322d9c22485a8ba9d14fd4ffca65c4fb4745a Reviewed-on: https://chromium-review.googlesource.com/954765 Commit-Queue: Adam Rice <ricea@chromium.org> Reviewed-by: Matt Falkenhagen <falken@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Cr-Commit-Position: refs/heads/master@{#544335} wpt-commits: f2ae7641fad03150b4238a8b34dc9bdfdf58c0dd wpt-pr: 10096 wpt-commits: f2ae7641fad03150b4238a8b34dc9bdfdf58c0dd wpt-pr: 10096
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/lint.whitelist
testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-abort.js
testing/web-platform/tests/service-workers/cache-storage/serviceworker/cache-abort.https.html
testing/web-platform/tests/service-workers/cache-storage/window/cache-abort.https.html
testing/web-platform/tests/service-workers/cache-storage/worker/cache-abort.https.html
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -291597,16 +291597,21 @@
      {}
     ]
    ],
    "service-workers/cache-storage/resources/test-helpers.js": [
     [
      {}
     ]
    ],
+   "service-workers/cache-storage/script-tests/cache-abort.js": [
+    [
+     {}
+    ]
+   ],
    "service-workers/cache-storage/script-tests/cache-add.js": [
     [
      {}
     ]
    ],
    "service-workers/cache-storage/script-tests/cache-delete.js": [
     [
      {}
@@ -360089,16 +360094,22 @@
    "service-workers/cache-storage/common.https.html": [
     [
      "/service-workers/cache-storage/common.https.html",
      {
       "timeout": "long"
      }
     ]
    ],
+   "service-workers/cache-storage/serviceworker/cache-abort.https.html": [
+    [
+     "/service-workers/cache-storage/serviceworker/cache-abort.https.html",
+     {}
+    ]
+   ],
    "service-workers/cache-storage/serviceworker/cache-add.https.html": [
     [
      "/service-workers/cache-storage/serviceworker/cache-add.https.html",
      {
       "timeout": "long"
      }
     ]
    ],
@@ -360167,16 +360178,22 @@
     ]
    ],
    "service-workers/cache-storage/serviceworker/credentials.https.html": [
     [
      "/service-workers/cache-storage/serviceworker/credentials.https.html",
      {}
     ]
    ],
+   "service-workers/cache-storage/window/cache-abort.https.html": [
+    [
+     "/service-workers/cache-storage/window/cache-abort.https.html",
+     {}
+    ]
+   ],
    "service-workers/cache-storage/window/cache-add.https.html": [
     [
      "/service-workers/cache-storage/window/cache-add.https.html",
      {
       "timeout": "long"
      }
     ]
    ],
@@ -360247,16 +360264,22 @@
    "service-workers/cache-storage/window/sandboxed-iframes.https.html": [
     [
      "/service-workers/cache-storage/window/sandboxed-iframes.https.html",
      {
       "timeout": "long"
      }
     ]
    ],
+   "service-workers/cache-storage/worker/cache-abort.https.html": [
+    [
+     "/service-workers/cache-storage/worker/cache-abort.https.html",
+     {}
+    ]
+   ],
    "service-workers/cache-storage/worker/cache-add.https.html": [
     [
      "/service-workers/cache-storage/worker/cache-add.https.html",
      {
       "timeout": "long"
      }
     ]
    ],
@@ -391565,17 +391588,17 @@
    "f8af4287f3b0f6925a2a6c5c75b3788e24de1680",
    "support"
   ],
   "./config.default.json": [
    "54422ca469a8d54fa4b8252803bb0e2c91459858",
    "support"
   ],
   "./lint.whitelist": [
-   "b35324fd499dcb7ba0a9deedc794bb13ee62e175",
+   "697da251dd64d990c1ec0603fd252ba6ea11ad26",
    "support"
   ],
   "./serve.py": [
    "0efa39b1f26f86d73f2fce4f9e46003d62057b41",
    "support"
   ],
   "./server-side.md": [
    "c51b17fbac2a2e3121dc74f7badbd2873ce92f61",
@@ -592396,16 +592419,20 @@
   "service-workers/cache-storage/resources/simple.txt": [
    "50d3c65ca4a0fa1ae81d167e38426b8e57ae6dbe",
    "support"
   ],
   "service-workers/cache-storage/resources/test-helpers.js": [
    "fc315489c4d337f7cf8395beb4005be9c12da9d6",
    "support"
   ],
+  "service-workers/cache-storage/script-tests/cache-abort.js": [
+   "7c381e34a8e1444ad82645caf05ec8cbfe8360f8",
+   "support"
+  ],
   "service-workers/cache-storage/script-tests/cache-add.js": [
    "5807ce231254f89d9e5f2fc43955a8dda5bd865d",
    "support"
   ],
   "service-workers/cache-storage/script-tests/cache-delete.js": [
    "997017dfefc7c1f55cdc3122c2a58ff3d70b8141",
    "support"
   ],
@@ -592432,16 +592459,20 @@
   "service-workers/cache-storage/script-tests/cache-storage-match.js": [
    "e3cc14ea5d0587c43a5b142fca84788383b549cb",
    "support"
   ],
   "service-workers/cache-storage/script-tests/cache-storage.js": [
    "43a44ad35e90ce759de7a855f75b149b756029b4",
    "support"
   ],
+  "service-workers/cache-storage/serviceworker/cache-abort.https.html": [
+   "6b44436f3b2e1a463e64f3f5fc343086a295a975",
+   "testharness"
+  ],
   "service-workers/cache-storage/serviceworker/cache-add.https.html": [
    "294e76cb7b067b17fc9a0850bdab1d6e169cc25a",
    "testharness"
   ],
   "service-workers/cache-storage/serviceworker/cache-delete.https.html": [
    "6484fca817f556be3ffead18f162649c0fbfba30",
    "testharness"
   ],
@@ -592472,16 +592503,20 @@
   "service-workers/cache-storage/serviceworker/cache-storage.https.html": [
    "dbf2c5f7fdbd8a1e604d0e1d301d40a7146e93d8",
    "testharness"
   ],
   "service-workers/cache-storage/serviceworker/credentials.https.html": [
    "ef598649e75e3c8736729d7e233982748e31eb79",
    "testharness"
   ],
+  "service-workers/cache-storage/window/cache-abort.https.html": [
+   "2143ee1d78242bd2d055f6ea1b63a1becff657fe",
+   "testharness"
+  ],
   "service-workers/cache-storage/window/cache-add.https.html": [
    "d2c83935c4f413fa6f9459843a9ba669deb0e8ce",
    "testharness"
   ],
   "service-workers/cache-storage/window/cache-delete.https.html": [
    "8b02db13f96f2d9328e5a7cc4c55dd58bd23618c",
    "testharness"
   ],
@@ -592512,16 +592547,20 @@
   "service-workers/cache-storage/window/cache-storage.https.html": [
    "3ee65e5b5aadb6d64e9c094188378f84f121f53f",
    "testharness"
   ],
   "service-workers/cache-storage/window/sandboxed-iframes.https.html": [
    "dafb0d18e02c256a78188fdaf6997a1abd58b215",
    "testharness"
   ],
+  "service-workers/cache-storage/worker/cache-abort.https.html": [
+   "d67a78e50008a587d0b349daaacafc25a18cfd5b",
+   "testharness"
+  ],
   "service-workers/cache-storage/worker/cache-add.https.html": [
    "2cbea6be14f2f1852993be40744cac72a7fc62f6",
    "testharness"
   ],
   "service-workers/cache-storage/worker/cache-delete.https.html": [
    "6e75a546b1646e8a97aa43aa9cf5434402dca064",
    "testharness"
   ],
--- a/testing/web-platform/tests/lint.whitelist
+++ b/testing/web-platform/tests/lint.whitelist
@@ -192,16 +192,17 @@ SET TIMEOUT: pointerevents/pointerevent_
 SET TIMEOUT: preload/single-download-preload.html
 SET TIMEOUT: resize-observer/resources/iframe.html
 SET TIMEOUT: resource-timing/resource-timing.js
 SET TIMEOUT: resource-timing/single-entry-per-resource.html
 SET TIMEOUT: screen-orientation/lock-bad-argument.html
 SET TIMEOUT: screen-orientation/onchange-event.html
 SET TIMEOUT: screen-orientation/resources/sandboxed-iframe-locking.html
 SET TIMEOUT: secure-contexts/basic-popup-and-iframe-tests.https.js
+SET TIMEOUT: service-workers/cache-storage/script-tests/cache-abort.js
 SET TIMEOUT: service-workers/service-worker/activation.https.html
 SET TIMEOUT: service-workers/service-worker/fetch-frame-resource.https.html
 SET TIMEOUT: service-workers/service-worker/fetch-request-redirect.https.html
 SET TIMEOUT: service-workers/service-worker/fetch-waits-for-activate.https.html
 SET TIMEOUT: service-workers/service-worker/ready.https.html
 SET TIMEOUT: service-workers/service-worker/update-recovery.https.html
 SET TIMEOUT: service-workers/service-worker/resources/extendable-event-async-waituntil.js
 SET TIMEOUT: service-workers/service-worker/resources/fetch-event-async-respond-with-worker.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/cache-storage/script-tests/cache-abort.js
@@ -0,0 +1,81 @@
+if (self.importScripts) {
+  importScripts('/resources/testharness.js');
+  importScripts('../resources/test-helpers.js');
+  importScripts('/common/utils.js');
+}
+
+// We perform the same tests on put, add, addAll. Parameterise the tests to
+// reduce repetition.
+const methodsToTest = {
+  put: async (cache, request) => {
+    const response = await fetch(request);
+    return cache.put(request, response);
+  },
+  add: async (cache, request) => cache.add(request),
+  addAll: async (cache, request) => cache.addAll([request]),
+};
+
+for (const method in methodsToTest) {
+  const perform = methodsToTest[method];
+
+  cache_test(async (cache, test) => {
+    const controller = new AbortController();
+    const signal = controller.signal;
+    controller.abort();
+    const request = new Request('../resources/simple.txt', { signal });
+    return promise_rejects(test, 'AbortError', perform(cache, request),
+                          `${method} should reject`);
+  }, `${method}() on an already-aborted request should reject with AbortError`);
+
+  cache_test(async (cache, test) => {
+    const controller = new AbortController();
+    const signal = controller.signal;
+    const request = new Request('../resources/simple.txt', { signal });
+    const promise = perform(cache, request);
+    controller.abort();
+    return promise_rejects(test, 'AbortError', promise,
+                          `${method} should reject`);
+  }, `${method}() synchronously followed by abort should reject with ` +
+     `AbortError`);
+
+  cache_test(async (cache, test) => {
+    const controller = new AbortController();
+    const signal = controller.signal;
+    const stateKey = token();
+    const abortKey = token();
+    const request = new Request(
+        `../../../fetch/api/resources/infinite-slow-response.py?stateKey=${stateKey}&abortKey=${abortKey}`,
+        { signal });
+
+    const promise = perform(cache, request);
+
+    // Wait for the server to start sending the response body.
+    let opened = false;
+    do {
+      // Normally only one fetch to 'stash-take' is needed, but the fetches
+      // will be served in reverse order sometimes
+      // (i.e., 'stash-take' gets served before 'infinite-slow-response').
+
+      const response =
+            await fetch(`../../../fetch/api/resources/stash-take.py?key=${stateKey}`);
+      const body = await response.json();
+      if (body === 'open') opened = true;
+    } while (!opened);
+
+    // Sadly the above loop cannot guarantee that the browser has started
+    // processing the response body. This delay is needed to make the test
+    // failures non-flaky in Chrome version 66. My deepest apologies.
+    await new Promise(resolve => setTimeout(resolve, 250));
+
+    controller.abort();
+
+    await promise_rejects(test, 'AbortError', promise,
+                          `${method} should reject`);
+
+    // infinite-slow-response.py doesn't know when to stop.
+    return fetch(`../../../fetch/api/resources/stash-put.py?key=${abortKey}`);
+  }, `${method}() followed by abort after headers received should reject ` +
+     `with AbortError`);
+}
+
+done();
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/cache-storage/serviceworker/cache-abort.https.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<title>Cache Storage: Abort</title>
+<link rel="help" href="https://fetch.spec.whatwg.org/#request-signal">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../../service-worker/resources/test-helpers.sub.js"></script>
+<script>
+service_worker_test('../script-tests/cache-abort.js');
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/cache-storage/window/cache-abort.https.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<title>Cache Storage: Abort</title>
+<link rel="help" href="https://fetch.spec.whatwg.org/#request-signal">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/test-helpers.js"></script>
+<script src="/common/utils.js"></script>
+<script src="../script-tests/cache-abort.js"></script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/cache-storage/worker/cache-abort.https.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<title>>Cache Storage: Abort</title>
+<link rel="help" href="https://fetch.spec.whatwg.org/#request-signal">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+fetch_tests_from_worker(new Worker('../script-tests/cache-abort.js'));
+</script>