Bug 1497314 [wpt PR 13360] - [Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort, a=testonly
authorRayan Kanso <rayankans@chromium.org>
Tue, 09 Oct 2018 20:37:51 +0000
changeset 498924 a379712d3dd4b9d4fbd231c1e081e34b66b1b870
parent 498923 2cee53dd577363866c3cc6ed7baf679a9936abbf
child 498925 abe1d19c586d1aa678761a8bf6e508daa7771cb3
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
bugs1497314, 13360, 1261477, 596723
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 1497314 [wpt PR 13360] - [Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort, a=testonly Automatic update from web-platform-tests[Background Fetch] Add WPT tests for BackgroundFetchRegistration::abort Simplify event dispatching code, and also allow for match/matchAll to be called with the abort event. Change-Id: I3a9d17102f176f7c68131ea144e555a44ffd6ab1 Reviewed-on: https://chromium-review.googlesource.com/c/1261477 Commit-Queue: Rayan Kanso <rayankans@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Reviewed-by: Mugdha Lakhani <nator@chromium.org> Cr-Commit-Position: refs/heads/master@{#596723} -- wpt-commits: 23cc12436af526289e615bf66171537ed11598fd wpt-pr: 13360
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,45 @@
+// 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 => {
+    // Run the following steps after the first request is complete.
+    registration.onprogress = async () => {
+      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);