unregister-immediately-before-installed.https.html (2236B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Use Clear-Site-Data to immediately unregister service workers</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script src="resources/unregister-immediately-helpers.js"></script> 8 <body> 9 <script> 10 'use strict'; 11 12 // These tests use the Clear-Site-Data network response header to immediately 13 // unregister a service worker registration with a worker whose state is 14 // 'installing' or 'parsed'. Clear-Site-Data must delete the registration, 15 // abort the installation and then clear the registration by setting the 16 // worker's state to 'redundant'. 17 18 promise_test(async test => { 19 // This test keeps the service worker in the 'parsed' state by using a 20 // script with an infinite loop. 21 const script_url = 'resources/onparse-infiniteloop-worker.js'; 22 const scope_url = 23 'resources/scope-for-unregister-immediately-with-parsed-worker'; 24 25 await service_worker_unregister(test, /*scope=*/script_url); 26 27 // Clear-Site-Data must cause register() to fail. 28 const register_promise = promise_rejects_dom(test, 'AbortError', 29 navigator.serviceWorker.register(script_url, { scope: scope_url}));; 30 31 await Promise.all([clear_site_data(), register_promise]); 32 33 await assert_no_registrations_exist(); 34 }, 'Clear-Site-Data must abort service worker registration.'); 35 36 promise_test(async test => { 37 // This test keeps the service worker in the 'installing' state by using a 38 // script with an install event waitUntil() promise that never resolves. 39 const script_url = 'resources/oninstall-waituntil-forever.js'; 40 const scope_url = 41 'resources/scope-for-unregister-immediately-with-installing-worker'; 42 43 const registration = await service_worker_unregister_and_register( 44 test, script_url, scope_url); 45 const service_worker = registration.installing; 46 47 // Clear-Site-Data must cause install to fail. 48 await Promise.all([ 49 clear_site_data(), 50 wait_for_state(test, service_worker, 'redundant')]); 51 52 await assert_no_registrations_exist(); 53 }, 'Clear-Site-Data must unregister a registration with a worker ' 54 + 'in the "installing" state.'); 55 56 </script> 57 </body>