| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Service Worker: Registration update()</title> | 2 <title>Service Worker: Registration update()</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/testharness-helpers.js"></script> | 5 <script src="resources/testharness-helpers.js"></script> |
| 6 <script src="resources/test-helpers.sub.js"></script> | 6 <script src="resources/test-helpers.sub.js"></script> |
| 7 <script> | 7 <script> |
| 8 'use strict'; |
| 9 |
| 8 promise_test(function(t) { | 10 promise_test(function(t) { |
| 9 var scope = 'resources/simple.txt'; | 11 var scope = 'resources/simple.txt'; |
| 10 var worker_url = 'resources/update-worker.py'; | 12 var worker_url = 'resources/update-worker.py'; |
| 11 var expected_url = normalizeURL(worker_url); | 13 var expected_url = normalizeURL(worker_url); |
| 12 var registration; | 14 var registration; |
| 13 var iframe; | 15 |
| 14 return service_worker_unregister_and_register(t, worker_url, scope) | 16 return service_worker_unregister_and_register(t, worker_url, scope) |
| 15 .then(function(r) { | 17 .then(function(r) { |
| 16 registration = r; | 18 registration = r; |
| 17 return wait_for_state(t, registration.installing, 'activated'); | 19 return wait_for_state(t, registration.installing, 'activated'); |
| 18 }) | 20 }) |
| 19 .then(function() { | 21 .then(function() { |
| 20 assert_equals(registration.installing, null, | 22 assert_equals(registration.installing, null, |
| 21 'installing should be null in the initial state.'); | 23 'installing should be null in the initial state.'); |
| 22 assert_equals(registration.waiting, null, | 24 assert_equals(registration.waiting, null, |
| 23 'waiting should be null in the initial state.'); | 25 'waiting should be null in the initial state.'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 34 'new installing should be set after update resolves.'); | 36 'new installing should be set after update resolves.'); |
| 35 assert_equals(registration.waiting, null, | 37 assert_equals(registration.waiting, null, |
| 36 'waiting should still be null after update resolves.'); | 38 'waiting should still be null after update resolves.'); |
| 37 assert_equals(registration.active.scriptURL, expected_url, | 39 assert_equals(registration.active.scriptURL, expected_url, |
| 38 'active should still exist after update found.'); | 40 'active should still exist after update found.'); |
| 39 return wait_for_state(t, registration.installing, 'installed'); | 41 return wait_for_state(t, registration.installing, 'installed'); |
| 40 }) | 42 }) |
| 41 .then(function() { | 43 .then(function() { |
| 42 assert_equals(registration.installing, null, | 44 assert_equals(registration.installing, null, |
| 43 'installing should be null after installing.'); | 45 'installing should be null after installing.'); |
| 44 if (registration.waiting) { | 46 assert_equals(registration.waiting.scriptURL, expected_url, |
| 45 assert_equals(registration.waiting.scriptURL, expected_url, | 47 'waiting should be set after installing.'); |
| 46 'waiting should be set after installing.'); | 48 assert_equals(registration.active.scriptURL, expected_url, |
| 47 assert_equals(registration.active.scriptURL, expected_url, | 49 'active should still exist after installing.'); |
| 48 'active should still exist after installing.'); | 50 return wait_for_state(t, registration.waiting, 'activated'); |
| 49 return wait_for_state(t, registration.waiting, 'activated'); | |
| 50 } | |
| 51 }) | 51 }) |
| 52 .then(function() { | 52 .then(function() { |
| 53 assert_equals(registration.installing, null, | 53 assert_equals(registration.installing, null, |
| 54 'installing should be null after activated.'); | 54 'installing should be null after activated.'); |
| 55 assert_equals(registration.waiting, null, | 55 assert_equals(registration.waiting, null, |
| 56 'waiting should be null after activated.'); | 56 'waiting should be null after activated.'); |
| 57 assert_equals(registration.active.scriptURL, expected_url, | 57 assert_equals(registration.active.scriptURL, expected_url, |
| 58 'new worker should be promoted to active.'); | 58 'new worker should be promoted to active.'); |
| 59 }) | 59 }) |
| 60 .then(function() { | 60 .then(function() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 'waiting should be null after activated.'); | 100 'waiting should be null after activated.'); |
| 101 assert_equals(registration.active.scriptURL, expected_url, | 101 assert_equals(registration.active.scriptURL, expected_url, |
| 102 'active should still exist after update found.'); | 102 'active should still exist after update found.'); |
| 103 | 103 |
| 104 // We need to hold a client alive so that unregister() below doesn't | 104 // We need to hold a client alive so that unregister() below doesn't |
| 105 // remove the registration before update() has had a chance to look | 105 // remove the registration before update() has had a chance to look |
| 106 // at the pending uninstall flag. | 106 // at the pending uninstall flag. |
| 107 return with_iframe(scope); | 107 return with_iframe(scope); |
| 108 }) | 108 }) |
| 109 .then(function(frame) { | 109 .then(function(frame) { |
| 110 iframe = frame; | 110 t.add_cleanup(function() { |
| 111 frame.remove(); |
| 112 }); |
| 111 | 113 |
| 112 return assert_promise_rejects( | 114 return assert_promise_rejects( |
| 113 Promise.all([registration.unregister(), registration.update()]), | 115 Promise.all([registration.unregister(), registration.update()]), |
| 114 new TypeError(), | 116 new TypeError(), |
| 115 'Calling update() while the uninstalling flag is set ' + | 117 'Calling update() while the uninstalling flag is set ' + |
| 116 'should return a promise that rejects with a TypeError.'); | 118 'should return a promise that rejects with a TypeError.'); |
| 117 }) | |
| 118 .then(function() { | |
| 119 iframe.remove(); | |
| 120 return t.done(); | |
| 121 }); | 119 }); |
| 122 }, 'Update a registration.'); | 120 }, 'Update a registration.'); |
| 123 </script> | 121 </script> |
| OLD | NEW |