Commit 428581b3 authored by Staphany Park's avatar Staphany Park Committed by Commit Bot

Cookie Store: Add test for cookiechange subscription list.

Bug: 963042
Change-Id: Ic9fbccdabf8ca49b694b4195e7262d3e80a4be6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1836662
Commit-Queue: Staphany Park <staphany@chromium.org>
Auto-Submit: Staphany Park <staphany@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702304}
parent 61886adc
self.GLOBAL = {
isWindow: function() { return false; },
isWorker: function() { return true; },
};
importScripts("/resources/testharness.js");
self.addEventListener('install', event => {
event.waitUntil((async () => {
try {
await cookieStore.subscribeToChanges([
{ name: 'cookie-name', matchType: 'equals',
url: '/cookie-store/scope/path' }]);
// 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) {}
})());
});
self.addEventListener('message', async event => {
const subscriptions = await cookieStore.getChangeSubscriptions();
event.ports[0].postMessage(subscriptions.length);
});
\ No newline at end of file
<!doctype html>
<meta charset="utf-8">
<title>Async Cookies: reset cookie change subscription list</title>
<link rel="help" href="https://github.com/WICG/cookie-store">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js">
</script>
<script src='resources/helpers.js'></script>
<script>
const worker_url = 'serviceworker_cookieStore_subscriptions_reset.sub.js';
const scope = '/cookie-store/';
async function getSubscriptionCount(serviceWorker) {
return sendMessageOverChannel('', serviceWorker);
}
promise_test(async t => {
const registration = await service_worker_unregister_and_register(
t, worker_url, scope);
t.add_cleanup(() => registration.unregister());
await wait_for_state(t, registration.installing, 'activated');
assert_equals(await getSubscriptionCount(registration.active), 1,
'subscription count before unregistration');
await registration.unregister();
const new_registration = await navigator.serviceWorker.register(
worker_url, { scope });
t.add_cleanup(() => new_registration.unregister());
await wait_for_state(t, new_registration.installing, 'activated');
assert_equals(await getSubscriptionCount(new_registration.active), 1,
'subscription count after unregistration');
}, `cookiechange subscription list resets across service worker
unregistrations`);
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment