Bug 1496854 [wpt PR 13398] - [Background Fetch] Notify observers of BackgroundFetchRegistration, a=testonly
authorMugdha Lakhani <nator@chromium.org>
Mon, 15 Oct 2018 17:16:09 +0000
changeset 489973 cd6f94d81963ad91334bec0adfb82f5ea6680a8d
parent 489972 87535197cdb7d84bb7160c5639e3c4fcfee72492
child 489974 052a4647bc04700502dacfbe14c1bbc1c2d658f2
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerstestonly
bugs1496854, 13398, 1264589, 598839
milestone64.0a1
Bug 1496854 [wpt PR 13398] - [Background Fetch] Notify observers of BackgroundFetchRegistration, a=testonly Automatic update from web-platform-tests[Background Fetch] Notify observers of BackgroundFetchRegistration of updates in failure_reason and result, everytime these change. This CL also has the effect of sending the onprogress event when failure_reason and result change upon completion of the background fetch. Change-Id: I137a73bbbddda56994b4914b677bec9cc7183993 Reviewed-on: https://chromium-review.googlesource.com/c/1264589 Commit-Queue: Mugdha Lakhani <nator@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: Rayan Kanso <rayankans@chromium.org> Reviewed-by: Peter Beverloo <peter@chromium.org> Cr-Commit-Position: refs/heads/master@{#598839} -- wpt-commits: 2ada2e794af8672b3988f8b9f085301207e5f78d wpt-pr: 13398
testing/web-platform/tests/background-fetch/fetch.https.window.js
--- a/testing/web-platform/tests/background-fetch/fetch.https.window.js
+++ b/testing/web-platform/tests/background-fetch/fetch.https.window.js
@@ -142,16 +142,34 @@ backgroundFetchTest(async (test, backgro
   assert_true(results[0].url.includes('resources/feature-name.txt'));
   assert_equals(results[0].status, 200);
   assert_equals(results[0].text, 'Background Fetch');
 
 }, 'Using Background Fetch to successfully fetch a single resource');
 
 backgroundFetchTest(async (test, backgroundFetch) => {
   const registrationId = uniqueId();
+  const registration =
+    await backgroundFetch.fetch(registrationId, 'resources/feature-name.txt');
+
+  assert_equals(registration.result, '');
+  assert_equals(registration.failureReason, '');
+
+  const {type, eventRegistration, results} =
+    await getMessageFromServiceWorker();
+  assert_equals('backgroundfetchsuccess', type);
+
+  assert_equals(eventRegistration.id, registration.id);
+  assert_equals(registration.result, 'success');
+  assert_equals(registration.failureReason, '');
+
+}, 'Registration object gets updated values when a background fetch completes.');
+
+backgroundFetchTest(async (test, backgroundFetch) => {
+  const registrationId = uniqueId();
 
   // Very large download total that will definitely exceed the quota.
   const options = {downloadTotal: Number.MAX_SAFE_INTEGER};
   await promise_rejects(
     test, 'QUOTA_EXCEEDED_ERR',
     backgroundFetch.fetch(registrationId, 'resources/feature-name.txt', options),
     'This fetch should have thrown a quota exceeded error');
 
@@ -235,16 +253,19 @@ backgroundFetchTest(async (test, backgro
   assert_true(results[0].url.includes('resources/missing-cat.txt'));
   assert_equals(results[0].status, 404);
   assert_equals(results[0].text, '');
 
   assert_equals(eventRegistration.id, registration.id);
   assert_equals(eventRegistration.result, 'failure');
   assert_equals(eventRegistration.failureReason, 'bad-status');
 
+  assert_equals(registration.result, 'failure');
+  assert_equals(registration.failureReason, 'bad-status');
+
 }, 'Using Background Fetch to fetch a non-existent resource should fail.');
 
 backgroundFetchTest(async (test, backgroundFetch) => {
   const registration = await backgroundFetch.fetch(
                          'my-id',
                          ['https://example.com', 'http://example.com']);
 
   const {type, eventRegistration, results} = await getMessageFromServiceWorker();