summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/unregister-immediately-before-installed.https.html
blob: 79cdaf062dc729c8029c553b485e59d510b87982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html>
<meta charset=utf-8>
<title>Use Clear-Site-Data to immediately unregister service workers</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script src="resources/unregister-immediately-helpers.js"></script>
<body>
<script>
'use strict';

// These tests use the Clear-Site-Data network response header to immediately
// unregister a service worker registration with a worker whose state is
// 'installing' or 'parsed'.  Clear-Site-Data must delete the registration,
// abort the installation and then clear the registration by setting the
// worker's state to 'redundant'.

promise_test(async test => {
  // This test keeps the the service worker in the 'parsed' state by using a
  // script with an infinite loop.
  const script_url = 'resources/onparse-infiniteloop-worker.js';
  const scope_url =
    'resources/scope-for-unregister-immediately-with-parsed-worker';

  await service_worker_unregister(test, /*scope=*/script_url);

  // Clear-Site-Data must cause register() to fail.
  const register_promise = promise_rejects_dom(test, 'AbortError',
    navigator.serviceWorker.register(script_url, { scope: scope_url}));;

  await Promise.all([clear_site_data(), register_promise]);

  await assert_no_registrations_exist();
 }, 'Clear-Site-Data must abort service worker registration.');

promise_test(async test => {
  // This test keeps the the service worker in the 'installing' state by using a
  // script with an install event waitUntil() promise that never resolves.
  const script_url = 'resources/oninstall-waituntil-forever.js';
  const scope_url =
    'resources/scope-for-unregister-immediately-with-installing-worker';

  const registration = await service_worker_unregister_and_register(
    test, script_url, scope_url);
  const service_worker = registration.installing;

  // Clear-Site-Data must cause install to fail.
  await Promise.all([
    clear_site_data(),
    wait_for_state(test, service_worker, 'redundant')]);

  await assert_no_registrations_exist();
 }, 'Clear-Site-Data must unregister a registration with a worker '
     + 'in the "installing" state.');

</script>
</body>