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.sub.js"></script> |
5 <script> | 5 <script> |
6 var worker_url = 'resources/empty-worker.js'; | 6 var worker_url = 'resources/empty-worker.js'; |
7 | 7 |
8 async_test(function(t) { | 8 async_test(function(t) { |
9 var scope = 'resources/scope/re-register-resolves-to-new-value'; | 9 var scope = 'resources/scope/re-register-resolves-to-new-value'; |
10 var iframe; | |
11 var registration; | 10 var registration; |
12 | 11 |
13 service_worker_unregister_and_register(t, worker_url, scope) | 12 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, r.installing, 'activated'); | 15 return wait_for_state(t, r.installing, 'activated'); |
17 }) | 16 }) |
18 .then(function() { | 17 .then(function() { |
19 return registration.unregister(); | 18 return registration.unregister(); |
20 }) | 19 }) |
(...skipping 21 matching lines...) Expand all Loading... |
42 return with_iframe(scope); | 41 return with_iframe(scope); |
43 }) | 42 }) |
44 .then(function(frame) { | 43 .then(function(frame) { |
45 return registration.unregister(); | 44 return registration.unregister(); |
46 }) | 45 }) |
47 .then(function() { | 46 .then(function() { |
48 return navigator.serviceWorker.register(worker_url, { scope: scope }); | 47 return navigator.serviceWorker.register(worker_url, { scope: scope }); |
49 }) | 48 }) |
50 .then(function(new_registration) { | 49 .then(function(new_registration) { |
51 assert_equals(registration, new_registration, | 50 assert_equals(registration, new_registration, |
52 'register should resolve to the same registration'); | 51 'new registration should resolve to the same registratio
n'); |
53 service_worker_unregister_and_done(t, scope); | 52 service_worker_unregister_and_done(t, scope); |
54 }) | 53 }) |
55 .catch(unreached_rejection(t)); | 54 .catch(unreached_rejection(t)); |
56 }, 'Unregister then register resolves to the original value if the ' + | 55 }, 'Unregister then register resolves to the original value if the ' + |
57 'registration is in use.'); | 56 'registration is in use.'); |
58 | 57 |
59 async_test(function(t) { | 58 async_test(function(t) { |
60 var scope = 'resources/scope/complete-unregistration-followed-by-' + | |
61 'reloading-controllee-iframe'; | |
62 var registration; | |
63 var frame; | |
64 var service_worker; | |
65 service_worker_unregister_and_register(t, worker_url, scope) | |
66 .then(function(r) { | |
67 registration = r; | |
68 return wait_for_state(t, r.installing, 'activated'); | |
69 }) | |
70 .then(function() { | |
71 return with_iframe(scope); | |
72 }) | |
73 .then(function(f) { | |
74 frame = f; | |
75 return registration.unregister(); | |
76 }) | |
77 .then(function() { | |
78 return new Promise(function(resolve) { | |
79 frame.onload = resolve; | |
80 frame.contentWindow.location.reload(); | |
81 }); | |
82 }) | |
83 .then(function() { | |
84 var c = frame.contentWindow.navigator.serviceWorker.controller; | |
85 assert_equals(c, null, 'a page after unregistration should not be ' + | |
86 'controlled by service worker'); | |
87 return navigator.serviceWorker.getRegistration(scope); | |
88 }) | |
89 .then(function(r) { | |
90 assert_equals(r, undefined, 'getRegistration should return ' + | |
91 'undefined after unregistration'); | |
92 service_worker_unregister_and_done(t, scope); | |
93 }) | |
94 .catch(unreached_rejection(t)); | |
95 }, 'Reloading the last controlled iframe after unregistration should ensure ' + | |
96 'the deletion of the registration'); | |
97 | |
98 async_test(function(t) { | |
99 var scope = 'resources/scope/re-register-does-not-affect-existing-controllee
'; | 59 var scope = 'resources/scope/re-register-does-not-affect-existing-controllee
'; |
100 var iframe; | 60 var iframe; |
101 var registration; | 61 var registration; |
102 var controller; | 62 var controller; |
103 | 63 |
104 service_worker_unregister_and_register(t, worker_url, scope) | 64 service_worker_unregister_and_register(t, worker_url, scope) |
105 .then(function(r) { | 65 .then(function(r) { |
106 registration = r; | 66 registration = r; |
107 return wait_for_state(t, r.installing, 'activated'); | 67 return wait_for_state(t, r.installing, 'activated'); |
108 }) | 68 }) |
109 .then(function() { | 69 .then(function() { |
110 return with_iframe(scope); | 70 return with_iframe(scope); |
111 }) | 71 }) |
112 .then(function(frame) { | 72 .then(function(frame) { |
113 iframe = frame; | 73 iframe = frame; |
114 controller = iframe.contentWindow.navigator.serviceWorker.controller; | 74 controller = iframe.contentWindow.navigator.serviceWorker.controller; |
115 return registration.unregister(); | 75 return registration.unregister(); |
116 }) | 76 }) |
117 .then(function() { | 77 .then(function() { |
118 return navigator.serviceWorker.register(worker_url, { scope: scope }); | 78 return navigator.serviceWorker.register(worker_url, { scope: scope }); |
119 }) | 79 }) |
120 .then(function(registration) { | 80 .then(function(registration) { |
121 assert_equals(registration.installing, null, | 81 assert_equals(registration.installing, null, |
122 'installing version is null'); | 82 'installing version is null'); |
123 assert_equals(registration.waiting, null, 'waiting version is null'); | 83 assert_equals(registration.waiting, null, 'waiting version is null'); |
124 assert_equals( | 84 assert_equals( |
125 iframe.contentWindow.navigator.serviceWorker.controller, | 85 iframe.contentWindow.navigator.serviceWorker.controller, |
126 controller, | 86 controller, |
127 'the worker from the first registration is the controller'); | 87 'the worker from the first registration is the controller'); |
| 88 iframe.remove(); |
128 service_worker_unregister_and_done(t, scope); | 89 service_worker_unregister_and_done(t, scope); |
129 }) | 90 }) |
130 .catch(unreached_rejection(t)); | 91 .catch(unreached_rejection(t)); |
131 }, 'Unregister then register does not affect existing controllee'); | 92 }, 'Unregister then register does not affect existing controllee'); |
132 | 93 |
133 async_test(function(t) { | 94 async_test(function(t) { |
134 var scope = 'resources/scope/resurrection'; | 95 var scope = 'resources/scope/resurrection'; |
135 var iframe; | 96 var iframe; |
136 var registration; | 97 var registration; |
137 | 98 |
(...skipping 15 matching lines...) Expand all Loading... |
153 .then(function() { | 114 .then(function() { |
154 iframe.remove(); | 115 iframe.remove(); |
155 return with_iframe(scope); | 116 return with_iframe(scope); |
156 }) | 117 }) |
157 .then(function(frame) { | 118 .then(function(frame) { |
158 // FIXME: When crbug.com/400602 is fixed, assert that controller | 119 // FIXME: When crbug.com/400602 is fixed, assert that controller |
159 // equals the original worker. | 120 // equals the original worker. |
160 assert_not_equals( | 121 assert_not_equals( |
161 frame.contentWindow.navigator.serviceWorker.controller, null, | 122 frame.contentWindow.navigator.serviceWorker.controller, null, |
162 'document should have a controller'); | 123 'document should have a controller'); |
| 124 frame.remove(); |
163 service_worker_unregister_and_done(t, scope); | 125 service_worker_unregister_and_done(t, scope); |
164 }) | 126 }) |
165 .catch(unreached_rejection(t)); | 127 .catch(unreached_rejection(t)); |
166 }, 'Unregister then register resurrects the registration'); | 128 }, 'Unregister then register resurrects the registration'); |
167 </script> | 129 </script> |
OLD | NEW |