| 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/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
| 6 <script> | 6 <script> |
| 7 promise_test(function(t) { | 7 promise_test(function(t) { |
| 8 var scope = 'resources/scope/update'; | 8 var scope = 'resources/scope/update'; |
| 9 var worker_url = 'resources/update-worker.php'; | 9 var worker_url = 'resources/update-worker.php'; |
| 10 var expected_url = normalizeURL(worker_url); | 10 var expected_url = normalizeURL(worker_url); |
| 11 var registration; | 11 var registration; |
| 12 | |
| 13 return service_worker_unregister_and_register(t, worker_url, scope) | 12 return service_worker_unregister_and_register(t, worker_url, scope) |
| 14 .then(function(r) { | 13 .then(function(r) { |
| 15 registration = r; | 14 registration = r; |
| 16 return wait_for_state(t, registration.installing, 'activated'); | 15 return wait_for_state(t, registration.installing, 'activated'); |
| 17 }) | 16 }) |
| 18 .then(function() { | 17 .then(function() { |
| 19 assert_equals(registration.installing, null, | 18 assert_equals(registration.installing, null, |
| 20 'installing should be null in the initial state.'); | 19 'installing should be null in the initial state.'); |
| 21 assert_equals(registration.waiting, null, | 20 assert_equals(registration.waiting, null, |
| 22 'waiting should be null in the initial state.'); | 21 'waiting should be null in the initial state.'); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return registration.update(); | 61 return registration.update(); |
| 63 }) | 62 }) |
| 64 .then( | 63 .then( |
| 65 function() { assert_unreached("update() should reject."); }, | 64 function() { assert_unreached("update() should reject."); }, |
| 66 function(e) { | 65 function(e) { |
| 67 assert_throws('SecurityError', function() { throw e; }, | 66 assert_throws('SecurityError', function() { throw e; }, |
| 68 'Using a disallowed mimetype should make update() ' + | 67 'Using a disallowed mimetype should make update() ' + |
| 69 'promise reject with a SecurityError.'); | 68 'promise reject with a SecurityError.'); |
| 70 assert_equals(registration.active.scriptURL, expected_url, | 69 assert_equals(registration.active.scriptURL, expected_url, |
| 71 'active should still exist after update failure.'); | 70 'active should still exist after update failure.'); |
| 72 return service_worker_unregister_and_done(t, scope); | 71 |
| 72 // A new worker(generated by update-worker.py) should be found. |
| 73 // The returned promise should reject as update-worker.py returns |
| 74 // a worker script with a syntax error. |
| 75 return registration.update(); |
| 76 }) |
| 77 .then( |
| 78 function() { assert_unreached("update() should reject."); }, |
| 79 function(e) { |
| 80 assert_throws({name: 'TypeError'}, function () { throw e; }, |
| 81 'A script syntax error should make update() ' + |
| 82 'promise reject with a TypeError.'); |
| 83 assert_equals(registration.active.scriptURL, expected_url, |
| 84 'active should still exist after update failure.'); |
| 85 |
| 86 // A new worker(generated by update-worker.py) should be found. |
| 87 // The returned promise should not reject, even though |
| 88 // update-worker.py returns a worker script that throws in the |
| 89 // install event handler. |
| 90 return Promise.all([registration.update(), |
| 91 wait_for_update(t, registration)]); |
| 92 }) |
| 93 .then(function() { |
| 94 assert_equals(registration.installing.scriptURL, expected_url, |
| 95 'installing should be set after update resolves (throw-i
nstall).'); |
| 96 assert_equals(registration.waiting, null, |
| 97 'waiting should still be null after update resolves (thr
ow-install).'); |
| 98 assert_equals(registration.active.scriptURL, expected_url, |
| 99 'active should still exist after update found (throw-ins
tall).'); |
| 100 |
| 101 // We need to hold a client alive so that unregister() below doesn't |
| 102 // remove the registration before update() has had a chance to look |
| 103 // at the pending uninstall flag. |
| 104 return with_iframe(scope); |
| 105 }) |
| 106 .then(function(frame) { |
| 107 return Promise.all([registration.unregister(), |
| 108 registration.update()]); |
| 109 }) |
| 110 .then( |
| 111 function() { assert_unreached("update() should reject."); }, |
| 112 function(e) { |
| 113 assert_throws({name: 'TypeError'}, function () { throw e; }, |
| 114 'Calling update() while the uninstalling flag is ' + |
| 115 'set should return a promise that rejects with an ' + |
| 116 'TypeError.'); |
| 73 }); | 117 }); |
| 74 }, 'Update a registration.'); | 118 }, 'Update a registration.'); |
| 75 </script> | 119 </script> |
| OLD | NEW |