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.js"></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')
12 else if (worker
.state
== 'redundant')
18 function wait_for_activate(worker
) {
19 return new Promise(function(resolve
, reject
) {
20 worker
.addEventListener('statechange', function(event
) {
21 if (worker
.state
== 'activated')
23 else if (worker
.state
== 'redundant')
29 function make_test(name
, script
) {
30 promise_test(function(t
) {
33 return service_worker_unregister_and_register(t
, script
, scope
)
36 return wait_for_install(registration
.installing
);
39 // Activate should succeed regardless of script errors.
40 return wait_for_activate(registration
.waiting
);
47 name
: 'activate handler throws an error',
48 script
: 'resources/onactivate-throw-error-worker.js',
51 name
: 'activate handler throws an error, error handler does not cancel',
52 script
: 'resources/onactivate-throw-error-with-empty-onerror-worker.js',
55 name
: 'activate handler dispatches an event that throws an error',
56 script
: 'resources/onactivate-throw-error-from-nested-event-worker.js',
59 name
: 'activate handler throws an error that is cancelled',
60 script
: 'resources/onactivate-throw-error-then-cancel-worker.js',
63 name
: 'activate handler throws an error and prevents default',
64 script
: 'resources/onactivate-throw-error-then-prevent-default-worker.js',
66 ].forEach(function(test_case
) {
67 make_test(test_case
.name
, test_case
.script
);