| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <title>Service Worker: Registration update()</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 promise_test(function(t) { | |
| 8 var scope = 'resources/scope/update'; | |
| 9 var worker_url = 'resources/update-worker.php'; | |
| 10 var expected_url = normalizeURL(worker_url); | |
| 11 var registration; | |
| 12 return service_worker_unregister_and_register(t, worker_url, scope) | |
| 13 .then(function(r) { | |
| 14 registration = r; | |
| 15 return wait_for_state(t, registration.installing, 'activated'); | |
| 16 }) | |
| 17 .then(function() { | |
| 18 assert_equals(registration.installing, null, | |
| 19 'installing should be null in the initial state.'); | |
| 20 assert_equals(registration.waiting, null, | |
| 21 'waiting should be null in the initial state.'); | |
| 22 assert_equals(registration.active.scriptURL, expected_url, | |
| 23 'active should exist in the initial state.'); | |
| 24 | |
| 25 // A new worker (generated by update-worker.php) should be found. | |
| 26 // The returned promise should resolve when a new worker script is | |
| 27 // fetched and starts installing. | |
| 28 return Promise.all([registration.update(), | |
| 29 wait_for_update(t, registration)]); | |
| 30 }) | |
| 31 .then(function() { | |
| 32 assert_equals(registration.installing.scriptURL, expected_url, | |
| 33 'new installing should be set after update resolves.'); | |
| 34 assert_equals(registration.waiting, null, | |
| 35 'waiting should still be null after update resolves.'); | |
| 36 assert_equals(registration.active.scriptURL, expected_url, | |
| 37 'active should still exist after update found.'); | |
| 38 return wait_for_state(t, registration.installing, 'installed'); | |
| 39 }) | |
| 40 .then(function() { | |
| 41 assert_equals(registration.installing, null, | |
| 42 'installing should be null after installing.'); | |
| 43 assert_equals(registration.waiting.scriptURL, expected_url, | |
| 44 'waiting should be set after installing.'); | |
| 45 assert_equals(registration.active.scriptURL, expected_url, | |
| 46 'active should still exist after installing.'); | |
| 47 return wait_for_state(t, registration.waiting, 'activated'); | |
| 48 }) | |
| 49 .then(function() { | |
| 50 assert_equals(registration.installing, null, | |
| 51 'installing should be null after activated.'); | |
| 52 assert_equals(registration.waiting, null, | |
| 53 'waiting should be null after activated.'); | |
| 54 assert_equals(registration.active.scriptURL, expected_url, | |
| 55 'new worker should be promoted to active.'); | |
| 56 }) | |
| 57 .then(function() { | |
| 58 // A new worker(generated by update-worker.php) should be found. | |
| 59 // The returned promise should reject as update-worker.php sets the | |
| 60 // mimetype to a disallowed value for this attempt. | |
| 61 return registration.update(); | |
| 62 }) | |
| 63 .then( | |
| 64 function() { assert_unreached("update() should reject."); }, | |
| 65 function(e) { | |
| 66 assert_throws('SecurityError', function() { throw e; }, | |
| 67 'Using a disallowed mimetype should make update() ' + | |
| 68 'promise reject with a SecurityError.'); | |
| 69 assert_equals(registration.active.scriptURL, expected_url, | |
| 70 'active should still exist after update failure.'); | |
| 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.'); | |
| 117 }); | |
| 118 }, 'Update a registration.'); | |
| 119 </script> | |
| OLD | NEW |