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.sub.js"></script> | 5 <script src="resources/test-helpers.sub.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. |
|
falken
2017/05/29 04:06:26
I think we lost the asserts about JS level equalit
mike3
2017/05/29 15:30:49
Acknowledged.
| |
| 10 'use strict'; | |
| 11 | |
| 12 function nextChange(worker) { | |
| 13 return new Promise(function(resolve, reject) { | |
| 14 worker.addEventListener('statechange', function handler(event) { | |
| 15 try { | |
| 16 worker.removeEventListener('statechange', handler); | |
| 17 resolve(event.currentTarget.state); | |
| 18 } catch (err) { | |
| 19 reject(err); | |
| 20 } | |
| 21 }); | |
| 22 }); | |
| 23 } | |
| 24 | |
| 10 promise_test(function(t) { | 25 promise_test(function(t) { |
| 11 var scope = 'resources/synced-state'; | 26 var scope = 'resources/synced-state'; |
| 12 var script = 'resources/empty-worker.js'; | 27 var script = 'resources/empty-worker.js'; |
| 28 var registration, worker; | |
| 29 | |
| 13 return service_worker_unregister_and_register(t, script, scope) | 30 return service_worker_unregister_and_register(t, script, scope) |
| 14 .then(function(registration) { | 31 .then(function(r) { |
| 15 return new Promise(function(resolve) { | 32 registration = r; |
| 16 var step = 0; | 33 worker = registration.installing; |
| 17 registration.installing.addEventListener('statechange', | 34 |
| 18 function(e) { | 35 t.add_cleanup(function() { |
| 19 step++; | 36 r.unregister(); |
| 20 if (step == 1) { | 37 }); |
| 21 assert_equals(e.currentTarget.state, 'installed', | 38 |
| 22 'original SW should be installed'); | 39 return nextChange(worker); |
| 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 }) | 40 }) |
| 60 .then(function() { | 41 .then(function(state) { |
| 61 return service_worker_unregister_and_done(t, scope); | 42 assert_equals(state, 'installed', |
| 43 'original SW should be installed'); | |
| 44 assert_equals(registration.installing, null, | |
| 45 'in installed, .installing should be null'); | |
| 46 assert_equals(registration.waiting.state, 'installed', | |
| 47 'in installed, .waiting should be installed'); | |
| 48 assert_equals(registration.active, null, | |
| 49 'in installed, .active should be null'); | |
|
falken
2017/05/29 04:06:25
assert_equals(registration.waiting, worker, ...);
mike3
2017/05/29 15:30:49
Done.
| |
| 50 | |
| 51 return nextChange(worker); | |
| 52 }) | |
| 53 .then(function(state) { | |
| 54 assert_equals(state, 'activating', | |
| 55 'original SW should be activating'); | |
| 56 assert_equals(registration.installing, null, | |
| 57 'in activating, .installing should be null'); | |
| 58 assert_equals(registration.waiting, null, | |
| 59 'in activating, .waiting should be null'); | |
| 60 assert_equals( | |
| 61 registration.active.state, 'activating', | |
| 62 'in activating, .active should be activating'); | |
|
falken
2017/05/29 04:06:25
assert_equals(registration.active, worker, ..);
mike3
2017/05/29 15:30:49
Done.
| |
| 63 | |
| 64 return nextChange(worker); | |
| 65 }) | |
| 66 .then(function(state) { | |
| 67 assert_equals(state, 'activated', | |
| 68 'original SW should be activated'); | |
| 69 assert_equals(registration.installing, null, | |
| 70 'in activated, .installing should be null'); | |
| 71 assert_equals(registration.waiting, null, | |
| 72 'in activated, .waiting should be null'); | |
| 73 assert_equals(registration.active.state, 'activated', | |
| 74 'in activated .active should be activated'); | |
|
falken
2017/05/29 04:06:25
assert_equals(registration.active, worker, ...)
mike3
2017/05/29 15:30:49
Done.
| |
| 62 }); | 75 }); |
| 63 }, 'worker objects for the same entity have the same state'); | 76 }, 'worker objects for the same entity have the same state'); |
| 64 </script> | 77 </script> |
| OLD | NEW |