onactivate-script-error.https.html (2286B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="resources/testharness-helpers.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="resources/test-helpers.sub.js"></script> 6 <script> 7 function wait_for_install(worker) { 8 return new Promise(function(resolve, reject) { 9 worker.addEventListener('statechange', function(event) { 10 if (worker.state == 'installed') 11 resolve(); 12 else if (worker.state == 'redundant') 13 reject(); 14 }); 15 }); 16 } 17 18 function wait_for_activate(worker) { 19 return new Promise(function(resolve, reject) { 20 worker.addEventListener('statechange', function(event) { 21 if (worker.state == 'activated') 22 resolve(); 23 else if (worker.state == 'redundant') 24 reject(); 25 }); 26 }); 27 } 28 29 function make_test(name, script) { 30 promise_test(function(t) { 31 var scope = script; 32 var registration; 33 return service_worker_unregister_and_register(t, script, scope) 34 .then(function(r) { 35 registration = r; 36 37 t.add_cleanup(function() { 38 return r.unregister(); 39 }); 40 41 return wait_for_install(registration.installing); 42 }) 43 .then(function() { 44 // Activate should succeed regardless of script errors. 45 return wait_for_activate(registration.waiting); 46 }); 47 }, name); 48 } 49 50 [ 51 { 52 name: 'activate handler throws an error', 53 script: 'resources/onactivate-throw-error-worker.js', 54 }, 55 { 56 name: 'activate handler throws an error, error handler does not cancel', 57 script: 'resources/onactivate-throw-error-with-empty-onerror-worker.js', 58 }, 59 { 60 name: 'activate handler dispatches an event that throws an error', 61 script: 'resources/onactivate-throw-error-from-nested-event-worker.js', 62 }, 63 { 64 name: 'activate handler throws an error that is cancelled', 65 script: 'resources/onactivate-throw-error-then-cancel-worker.js', 66 }, 67 { 68 name: 'activate handler throws an error and prevents default', 69 script: 'resources/onactivate-throw-error-then-prevent-default-worker.js', 70 } 71 ].forEach(function(test_case) { 72 make_test(test_case.name, test_case.script); 73 }); 74 </script>