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 var sw = registration.installing; |
16 })) | |
17 .then(t.step_func(function(sw) { | |
18 sw.addEventListener('statechange', t.step_func(onStateChange(sw))); | 16 sw.addEventListener('statechange', t.step_func(onStateChange(sw))); |
19 assert_equals(sw.state, 'installing', | 17 assert_equals(sw.state, 'installing', |
20 'the service worker should be in "installing" state.'); | 18 'the service worker should be in "installing" state.'); |
21 checkStateTransition(sw.state); | 19 checkStateTransition(sw.state); |
22 })) | 20 })) |
23 .catch(unreached_rejection(t)); | 21 .catch(unreached_rejection(t)); |
24 | 22 |
25 function checkStateTransition(newState) { | 23 function checkStateTransition(newState) { |
26 switch (currentState) { | 24 switch (currentState) { |
27 case 'test-is-starting': | 25 case 'test-is-starting': |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 'the type of the event should be "statechange".'); | 60 'the type of the event should be "statechange".'); |
63 | 61 |
64 checkStateTransition(event.target.state); | 62 checkStateTransition(event.target.state); |
65 | 63 |
66 if (event.target.state == 'activated') | 64 if (event.target.state == 'activated') |
67 service_worker_unregister_and_done(t, scope); | 65 service_worker_unregister_and_done(t, scope); |
68 }; | 66 }; |
69 } | 67 } |
70 }()); | 68 }()); |
71 </script> | 69 </script> |
OLD | NEW |