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 = 'resources/state/'; | 10 var scope = 'resources/state/'; |
11 | 11 |
12 service_worker_unregister_and_register( | 12 service_worker_unregister_and_register( |
13 t, 'resources/empty-worker.js', scope) | 13 t, 'resources/empty-worker.js', scope) |
14 .then(t.step_func(function(registration) { | 14 .then(t.step_func(function(registration) { |
15 return wait_for_update(t, registration); | 15 return wait_for_update(t, registration); |
16 })) | 16 })) |
17 .then(t.step_func(function(sw) { | 17 .then(t.step_func(function(sw) { |
18 sw.addEventListener('statechange', t.step_func(onStateChange(sw))); | 18 sw.addEventListener('statechange', t.step_func(onStateChange(sw))); |
19 assert_in_array(sw.state, ['parsed', 'installing'], | 19 assert_equals(sw.state, 'installing', |
20 'the service worker should be in a state up to ' + | 20 'the service worker should be in "installing" state.'); |
21 '"installing".'); | |
22 checkStateTransition(sw.state); | 21 checkStateTransition(sw.state); |
23 })) | 22 })) |
24 .catch(unreached_rejection(t)); | 23 .catch(unreached_rejection(t)); |
25 | 24 |
26 function checkStateTransition(newState) { | 25 function checkStateTransition(newState) { |
27 switch (currentState) { | 26 switch (currentState) { |
28 case 'test-is-starting': | 27 case 'test-is-starting': |
29 break; // anything goes | 28 break; // anything goes |
30 case 'parsed': | |
31 assert_equals(newState, 'installing'); | |
32 break; | |
33 case 'installing': | 29 case 'installing': |
34 assert_in_array(newState, ['installed', 'redundant']); | 30 assert_in_array(newState, ['installed', 'redundant']); |
35 break; | 31 break; |
36 case 'installed': | 32 case 'installed': |
37 assert_in_array(newState, ['activating', 'redundant']); | 33 assert_in_array(newState, ['activating', 'redundant']); |
38 break; | 34 break; |
39 case 'activating': | 35 case 'activating': |
40 assert_in_array(newState, ['activated', 'redundant']); | 36 assert_in_array(newState, ['activated', 'redundant']); |
41 break; | 37 break; |
42 case 'activated': | 38 case 'activated': |
(...skipping 23 matching lines...) Expand all Loading... |
66 'the type of the event should be "statechange".'); | 62 'the type of the event should be "statechange".'); |
67 | 63 |
68 checkStateTransition(event.target.state); | 64 checkStateTransition(event.target.state); |
69 | 65 |
70 if (event.target.state == 'activated') | 66 if (event.target.state == 'activated') |
71 service_worker_unregister_and_done(t, scope); | 67 service_worker_unregister_and_done(t, scope); |
72 }; | 68 }; |
73 } | 69 } |
74 }()); | 70 }()); |
75 </script> | 71 </script> |
OLD | NEW |