Bug 1496784 [wpt PR 13390] - Resubmit cr/1261477, a=testonly
authorRayan Kanso <rayankans@chromium.org>
Thu, 11 Oct 2018 09:30:57 +0000
changeset 441022 ad04238da3b66b40bbf8c0609e8d55469652b974
parent 441021 b4124072ce413dd778e0d1780ea71283b1c698ce
child 441023 bcd7b358b492a08052588e078fb11a8c371c01d1
push id34842
push useraciure@mozilla.com
push dateSat, 13 Oct 2018 09:36:47 +0000
treeherdermozilla-central@94a62c1aad52 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1496784, 13390, 1261477, 1264640, 597106
milestone64.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 1496784 [wpt PR 13390] - Resubmit cr/1261477, a=testonly Automatic update from web-platform-testsResubmit cr/1261477 I reproduced the failure locally, and then re-ran with the changes 100 time successfully TBR=peter@chromium.org Change-Id: Ieb60211fcd9c6beb1aec2b152f298335c4d9178b Reviewed-on: https://chromium-review.googlesource.com/c/1264640 Reviewed-by: Mugdha Lakhani <nator@chromium.org> Commit-Queue: Rayan Kanso <rayankans@chromium.org> Cr-Commit-Position: refs/heads/master@{#597106} -- wpt-commits: 786e201985b7c46ef59185c2c519f9081374fb2a wpt-pr: 13390
testing/web-platform/tests/background-fetch/abort.https.window.js
testing/web-platform/tests/background-fetch/service_workers/sw.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/background-fetch/abort.https.window.js
@@ -0,0 +1,50 @@
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/utils.js
+'use strict';
+
+// Covers basic functionality provided by BackgroundFetchManager.abort().
+// https://wicg.github.io/background-fetch/#background-fetch-registration-abort
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(),
+      ['resources/feature-name.txt', '/serviceworker/resources/slow-response.php']);
+
+  assert_true(await registration.abort());
+  assert_false(await registration.abort());
+
+}, 'Aborting the same registration twice fails');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registration = await backgroundFetch.fetch(
+      uniqueId(),
+      ['resources/feature-name.txt', '/serviceworker/resources/slow-response.php']);
+  const resultPromise = getMessageFromServiceWorker();
+
+  await new Promise(resolve => {
+    registration.onprogress = async (e) => {
+      // The size of the first file.
+      if (e.target.downloaded < 16)
+        return;
+
+      // At this point the first file is downloaded.
+
+      assert_true(await registration.abort());
+
+      const {type, eventRegistration, results} = await resultPromise;
+
+      assert_equals(eventRegistration.result, 'failure');
+      assert_equals(eventRegistration.failureReason, 'aborted');
+
+      assert_equals(type, 'backgroundfetchabort');
+      assert_equals(results.length, 1);
+
+      assert_true(results[0].url.includes('resources/feature-name.txt'));
+      assert_equals(results[0].status, 200);
+      assert_equals(results[0].text, 'Background Fetch');
+
+      resolve();
+    };
+  });
+
+}, 'Calling BackgroundFetchRegistration.abort sets the correct fields and responses are still available');
\ No newline at end of file
--- a/testing/web-platform/tests/background-fetch/service_workers/sw.js
+++ b/testing/web-platform/tests/background-fetch/service_workers/sw.js
@@ -22,8 +22,9 @@ function handleBackgroundFetchUpdateEven
         const registrationCopy = cloneRegistration(event.registration);
         sendMessageToDocument(
           { type: event.type, eventRegistration: registrationCopy, results })
       }));
 }
 
 self.addEventListener('backgroundfetchsuccess', handleBackgroundFetchUpdateEvent);
 self.addEventListener('backgroundfetchfail', handleBackgroundFetchUpdateEvent);
+self.addEventListener('backgroundfetchabort', handleBackgroundFetchUpdateEvent);