Bug 1472899 [wpt PR 11761] - Async Cookies: Expose oncookiechange on ServiceWorkerGlobalScope., a=testonly
authorVictor Costan <pwnall@chromium.org>
Sat, 07 Jul 2018 00:23:44 +0000
changeset 426148 b7c6f80c568da5de83794b5b722bc0eb2ad39935
parent 426147 23a5a863278ccd52e6cb91c412ad475999f662e1
child 426149 234b05356393dc6ed3c1919512dc02c31f8a4773
push id34267
push userrgurzau@mozilla.com
push dateWed, 11 Jul 2018 22:05:21 +0000
treeherdermozilla-central@3aca103e4915 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1472899, 11761, 979334, 729800, 1123766, 572400
milestone63.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 1472899 [wpt PR 11761] - Async Cookies: Expose oncookiechange on ServiceWorkerGlobalScope., a=testonly Automatic update from web-platform-testsAsync Cookies: Expose oncookiechange on ServiceWorkerGlobalScope. cookiechange events have been dispatched to ServiceWorkerGlobalScope since https://crrev.com/c/979334 landed, and can be observed using addEventListener, as shown by the WPT test at cookie-store/serviceworker_cookieStore_subscriptions_basic.tentative.https.html This CL adds the oncookiechange attribute to ServiceWorkerGlobalScope, allowing the event to be handled by a DOM0-style event handler. Bug: 729800 Change-Id: Ic27979d94934abf833c116787cdad5243422324b Reviewed-on: https://chromium-review.googlesource.com/1123766 Commit-Queue: Victor Costan <pwnall@chromium.org> Reviewed-by: Kent Tamura <tkent@chromium.org> Reviewed-by: Joshua Bell <jsbell@chromium.org> Cr-Commit-Position: refs/heads/master@{#572400} -- wpt-commits: bf35451761ed3c9063f928bc8c4c340ee66634f3 wpt-pr: 11761
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions.js
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_basic.js
testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_empty.js
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/interfaces/cookie-store.idl
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -217108,16 +217108,21 @@
      {}
     ]
    ],
    "cookie-store/serviceworker_cookieStore_subscriptions_empty.js": [
     [
      {}
     ]
    ],
+   "cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.js": [
+    [
+     {}
+    ]
+   ],
    "cookie-store/serviceworker_cookieStore_subscriptions_mismatch.js": [
     [
      {}
     ]
    ],
    "cookies/META.yml": [
     [
      {}
@@ -316229,16 +316234,22 @@
     ]
    ],
    "cookie-store/serviceworker_cookieStore_subscriptions_empty.tentative.https.html": [
     [
      "/cookie-store/serviceworker_cookieStore_subscriptions_empty.tentative.https.html",
      {}
     ]
    ],
