Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / synced-state.html
blob63a6e5b23226e2cc655dd3473da658a965f77d2e
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.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 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');
36 assert_equals(
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');
48 resolve();
53 .then(function() {
54 return service_worker_unregister_and_done(t, scope);
55 });
56 }, 'worker objects for the same entity have the same state');
57 </script>