Bug 1574168 [wpt PR 18340] - [cookie-store] Attempt of deflake remaining service worker tests, a=testonly
authorRobert Ma <robertma@chromium.org>
Mon, 19 Aug 2019 10:41:39 +0000
changeset 553463 e2ca31539fd1be204f9d095fa98d77521b82329a
parent 553462 7e83d17c5b4eb1ba81b83ed4d0855e674e0ccde7
child 553464 fa43a72c917c824dbe1053d39c3a6b8b23982d33
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1574168, 18340, 18324
milestone70.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 1574168 [wpt PR 18340] - [cookie-store] Attempt of deflake remaining service worker tests, a=testonly Automatic update from web-platform-tests [cookie-store] Deflake service worker registration (part 2) This is a follow-up to https://github.com/web-platform-tests/wpt/pull/18324 This change by itself isn't sufficient to deflake the two tests. -- [cookie-store] Attempt to deflake two tests Move the event handler registration to the top scope of the service worker (Chrome warning: "Event handler of ... event must be added on the initial evaluation of worker script."). -- wpt-commits: a13797b678be16d1bec8cae0a8288e6101569cae, 909a1049b9431ae7e1a64c871b5c6822f0a90367 wpt-pr: 18340
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.js
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.js
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.tentative.https.html
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.js
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.js
@@ -14,33 +14,35 @@ self.addEventListener('install', (event)
       // If the worker enters the "redundant" state, the UA may terminate it
       // before all tests have been reported to the client. Stifle errors in
       // order to avoid this and ensure all tests are consistently reported.
     } catch (err) {}
   })());
 });
 
 // Resolves when the service worker receives the 'activate' event.
-const kServiceWorkerActivatedPromise = new Promise(resolve => {
+const kServiceWorkerActivatedPromise = new Promise((resolve) => {
   self.addEventListener('activate', event => { resolve(); });
 });
 
+const kCookieChangeReceivedPromise = new Promise((resolve) => {
+  self.addEventListener('cookiechange', (event) => {
+    resolve(event);
+  });
+});
+
 promise_test(async testCase => {
   await kServiceWorkerActivatedPromise;
 
-  const cookie_change_received_promise = new Promise((resolve) => {
-    self.oncookiechange = (event) => { resolve(event); };
-  });
-
   await cookieStore.set('cookie-name', 'cookie-value');
   testCase.add_cleanup(async () => {
     await cookieStore.delete('cookie-name');
   });
 
-  const event = await cookie_change_received_promise;
+  const event = await kCookieChangeReceivedPromise;
   assert_equals(event.type, 'cookiechange');
   assert_equals(event.changed.length, 1);
   assert_equals(event.changed[0].name, 'cookie-name');
   assert_equals(event.changed[0].value, 'cookie-value');
   assert_equals(event.deleted.length, 0);
   assert_true(event instanceof ExtendableCookieChangeEvent);
   assert_true(event instanceof ExtendableEvent);
 }, 'cookiechange dispatched with cookie change that matches subscription ' +
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html
@@ -6,17 +6,17 @@
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script>
 'use strict';
 
 (async () => {
   const scope = 'scope';
 
-  let registration = await navigator.serviceWorker.getRegistration(scope);
-  if (registration)
-    await registration.unregister();
-  registration = await navigator.serviceWorker.register(
+  const registration = await navigator.serviceWorker.register(
       'serviceworker_cookieStore_subscriptions_eventhandler_attribute.js', {scope});
+  add_completion_callback(() => {
+    registration.unregister();
+  });
 
   fetch_tests_from_worker(registration.installing);
 })();
 </script>
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.js
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.js
@@ -14,38 +14,38 @@ self.addEventListener('install', (event)
       // If the worker enters the "redundant" state, the UA may terminate it
       // before all tests have been reported to the client. Stifle errors in
       // order to avoid this and ensure all tests are consistently reported.
     } catch (err) {}
   })());
 });
 
 // Resolves when the service worker receives the 'activate' event.
-const kServiceWorkerActivatedPromise = new Promise(resolve => {
+const kServiceWorkerActivatedPromise = new Promise((resolve) => {
   self.addEventListener('activate', event => { resolve(); });
 });
 
+const kCookieChangeReceivedPromise = new Promise((resolve) => {
+  self.addEventListener('cookiechange', (event) => {
+    resolve(event);
+  });
+});
+
 promise_test(async testCase => {
   await kServiceWorkerActivatedPromise;
 
-  const cookie_change_received_promise = new Promise((resolve) => {
-    self.addEventListener('cookiechange', (event) => {
-      resolve(event);
-    });
-  });
-
   await cookieStore.set('another-cookie-name', 'cookie-value');
   testCase.add_cleanup(async () => {
     await cookieStore.delete('another-cookie-name');
   });
   await cookieStore.set('cookie-name', 'cookie-value');
   testCase.add_cleanup(async () => {
     await cookieStore.delete('cookie-name');
   });
 
-  const event = await cookie_change_received_promise;
+  const event = await kCookieChangeReceivedPromise;
   assert_equals(event.type, 'cookiechange');
   assert_equals(event.changed.length, 1);
   assert_equals(event.changed[0].name, 'cookie-name');
   assert_equals(event.changed[0].value, 'cookie-value');
 }, 'cookiechange not dispatched for change that does not match subscription');
 
 done();
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.tentative.https.html
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.tentative.https.html
@@ -5,17 +5,17 @@
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script>
 'use strict';
 
 (async () => {
   const scope = 'scope';
 
-  let registration = await navigator.serviceWorker.getRegistration(scope);
-  if (registration)
-    await registration.unregister();
-  registration = await navigator.serviceWorker.register(
+  const registration = await navigator.serviceWorker.register(
       'serviceworker_cookieStore_subscriptions_mismatch.js', {scope});
+  add_completion_callback(() => {
+    registration.unregister();
+  });
 
   fetch_tests_from_worker(registration.installing);
 })();
 </script>