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