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.js"></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
) {
17 registration
.installing
.addEventListener('statechange',
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 assert_equals(registration
.waiting
.state
, 'installed',
26 'in installed, .waiting should be installed');
27 assert_equals(registration
.active
, null,
28 'in installed, .active should be null');
29 } else if (step
== 2) {
30 assert_equals(e
.currentTarget
.state
, 'activating',
31 'original SW should be activating');
32 assert_equals(registration
.installing
, null,
33 'in activating, .installing should be null');
34 assert_equals(registration
.waiting
, null,
35 'in activating, .waiting should be null');
37 registration
.active
.state
, 'activating',
38 'in activating, .active should be activating');
39 } else if (step
== 3) {
40 assert_equals(e
.currentTarget
.state
, 'activated',
41 'original SW should be activated');
42 assert_equals(registration
.installing
, null,
43 'in activated, .installing should be null');
44 assert_equals(registration
.waiting
, null,
45 'in activated, .waiting should be null');
46 assert_equals(registration
.active
.state
, 'activated',
47 'in activated .active should be activated');
54 return service_worker_unregister_and_done(t
, scope
);
56 }, 'worker objects for the same entity have the same state');