OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <title>ServiceWorker: worker objects have synced state</title> |
| 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="/resources/testharnessreport.js"></script> |
| 5 <script src="resources/test-helpers.sub.js"></script> |
| 6 <script> |
| 7 // Tests that ServiceWorker objects representing the same Service Worker |
| 8 // entity have the same state. JS object equality is not tested, since the spec |
| 9 // does not require it. |
| 10 promise_test(function(t) { |
| 11 var scope = 'resources/synced-state'; |
| 12 var script = 'resources/empty-worker.js'; |
| 13 return service_worker_unregister_and_register(t, script, scope) |
| 14 .then(function(registration) { |
| 15 return new Promise(function(resolve) { |
| 16 var step = 0; |
| 17 registration.installing.addEventListener('statechange', |
| 18 function(e) { |
| 19 step++; |
| 20 if (step == 1) { |
| 21 assert_equals(e.currentTarget.state, 'installed', |
| 22 'original SW should be installed'); |
| 23 assert_equals(registration.installing, null, |
| 24 'in installed, .installing should be null'); |
| 25 // The Activate algorithm may have cleared the waiting worke
r |
| 26 // by now. |
| 27 if (registration.waiting) { |
| 28 assert_equals(registration.waiting.state, 'installed', |
| 29 'in installed, .waiting should be installed'
); |
| 30 assert_equals(registration.active, null, |
| 31 'in installed, .active should be null'); |
| 32 } else { |
| 33 assert_equals(registration.active.state, 'activating', |
| 34 'in installed, .active should be activating'
); |
| 35 } |
| 36 } else if (step == 2) { |
| 37 assert_equals(e.currentTarget.state, 'activating', |
| 38 'original SW should be activating'); |
| 39 assert_equals(registration.installing, null, |
| 40 'in activating, .installing should be null'); |
| 41 assert_equals(registration.waiting, null, |
| 42 'in activating, .waiting should be null'); |
| 43 assert_equals( |
| 44 registration.active.state, 'activating', |
| 45 'in activating, .active should be activating'); |
| 46 } else if (step == 3) { |
| 47 assert_equals(e.currentTarget.state, 'activated', |
| 48 'original SW should be activated'); |
| 49 assert_equals(registration.installing, null, |
| 50 'in activated, .installing should be null'); |
| 51 assert_equals(registration.waiting, null, |
| 52 'in activated, .waiting should be null'); |
| 53 assert_equals(registration.active.state, 'activated', |
| 54 'in activated .active should be activated'); |
| 55 resolve(); |
| 56 } |
| 57 }) |
| 58 }) |
| 59 }) |
| 60 .then(function() { |
| 61 return service_worker_unregister_and_done(t, scope); |
| 62 }); |
| 63 }, 'worker objects for the same entity have the same state'); |
| 64 </script> |
OLD | NEW |