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