Bug 1498415 [wpt PR 13473] - [Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort, a=testonly
☠☠ backed out by 09dd66ffc95a ☠ ☠
authorRayan Kanso <rayankans@chromium.org>
Mon, 15 Oct 2018 17:16:21 +0000
changeset 500061 538db52b38f0fdd17ae1772625f4d25e075422b6
parent 500060 c6cefa08ec89a993bc3d8a34655d13bf9c192ae3
child 500062 f290eaf8cd44c473def2a5c9f0466ef2b8d3d8ff
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1498415, 13473, 1261477, 1276557, 598848
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 1498415 [wpt PR 13473] - [Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort, a=testonly Automatic update from web-platform-tests[Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort Re-resubmit cr/1261477 The issue was that there is a race condition between the abort going through, and the downloaded file being persisted on disk. I added an extra check in the WPT test. Change-Id: I98aa005b4637c08f60a126a6c7c896c1c0edfddf Reviewed-on: https://chromium-review.googlesource.com/c/1276557 Commit-Queue: Rayan Kanso <rayankans@chromium.org> Reviewed-by: Mugdha Lakhani <nator@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Cr-Commit-Position: refs/heads/master@{#598848} -- wpt-commits: c54a084daf22377e9c9ac3b50f9220ad0df27858 wpt-pr: 13473
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,59 @@
+// 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']);
+
+  await new Promise(resolve => {
+    let aborted = false;
+    const expectedResultText = 'Background Fetch';
+
+    registration.onprogress = async event => {
+      if (event.target.downloaded < expectedResultText.length)
+        return;
+
+      if (aborted)
+        return;
+
+      // Abort after the first file has been downloaded and check the results.
+
+      aborted = true;
+      assert_true(await registration.abort());
+
+      const {type, eventRegistration, results} = await getMessageFromServiceWorker();
+
+      assert_equals(eventRegistration.result, 'failure');
+      assert_equals(eventRegistration.failureReason, 'aborted');
+      assert_equals(registration.result, 'failure');
+      assert_equals(registration.failureReason, 'aborted');
+
+      assert_equals(type, 'backgroundfetchabort');
+
+      // The abort might have gone through before the first result was persisted.
+      if (results.length === 1) {
+        assert_true(results[0].url.includes('resources/feature-name.txt'));
+        assert_equals(results[0].status, 200);
+        assert_equals(results[0].text, expectedResultText);
+      }
+
+      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);