OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="resources/test-helpers.js"></script> | 4 <script src="resources/test-helpers.js"></script> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 (function () { | 7 (function () { |
8 var t = async_test('Service Worker state property and "statechange" event'); | 8 var t = async_test('Service Worker state property and "statechange" event'); |
9 var currentState = 'test-is-starting'; | 9 var currentState = 'test-is-starting'; |
10 var scope = '/state/'; | 10 var scope = '/state/'; |
11 | 11 |
12 service_worker_unregister_and_register(t, 'resources/worker-no-op.js', scope
).then(t.step_func(onRegister)); | 12 service_worker_unregister_and_register( |
13 | 13 t, 'resources/worker-no-op.js', scope) |
14 function onRegister(sw) { | 14 .then(t.step_func(function(registration) { |
15 sw.addEventListener('statechange', t.step_func(onStateChange(sw))); | 15 return wait_for_update(t, registration); |
16 assert_in_array(sw.state, ['parsed', 'installing'], | 16 })) |
17 'the service worker should be in a state up to ' + | 17 .then(t.step_func(function(sw) { |
18 '"installing".'); | 18 sw.addEventListener('statechange', t.step_func(onStateChange(sw))); |
19 checkStateTransition(sw.state); | 19 assert_in_array(sw.state, ['parsed', 'installing'], |
20 } | 20 'the service worker should be in a state up to ' + |
| 21 '"installing".'); |
| 22 checkStateTransition(sw.state); |
| 23 })) |
| 24 .catch(unreached_rejection(t)); |
21 | 25 |
22 function checkStateTransition(newState) { | 26 function checkStateTransition(newState) { |
23 switch (currentState) { | 27 switch (currentState) { |
24 case 'test-is-starting': | 28 case 'test-is-starting': |
25 break; // anything goes | 29 break; // anything goes |
26 case 'parsed': | 30 case 'parsed': |
27 assert_equals(newState, 'installing'); | 31 assert_equals(newState, 'installing'); |
28 break; | 32 break; |
29 case 'installing': | 33 case 'installing': |
30 assert_in_array(newState, ['installed', 'redundant']); | 34 assert_in_array(newState, ['installed', 'redundant']); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 'the type of the event should be "statechange".'); | 66 'the type of the event should be "statechange".'); |
63 | 67 |
64 checkStateTransition(event.target.state); | 68 checkStateTransition(event.target.state); |
65 | 69 |
66 if (event.target.state == 'activated') | 70 if (event.target.state == 'activated') |
67 service_worker_unregister_and_done(t, scope); | 71 service_worker_unregister_and_done(t, scope); |
68 }; | 72 }; |
69 } | 73 } |
70 }()); | 74 }()); |
71 </script> | 75 </script> |
OLD | NEW |