Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <title>ServiceWorker: worker objects have synced state</title> | 2 <title>ServiceWorker: worker objects have synced state</title> |
| 3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
| 6 <script> | 6 <script> |
| 7 // Tests that ServiceWorker objects representing the same Service Worker | 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 | 8 // entity have the same state. JS-level equality is now required according to |
| 9 // does not require it. | 9 // the spec. |
| 10 promise_test(function(t) { | 10 promise_test(function(t) { |
| 11 var scope = 'resources/synced-state'; | 11 var scope = 'resources/synced-state'; |
|
nhiroki
2016/04/18 03:26:53
Indents would be broken. These lines need 2 more s
shimazu (google)
2016/04/18 06:39:13
Done.
| |
| 12 var script = 'resources/empty-worker.js'; | 12 var script = 'resources/empty-worker.js'; |
| 13 return service_worker_unregister_and_register(t, script, scope) | 13 var registration; |
| 14 .then(function(registration) { | 14 return service_worker_unregister_and_register(t, script, scope) |
| 15 return new Promise(function(resolve) { | 15 .then(function(r) { |
| 16 var step = 0; | 16 var step = 0; |
| 17 registration.installing.addEventListener('statechange', | 17 registration = r; |
| 18 function(e) { | 18 add_completion_callback(function() { r.unregister(); }); |
| 19 step++; | 19 return new Promise(function(resolve) { |
| 20 if (step == 1) { | 20 r.installing.addEventListener('statechange', function(e) { |
| 21 assert_equals(e.currentTarget.state, 'installed', | 21 step++; |
| 22 'original SW should be installed'); | 22 if (step == 1) { |
| 23 assert_equals(registration.installing, null, | 23 assert_equals(e.currentTarget.state, 'installed', |
| 24 'in installed, .installing should be null'); | 24 'original SW should be installed'); |
| 25 assert_equals(registration.waiting.state, 'installed', | 25 assert_equals(r.installing, null, |
| 26 'in installed, .waiting should be installed'); | 26 'in installed, .installing should be null'); |
| 27 assert_equals(registration.active, null, | 27 assert_equals(r.waiting.state, 'installed', |
| 28 'in installed, .active should be null'); | 28 'in installed, the state of .waiting ' + |
| 29 } else if (step == 2) { | 29 'should be installed'); |
| 30 assert_equals(e.currentTarget.state, 'activating', | 30 assert_equals(r.active, null, |
| 31 'original SW should be activating'); | 31 'in installed, .active should be null'); |
| 32 assert_equals(registration.installing, null, | 32 assert_equals(r.waiting, e.currentTarget, |
| 33 'in activating, .installing should be null'); | 33 '.waiting should be equal to the original ' + |
| 34 assert_equals(registration.waiting, null, | 34 'SW in installed'); |
| 35 'in activating, .waiting should be null'); | 35 } else if (step == 2) { |
| 36 assert_equals( | 36 assert_equals(e.currentTarget.state, 'activating', |
| 37 registration.active.state, 'activating', | 37 'original SW should be activating'); |
| 38 'in activating, .active should be activating'); | 38 assert_equals(r.installing, null, |
| 39 } else if (step == 3) { | 39 'in activating, .installing should be null'); |
| 40 assert_equals(e.currentTarget.state, 'activated', | 40 assert_equals(r.waiting, null, |
| 41 'original SW should be activated'); | 41 'in activating, .waiting should be null'); |
| 42 assert_equals(registration.installing, null, | 42 assert_equals(r.active.state, 'activating', |
| 43 'in activated, .installing should be null'); | 43 'in activating, the state of .active ' + |
| 44 assert_equals(registration.waiting, null, | 44 'should be activating'); |
| 45 'in activated, .waiting should be null'); | 45 assert_equals(r.active, e.currentTarget, |
| 46 assert_equals(registration.active.state, 'activated', | 46 '.active should be equal to the original ' + |
| 47 'in activated .active should be activated'); | 47 'SW in activating'); |
| 48 resolve(); | 48 } else if (step == 3) { |
| 49 } | 49 assert_equals(e.currentTarget.state, 'activated', |
| 50 }) | 50 'original SW should be activated'); |
| 51 }) | 51 assert_equals(r.installing, null, |
| 52 }) | 52 'in activated, .installing should be null'); |
| 53 .then(function() { | 53 assert_equals(r.waiting, null, |
| 54 return service_worker_unregister_and_done(t, scope); | 54 'in activated, .waiting should be null'); |
| 55 }); | 55 assert_equals(r.active.state, 'activated', |
| 56 }, 'worker objects for the same entity have the same state'); | 56 'in activated, the state of .active should ' + |
| 57 'be activated'); | |
| 58 assert_equals(r.active, e.currentTarget, | |
| 59 '.active should be equal to the original ' + | |
| 60 'SW in activated'); | |
| 61 resolve(); | |
| 62 } | |
| 63 }); | |
| 64 }); | |
| 65 }) | |
| 66 .then(function() { | |
| 67 return navigator.serviceWorker.getRegistration(scope); | |
| 68 }) | |
| 69 .then(function(r) { | |
| 70 assert_equals(r, registration, 'getRegistration should return the ' + | |
| 71 'same object with the registered one'); | |
| 72 }); | |
| 73 }, 'worker objects for the same entity have the same state'); | |
| 57 </script> | 74 </script> |
| OLD | NEW |