diff options
Diffstat (limited to 'testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_reset.https.html')
-rw-r--r-- | testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_reset.https.html | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_reset.https.html b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_reset.https.html new file mode 100644 index 0000000000..a1124e9220 --- /dev/null +++ b/testing/web-platform/tests/cookie-store/serviceworker_cookieStore_subscriptions_reset.https.html @@ -0,0 +1,55 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Cookie Store API: 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> +'use strict'; + +promise_test(async t => { + const registration = await service_worker_unregister_and_register( + t, 'resources/empty_sw.js', 'resources/does/not/exist'); + t.add_cleanup(() => registration.unregister()); + await wait_for_state(t, registration.installing, 'activated'); + await registration.cookies.subscribe( + [{ name: 'cookie-name' }]); + const original_subscriptions = await registration.cookies.getSubscriptions(); + assert_equals(original_subscriptions.length, 1, + 'subscription count before unregistration'); + + await registration.unregister(); + + const new_registration = await navigator.serviceWorker.register( + 'resources/empty_sw.js', { scope: 'resources/does/not/exist' }); + t.add_cleanup(() => new_registration.unregister()); + await wait_for_state(t, new_registration.installing, 'activated'); + + const new_subscriptions = await new_registration.cookies.getSubscriptions(); + assert_equals(new_subscriptions.length, 0, + 'subscription count after unregistration'); +}, 'cookiechange subscriptions reset across service worker unregistrations'); + +promise_test(async t => { + const registration = await service_worker_unregister_and_register( + t, 'resources/always_changing_sw.sub.js', 'resources/does/not/exist'); + t.add_cleanup(() => registration.unregister()); + await wait_for_state(t, registration.installing, 'activated'); + await registration.cookies.subscribe( + [{ name: 'cookie-name' }]); + const original_subscriptions = await registration.cookies.getSubscriptions(); + assert_equals(original_subscriptions.length, 1, + 'subscription count before update'); + + await registration.update(); + const worker = await wait_for_update(t, registration); + await wait_for_state(t, worker, 'activated'); + + const update_subscriptions = await registration.cookies.getSubscriptions(); + assert_equals(update_subscriptions.length, 1, + 'subscription count after update'); +}, 'cookiechange subscriptions persist across service worker updates'); +</script> |