oninstall-script-error.https.html (2493B)
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_event(worker) { 8 return new Promise(function(resolve) { 9 worker.addEventListener('statechange', function(event) { 10 if (worker.state == 'installed') 11 resolve(true); 12 else if (worker.state == 'redundant') 13 resolve(false); 14 }); 15 }); 16 } 17 18 function make_test(name, script, expect_install) { 19 promise_test(function(t) { 20 var scope = script; 21 return service_worker_unregister_and_register(t, script, scope) 22 .then(function(registration) { 23 return wait_for_install_event(registration.installing); 24 }) 25 .then(function(did_install) { 26 assert_equals(did_install, expect_install, 27 'The worker was installed'); 28 }) 29 }, name); 30 } 31 32 [ 33 { 34 name: 'install handler throws an error', 35 script: 'resources/oninstall-throw-error-worker.js', 36 expect_install: true 37 }, 38 { 39 name: 'install handler throws an error, error handler does not cancel', 40 script: 'resources/oninstall-throw-error-with-empty-onerror-worker.js', 41 expect_install: true 42 }, 43 { 44 name: 'install handler dispatches an event that throws an error', 45 script: 'resources/oninstall-throw-error-from-nested-event-worker.js', 46 expect_install: true 47 }, 48 { 49 name: 'install handler throws an error in the waitUntil', 50 script: 'resources/oninstall-waituntil-throw-error-worker.js', 51 expect_install: false 52 }, 53 54 // The following two cases test what happens when the ServiceWorkerGlobalScope 55 // 'error' event handler cancels the resulting error event. Since the 56 // original 'install' event handler through, the installation should still 57 // be stopped in this case. See: 58 // https://github.com/slightlyoff/ServiceWorker/issues/778 59 { 60 name: 'install handler throws an error that is cancelled', 61 script: 'resources/oninstall-throw-error-then-cancel-worker.js', 62 expect_install: true 63 }, 64 { 65 name: 'install handler throws an error and prevents default', 66 script: 'resources/oninstall-throw-error-then-prevent-default-worker.js', 67 expect_install: true 68 } 69 ].forEach(function(test_case) { 70 make_test(test_case.name, test_case.script, test_case.expect_install); 71 }); 72 </script>