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'; |
| 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 return service_worker_unregister_and_register(t, script, scope) |
| 14 .then(function(registration) { | 14 .then(function(registration) { |
| 15 return new Promise(function(resolve) { | 15 return new Promise(function(resolve) { |
| 16 var step = 0; | 16 var step = 0; |
| 17 registration.installing.addEventListener('statechange', | 17 registration.installing.addEventListener( |
| 18 function(e) { | 18 'statechange', function(e) { |
| 19 var state = e.currentTarget.state; | |
|
nhiroki
2016/04/11 06:15:24
unused?
shimazu (google)
2016/04/11 07:21:08
Done.
| |
| 20 console.log(e.currentTarget.state); | |
| 21 console.log(registration); | |
|
nhiroki
2016/04/11 06:15:24
Can you remove console.log()s?
shimazu (google)
2016/04/11 07:21:08
Done.
| |
| 22 navigator.serviceWorker.getRegistration(scope) | |
| 23 .then(function(r) { | |
| 24 assert_equals(r, registration, | |
| 25 'Equality of registration should ' + | |
| 26 'be kept all the time: ' + step); | |
|
nhiroki
2016/04/11 06:15:24
It's likely that the test step proceeds before thi
shimazu (google)
2016/04/11 07:21:08
Done.
| |
| 27 }); | |
| 19 step++; | 28 step++; |
| 20 if (step == 1) { | 29 if (step == 1) { |
| 21 assert_equals(e.currentTarget.state, 'installed', | 30 assert_equals(e.currentTarget.state, 'installed', |
| 22 'original SW should be installed'); | 31 'original SW should be installed'); |
| 23 assert_equals(registration.installing, null, | 32 assert_equals(registration.installing, null, |
| 24 'in installed, .installing should be null'); | 33 'in installed, .installing should be null'); |
| 25 assert_equals(registration.waiting.state, 'installed', | 34 assert_equals(registration.waiting.state, 'installed', |
| 26 'in installed, .waiting should be installed'); | 35 'in installed, the state of .waiting ' + |
| 36 'should be installed'); | |
| 27 assert_equals(registration.active, null, | 37 assert_equals(registration.active, null, |
| 28 'in installed, .active should be null'); | 38 'in installed, .active should be null'); |
| 39 assert_equals(registration.waiting, e.currentTarget, | |
| 40 'SW object should be kept the equality ' + | |
|
nhiroki
2016/04/11 06:15:24
".waiting should be equal to the original SW." wou
| |
| 41 '(installed)'); | |
| 29 } else if (step == 2) { | 42 } else if (step == 2) { |
| 30 assert_equals(e.currentTarget.state, 'activating', | 43 assert_equals(e.currentTarget.state, 'activating', |
| 31 'original SW should be activating'); | 44 'original SW should be activating'); |
| 32 assert_equals(registration.installing, null, | 45 assert_equals(registration.installing, null, |
| 33 'in activating, .installing should be null'); | 46 'in activating, .installing should be null'); |
| 34 assert_equals(registration.waiting, null, | 47 assert_equals(registration.waiting, null, |
| 35 'in activating, .waiting should be null'); | 48 'in activating, .waiting should be null'); |
| 36 assert_equals( | 49 assert_equals(registration.active.state, 'activating', |
| 37 registration.active.state, 'activating', | 50 'in activating, the state of .active ' + |
| 38 'in activating, .active should be activating'); | 51 'should be activating'); |
| 52 assert_equals(registration.active, e.currentTarget, | |
| 53 'SW object should be kept the equality ' + | |
| 54 '(activating)'); | |
|
nhiroki
2016/04/11 06:15:24
ditto
| |
| 39 } else if (step == 3) { | 55 } else if (step == 3) { |
| 40 assert_equals(e.currentTarget.state, 'activated', | 56 assert_equals(e.currentTarget.state, 'activated', |
| 41 'original SW should be activated'); | 57 'original SW should be activated'); |
| 42 assert_equals(registration.installing, null, | 58 assert_equals(registration.installing, null, |
| 43 'in activated, .installing should be null'); | 59 'in activated, .installing should be null'); |
| 44 assert_equals(registration.waiting, null, | 60 assert_equals(registration.waiting, null, |
| 45 'in activated, .waiting should be null'); | 61 'in activated, .waiting should be null'); |
| 46 assert_equals(registration.active.state, 'activated', | 62 assert_equals(registration.active.state, 'activated', |
| 47 'in activated .active should be activated'); | 63 'in activated, the state of .active should ' + |
| 64 'be activated'); | |
| 65 assert_equals(registration.active, e.currentTarget, | |
| 66 'SW object should be kept the equality ' + | |
| 67 '(activated)'); | |
|
nhiroki
2016/04/11 06:15:24
ditto.
| |
| 48 resolve(); | 68 resolve(); |
| 49 } | 69 } |
| 50 }) | 70 }); |
| 51 }) | 71 }); |
| 52 }) | 72 }) |
| 53 .then(function() { | 73 .then(function() { |
| 54 return service_worker_unregister_and_done(t, scope); | 74 return service_worker_unregister_and_done(t, scope); |
| 55 }); | 75 }); |
| 56 }, 'worker objects for the same entity have the same state'); | 76 }, 'worker objects for the same entity have the same state'); |
| 57 </script> | 77 </script> |
| OLD | NEW |