OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="/resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="/resources/testharnessreport.js"></script> |
4 <script src="resources/test-helpers.js"></script> | 4 <script src="resources/test-helpers.sub.js"></script> |
5 <script> | 5 <script> |
6 promise_test(function(t) { | 6 async_test(function(t) { |
7 var scope = 'resources/scope/installing-waiting-active-after-registration'; | 7 var scope = 'resources/scope/installing-waiting-active-after-registration'; |
8 var worker_url = 'resources/empty-worker.js'; | 8 var worker_url = 'resources/empty-worker.js'; |
9 var expected_url = normalizeURL(worker_url); | 9 var expected_url = normalizeURL(worker_url); |
10 var installing_worker; | |
11 var registration; | |
12 | 10 |
13 return service_worker_unregister_and_register(t, worker_url, scope) | 11 service_worker_unregister_and_register(t, worker_url, scope) |
14 .then(function(r) { | 12 .then(function(r) { |
15 add_completion_callback(function() { r.unregister(); }); | |
16 registration = r; | 13 registration = r; |
17 installing_worker = registration.installing; | |
18 assert_equals(registration.installing.scriptURL, expected_url, | 14 assert_equals(registration.installing.scriptURL, expected_url, |
19 'installing before updatefound'); | 15 'installing before updatefound'); |
20 assert_equals(registration.waiting, null, | 16 assert_equals(registration.waiting, null, |
21 'waiting before updatefound'); | 17 'waiting before updatefound'); |
22 assert_equals(registration.active, null, | 18 assert_equals(registration.active, null, |
23 'active before updatefound'); | 19 'active before updatefound'); |
24 return wait_for_update(t, registration); | 20 return wait_for_update(t, registration); |
25 }) | 21 }) |
26 .then(function() { | 22 .then(function(worker) { |
27 assert_equals(registration.installing, installing_worker, | 23 assert_equals(registration.installing.scriptURL, expected_url, |
28 'installing after updatefound'); | 24 'installing after updatefound'); |
29 assert_equals(registration.waiting, null, | 25 assert_equals(registration.waiting, null, |
30 'waiting after updatefound'); | 26 'waiting after updatefound'); |
31 assert_equals(registration.active, null, | 27 assert_equals(registration.active, null, |
32 'active after updatefound'); | 28 'active after updatefound'); |
33 return wait_for_state(t, registration.installing, 'installed'); | 29 return wait_for_state(t, registration.installing, 'installed'); |
34 }) | 30 }) |
35 .then(function() { | 31 .then(function() { |
36 assert_equals(registration.installing, null, | 32 assert_equals(registration.installing, null, |
37 'installing after installed'); | 33 'installing after installed'); |
38 assert_equals(registration.waiting, installing_worker, | 34 var newest = registration.waiting || registration.active; |
39 'waiting after installed'); | 35 assert_equals(newest.scriptURL, expected_url, |
40 assert_equals(registration.active, null, | 36 'waiting or active after installed'); |
41 'active after installed'); | 37 if (registration.waiting) { |
42 return wait_for_state(t, registration.waiting, 'activated'); | 38 return wait_for_state(t, registration.waiting, 'activated') |
| 39 .then(function() { |
| 40 assert_equals(registration.installing, null, |
| 41 'installing after activated'); |
| 42 assert_equals(registration.waiting, null, |
| 43 'waiting after activated'); |
| 44 assert_equals(registration.active.scriptURL, expected_url, |
| 45 'active after activated'); |
| 46 }); |
| 47 } |
43 }) | 48 }) |
44 .then(function() { | 49 .then(function() { |
45 assert_equals(registration.installing, null, | |
46 'installing after activated'); | |
47 assert_equals(registration.waiting, null, | |
48 'waiting after activated'); | |
49 assert_equals(registration.active, installing_worker, | |
50 'active after activated'); | |
51 return Promise.all([ | 50 return Promise.all([ |
52 wait_for_state(t, registration.active, 'redundant'), | 51 wait_for_state(t, registration.active, 'redundant'), |
53 registration.unregister() | 52 registration.unregister() |
54 ]); | 53 ]); |
55 }) | 54 }) |
56 .then(function() { | 55 .then(function() { |
57 assert_equals(registration.installing, null, | 56 assert_equals(registration.installing, null, |
58 'installing after redundant'); | 57 'installing after redundant'); |
59 assert_equals(registration.waiting, null, | 58 assert_equals(registration.waiting, null, |
60 'waiting after redundant'); | 59 'waiting after redundant'); |
61 // According to spec, Clear Registration runs Update State which is | 60 // According to spec, Clear Registration runs Update State which is |
62 // immediately followed by setting active to null, which means by the | 61 // immediately followed by setting active to null, which means by the |
63 // time the event loop turns and the Promise for statechange is | 62 // time the event loop turns and the Promise for statechange is |
64 // resolved, this will be gone. | 63 // resolved, this will be gone. |
65 assert_equals(registration.active, null, | 64 assert_equals(registration.active, null, |
66 'active should be null after redundant'); | 65 'active should be null after redundant'); |
67 }); | 66 t.done(); |
| 67 }) |
| 68 .catch(unreached_rejection(t)); |
68 }, 'installing/waiting/active after registration'); | 69 }, 'installing/waiting/active after registration'); |
69 </script> | 70 </script> |
OLD | NEW |