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/testharness-helpers.js"></script> |
| 6 <script src="resources/test-helpers.sub.js"></script> |
6 <script> | 7 <script> |
7 promise_test(function(t) { | 8 promise_test(function(t) { |
8 var scope = 'resources/scope/update'; | 9 var scope = 'resources/simple.txt'; |
9 var worker_url = 'resources/update-worker.php'; | 10 var worker_url = 'resources/update-worker.py'; |
10 var expected_url = normalizeURL(worker_url); | 11 var expected_url = normalizeURL(worker_url); |
11 var registration; | 12 var registration; |
| 13 var iframe; |
12 return service_worker_unregister_and_register(t, worker_url, scope) | 14 return service_worker_unregister_and_register(t, worker_url, scope) |
13 .then(function(r) { | 15 .then(function(r) { |
14 registration = r; | 16 registration = r; |
15 return wait_for_state(t, registration.installing, 'activated'); | 17 return wait_for_state(t, registration.installing, 'activated'); |
16 }) | 18 }) |
17 .then(function() { | 19 .then(function() { |
18 assert_equals(registration.installing, null, | 20 assert_equals(registration.installing, null, |
19 'installing should be null in the initial state.'); | 21 'installing should be null in the initial state.'); |
20 assert_equals(registration.waiting, null, | 22 assert_equals(registration.waiting, null, |
21 'waiting should be null in the initial state.'); | 23 'waiting should be null in the initial state.'); |
22 assert_equals(registration.active.scriptURL, expected_url, | 24 assert_equals(registration.active.scriptURL, expected_url, |
23 'active should exist in the initial state.'); | 25 'active should exist in the initial state.'); |
24 | 26 // A new worker (generated by update-worker.py) should be found. |
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 // The returned promise should resolve when a new worker script is |
27 // fetched and starts installing. | 28 // fetched and starts installing. |
28 return Promise.all([registration.update(), | 29 return Promise.all([registration.update(), |
29 wait_for_update(t, registration)]); | 30 wait_for_update(t, registration)]); |
30 }) | 31 }) |
31 .then(function() { | 32 .then(function() { |
32 assert_equals(registration.installing.scriptURL, expected_url, | 33 assert_equals(registration.installing.scriptURL, expected_url, |
33 'new installing should be set after update resolves.'); | 34 'new installing should be set after update resolves.'); |
34 assert_equals(registration.waiting, null, | 35 assert_equals(registration.waiting, null, |
35 'waiting should still be null after update resolves.'); | 36 'waiting should still be null after update resolves.'); |
36 assert_equals(registration.active.scriptURL, expected_url, | 37 assert_equals(registration.active.scriptURL, expected_url, |
37 'active should still exist after update found.'); | 38 'active should still exist after update found.'); |
38 return wait_for_state(t, registration.installing, 'installed'); | 39 return wait_for_state(t, registration.installing, 'installed'); |
39 }) | 40 }) |
40 .then(function() { | 41 .then(function() { |
41 assert_equals(registration.installing, null, | 42 assert_equals(registration.installing, null, |
42 'installing should be null after installing.'); | 43 'installing should be null after installing.'); |
43 assert_equals(registration.waiting.scriptURL, expected_url, | 44 if (registration.waiting) { |
44 'waiting should be set after installing.'); | 45 assert_equals(registration.waiting.scriptURL, expected_url, |
45 assert_equals(registration.active.scriptURL, expected_url, | 46 'waiting should be set after installing.'); |
46 'active should still exist after installing.'); | 47 assert_equals(registration.active.scriptURL, expected_url, |
47 return wait_for_state(t, registration.waiting, 'activated'); | 48 'active should still exist after installing.'); |
| 49 return wait_for_state(t, registration.waiting, 'activated'); |
| 50 } |
48 }) | 51 }) |
49 .then(function() { | 52 .then(function() { |
50 assert_equals(registration.installing, null, | 53 assert_equals(registration.installing, null, |
51 'installing should be null after activated.'); | 54 'installing should be null after activated.'); |
52 assert_equals(registration.waiting, null, | 55 assert_equals(registration.waiting, null, |
53 'waiting should be null after activated.'); | 56 'waiting should be null after activated.'); |
54 assert_equals(registration.active.scriptURL, expected_url, | 57 assert_equals(registration.active.scriptURL, expected_url, |
55 'new worker should be promoted to active.'); | 58 'new worker should be promoted to active.'); |
56 }) | 59 }) |
57 .then(function() { | 60 .then(function() { |
58 // A new worker(generated by update-worker.php) should be found. | 61 // A new worker(generated by update-worker.py) should be found. |
59 // The returned promise should reject as update-worker.php sets the | 62 // The returned promise should reject as update-worker.py sets the |
60 // mimetype to a disallowed value for this attempt. | 63 // mimetype to a disallowed value for this attempt. |
61 return registration.update(); | 64 return registration.update(); |
62 }) | 65 }) |
63 .then( | 66 .then( |
64 function() { assert_unreached("update() should reject."); }, | 67 function() { assert_unreached("update() should reject."); }, |
65 function(e) { | 68 function(e) { |
66 assert_throws('SecurityError', function() { throw e; }, | 69 assert_throws('SecurityError', function() { throw e; }, |
67 'Using a disallowed mimetype should make update() ' + | 70 'Using a disallowed mimetype should make update() ' + |
68 'promise reject with a SecurityError.'); | 71 'promise reject with a SecurityError.'); |
69 assert_equals(registration.active.scriptURL, expected_url, | 72 assert_equals(registration.active.scriptURL, expected_url, |
(...skipping 15 matching lines...) Expand all Loading... |
85 | 88 |
86 // A new worker(generated by update-worker.py) should be found. | 89 // A new worker(generated by update-worker.py) should be found. |
87 // The returned promise should not reject, even though | 90 // The returned promise should not reject, even though |
88 // update-worker.py returns a worker script that throws in the | 91 // update-worker.py returns a worker script that throws in the |
89 // install event handler. | 92 // install event handler. |
90 return Promise.all([registration.update(), | 93 return Promise.all([registration.update(), |
91 wait_for_update(t, registration)]); | 94 wait_for_update(t, registration)]); |
92 }) | 95 }) |
93 .then(function() { | 96 .then(function() { |
94 assert_equals(registration.installing.scriptURL, expected_url, | 97 assert_equals(registration.installing.scriptURL, expected_url, |
95 'installing should be set after update resolves (throw-i
nstall).'); | 98 'new installing should be set after update resolves.'); |
96 assert_equals(registration.waiting, null, | 99 assert_equals(registration.waiting, null, |
97 'waiting should still be null after update resolves (thr
ow-install).'); | 100 'waiting should be null after activated.'); |
98 assert_equals(registration.active.scriptURL, expected_url, | 101 assert_equals(registration.active.scriptURL, expected_url, |
99 'active should still exist after update found (throw-ins
tall).'); | 102 'active should still exist after update found.'); |
100 | 103 |
101 // 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 |
102 // remove the registration before update() has had a chance to look | 105 // remove the registration before update() has had a chance to look |
103 // at the pending uninstall flag. | 106 // at the pending uninstall flag. |
104 return with_iframe(scope); | 107 return with_iframe(scope); |
105 }) | 108 }) |
106 .then(function(frame) { | 109 .then(function(frame) { |
107 return Promise.all([registration.unregister(), | 110 iframe = frame; |
108 registration.update()]); | 111 |
| 112 return assert_promise_rejects( |
| 113 Promise.all([registration.unregister(), registration.update()]), |
| 114 new TypeError(), |
| 115 'Calling update() while the uninstalling flag is set ' + |
| 116 'should return a promise that rejects with a TypeError.'); |
109 }) | 117 }) |
110 .then( | 118 .then(function() { |
111 function() { assert_unreached("update() should reject."); }, | 119 iframe.remove(); |
112 function(e) { | 120 return t.done(); |
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 }); | 121 }); |
118 }, 'Update a registration.'); | 122 }, 'Update a registration.'); |
119 </script> | 123 </script> |
OLD | NEW |