+   "cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html": [
+    [
+     "/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html",
+     {}
+    ]
+   ],
    "cookie-store/serviceworker_cookieStore_subscriptions_mismatch.tentative.https.html": [
     [
      "/cookie-store/serviceworker_cookieStore_subscriptions_mismatch.tentative.https.html",
      {}
     ]
    ],
    "cookies/http-state/attribute-tests.html": [
     [
@@ -441141,41 +441152,49 @@
    "515dc7d31bbc6af83276939dbb997ccd0e8de3ec",
    "support"
   ],
   "cookie-store/serviceworker_cookieStore_basic.tentative.https.html": [
    "0700dc72bc1e00832546d4a6826a5474600af06c",
    "testharness"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions.js": [
-   "7e140635e7587de1c606a0faf4a0bf8d8eb8c41e",
+   "7197cdc912d381a258a7b80daaa0d12e20a66fe5",
    "support"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions.tentative.https.html": [
    "4389e108fcbad909506ce6ea0d30e32f5973bfce",
    "testharness"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions_basic.js": [
-   "9b477518ee4c8cdc103d3cab11cca371b7b2f72d",
+   "503a93f435cf7784ff2b98dc7c3f5d1a1ba1fb14",
    "support"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions_basic.tentative.https.html": [
    "3836f1d36746ae11b76ee420ba34d902d48bc0af",
    "testharness"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions_empty.js": [
-   "fd8cf9d3dab06824cf0497c44a388c0cea7d02d6",
+   "a90b1e59e0708838ad84618c4acfb6291ec82bd9",
    "support"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions_empty.tentative.https.html": [
    "3f8ec6177bc54738213fab8a1f8947d58714456d",
    "testharness"
   ],
+  "cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.js": [
+   "4cc19c733cea09c1143dba9ef017ccb59aee8ddc",
+   "support"
+  ],
+  "cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html": [
+   "e0d44d998137cea66fc66d88a12b485386962b34",
+   "testharness"
+  ],
   "cookie-store/serviceworker_cookieStore_subscriptions_mismatch.js": [
-   "fa57006fdb09070feb6c7a83553d300d725761b6",
+   "464447630cdf01b80e4469fb79756c9898653cc4",
    "support"
   ],
   "cookie-store/serviceworker_cookieStore_subscriptions_mismatch.tentative.https.html": [
    "594f019786ffb316e8140e9f30a2cecadceda2fa",
    "testharness"
   ],
   "cookies/META.yml": [
    "7456d333deb42015924578efc2a9269fbfa696bf",
@@ -593669,17 +593688,17 @@
    "e674e142d1348afd587b566d86b9390ad8bc56a0",
    "support"
   ],
   "interfaces/console.idl": [
    "43ced34008dc73d05c79140d8dc33c60e2d9df3a",
    "support"
   ],
   "interfaces/cookie-store.idl": [
-   "468487d9aee05767b52a112275155fa883720aa0",
+   "fe873252f8a58c66f736fbabd90d6d37a15df139",
    "support"
   ],
   "interfaces/cors-rfc1918.idl": [
    "d7f133c8dd6e1656f82c077d9795714827b9c869",
    "support"
   ],
   "interfaces/credential-management.idl": [
    "29a0bcde9ddd6629c7bf05757cea45c831fe9a6b",
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions.js
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions.js
@@ -98,16 +98,16 @@ promise_test(async testCase => {
   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);
 
-  await async_cleanup(() => {
-    cookieStore.delete('cookie-name');
+  await async_cleanup(async () => {
+    await cookieStore.delete('cookie-name');
     g_cookie_changes = [];
     RearmCookieChangeReceivedPromise();
   });
 }, 'cookiechange dispatched with cookie change that matches subscription');
 
 done();
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_basic.js
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_basic.js
@@ -1,17 +1,17 @@
 self.GLOBAL = {
   isWindow: function() { return false; },
   isWorker: function() { return true; },
 };
 importScripts("/resources/testharness.js");
 
 self.addEventListener('install', (event) => {
   event.waitUntil((async () => {
-    cookieStore.subscribeToChanges([
+    await cookieStore.subscribeToChanges([
       { name: 'cookie-name', matchType: 'equals', url: '/scope/path' }]);
   })());
 });
 
 // Workaround because add_cleanup doesn't support async functions yet.
 // See https://github.com/web-platform-tests/wpt/issues/6075
 async function async_cleanup(cleanup_function) {
   try {
@@ -52,12 +52,13 @@ promise_test(async testCase => {
   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);
 
-  await async_cleanup(() => { cookieStore.delete('cookie-name'); });
-}, 'cookiechange dispatched with cookie change that matches subscription');
+  await async_cleanup(() => cookieStore.delete('cookie-name'));
+}, 'cookiechange dispatched with cookie change that matches subscription ' +
+   'to event handler registered with addEventListener');
 
 done();
--- a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_empty.js
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_empty.js
@@ -1,17 +1,17 @@
 self.GLOBAL = {
   isWindow: function() { return false; },
   isWorker: function() { return true; },
 };
 importScripts("/resources/testharness.js");
 
 self.addEventListener('install', (event) => {
   event.waitUntil((async () => {
-    cookieStore.subscribeToChanges([]);
+    await cookieStore.subscribeToChanges([]);
   })());
 });
 
 // Workaround because add_cleanup doesn't support async functions yet.
 // See https://github.com/w3c/web-platform-tests/issues/6075
 async function async_cleanup(cleanup_function) {
   try {
     await cleanup_function();
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.js
@@ -0,0 +1,51 @@
+self.GLOBAL = {
+  isWindow: function() { return false; },
+  isWorker: function() { return true; },
+};
+importScripts("/resources/testharness.js");
+
+self.addEventListener('install', (event) => {
+  event.waitUntil((async () => {
+    await cookieStore.subscribeToChanges([
+      { name: 'cookie-name', matchType: 'equals', url: '/scope/path' }]);
+  })());
+});
+
+// Workaround because add_cleanup doesn't support async functions yet.
+// See https://github.com/web-platform-tests/wpt/issues/6075
+async function async_cleanup(cleanup_function) {
+  try {
+    await cleanup_function();
+  } catch (e) {
+    // Errors in cleanup functions shouldn't result in test failures.
+  }
+}
+
+// Resolves when the service worker receives the 'activate' event.
+const kServiceWorkerActivatedPromise = new Promise(resolve => {
+  self.addEventListener('activate', event => { resolve(); });
+});
+
+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');
+
+  const event = await cookie_change_received_promise;
+  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);
+
+  await async_cleanup(() => cookieStore.delete('cookie-name'));
+}, 'cookiechange dispatched with cookie change that matches subscription ' +
+   'to event handler registered with oncookiechange');
+
+done();
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_eventhandler_attribute.tentative.https.html
@@ -0,0 +1,22 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Async Cookies: oncookiechange event handler attribute in ServiceWorker</title>
+<link rel="help" href="https://github.com/WICG/cookie-store">
+<link rel="author" href="pwnall@chromium.org" title="Victor Costan">
+<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(
+      'serviceworker_cookieStore_subscriptions_eventhandler_attribute.js', {scope});
+
+  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
@@ -1,17 +1,17 @@
 self.GLOBAL = {
   isWindow: function() { return false; },
   isWorker: function() { return true; },
 };
 importScripts("/resources/testharness.js");
 
 self.addEventListener('install', (event) => {
   event.waitUntil((async () => {
-    cookieStore.subscribeToChanges([
+    await cookieStore.subscribeToChanges([
       { name: 'cookie-name', matchType: 'equals', url: '/scope/path' }]);
   })());
 });
 
 // Workaround because add_cleanup doesn't support async functions yet.
 // See https://github.com/w3c/web-platform-tests/issues/6075
 async function async_cleanup(cleanup_function) {
   try {
@@ -39,15 +39,15 @@ promise_test(async testCase => {
   await cookieStore.set('cookie-name', 'cookie-value');
 
   const event = await cookie_change_received_promise;
   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');
 
-  await async_cleanup(() => {
-    cookieStore.delete('another-cookie-name');
-    cookieStore.delete('cookie-name');
+  await async_cleanup(async () => {
+    await cookieStore.delete('another-cookie-name');
+    await cookieStore.delete('cookie-name');
   });
 }, 'cookiechange not dispatched for change that does not match subscription');
 
 done();
--- a/testing/web-platform/tests/interfaces/cookie-store.idl
+++ b/testing/web-platform/tests/interfaces/cookie-store.idl
@@ -103,9 +103,10 @@ dictionary CookieStoreSetExtraOptions : 
 
 [SecureContext]
 partial interface Window {
   [Replaceable, SameObject] readonly attribute CookieStore cookieStore;
 };
 
 partial interface ServiceWorkerGlobalScope {
   [Replaceable, SameObject] readonly attribute CookieStore cookieStore;
+  attribute EventHandler oncookiechange;
 };