OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <script src="../resources/testharness.js"></script> | |
3 <script src="../resources/testharnessreport.js"></script> | |
4 <script src="resources/test-helpers.js"></script> | |
5 <script> | |
6 var worker_url = 'resources/empty-worker.js'; | |
7 | |
8 async_test(function(t) { | |
9 var scope = 'resources/scope/re-register-resolves-to-new-value'; | |
10 var iframe; | |
11 var registration; | |
12 | |
13 service_worker_unregister_and_register(t, worker_url, scope) | |
14 .then(function(r) { | |
15 registration = r; | |
16 return wait_for_state(t, r.installing, 'activated'); | |
17 }) | |
18 .then(function() { | |
19 return registration.unregister(); | |
20 }) | |
21 .then(function() { | |
22 return navigator.serviceWorker.register(worker_url, { scope: scope }); | |
23 }) | |
24 .then(function(new_registration) { | |
25 assert_not_equals(registration, new_registration, | |
26 'register should resolve to a new value'); | |
27 service_worker_unregister_and_done(t, scope); | |
28 }) | |
29 .catch(unreached_rejection(t)); | |
30 }, 'Unregister then register resolves to a new value'); | |
31 | |
32 async_test(function(t) { | |
33 var scope = 'resources/scope/re-register-while-old-registration-in-use'; | |
34 var registration; | |
35 | |
36 service_worker_unregister_and_register(t, worker_url, scope) | |
37 .then(function(r) { | |
38 registration = r; | |
39 return wait_for_state(t, r.installing, 'activated'); | |
40 }) | |
41 .then(function() { | |
42 return with_iframe(scope); | |
43 }) | |
44 .then(function(frame) { | |
45 return registration.unregister(); | |
46 }) | |
47 .then(function() { | |
48 return navigator.serviceWorker.register(worker_url, { scope: scope }); | |
49 }) | |
50 .then(function(new_registration) { | |
51 assert_equals(registration, new_registration, | |
52 'register should resolve to the same registration'); | |
53 service_worker_unregister_and_done(t, scope); | |
54 }) | |
55 .catch(unreached_rejection(t)); | |
56 }, 'Unregister then register resolves to the original value if the ' + | |
57 'registration is in use.'); | |
58 | |
59 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
'; | |
100 var iframe; | |
101 var registration; | |
102 var controller; | |
103 | |
104 service_worker_unregister_and_register(t, worker_url, scope) | |
105 .then(function(r) { | |
106 registration = r; | |
107 return wait_for_state(t, r.installing, 'activated'); | |
108 }) | |
109 .then(function() { | |
110 return with_iframe(scope); | |
111 }) | |
112 .then(function(frame) { | |
113 iframe = frame; | |
114 controller = iframe.contentWindow.navigator.serviceWorker.controller; | |
115 return registration.unregister(); | |
116 }) | |
117 .then(function() { | |
118 return navigator.serviceWorker.register(worker_url, { scope: scope }); | |
119 }) | |
120 .then(function(registration) { | |
121 assert_equals(registration.installing, null, | |
122 'installing version is null'); | |
123 assert_equals(registration.waiting, null, 'waiting version is null'); | |
124 assert_equals( | |
125 iframe.contentWindow.navigator.serviceWorker.controller, | |
126 controller, | |
127 'the worker from the first registration is the controller'); | |
128 service_worker_unregister_and_done(t, scope); | |
129 }) | |
130 .catch(unreached_rejection(t)); | |
131 }, 'Unregister then register does not affect existing controllee'); | |
132 | |
133 async_test(function(t) { | |
134 var scope = 'resources/scope/resurrection'; | |
135 var iframe; | |
136 var registration; | |
137 | |
138 service_worker_unregister_and_register(t, worker_url, scope) | |
139 .then(function(r) { | |
140 registration = r; | |
141 return wait_for_state(t, r.installing, 'activated'); | |
142 }) | |
143 .then(function() { | |
144 return with_iframe(scope); | |
145 }) | |
146 .then(function(frame) { | |
147 iframe = frame; | |
148 return registration.unregister(); | |
149 }) | |
150 .then(function() { | |
151 return navigator.serviceWorker.register(worker_url, { scope: scope }); | |
152 }) | |
153 .then(function() { | |
154 iframe.remove(); | |
155 return with_iframe(scope); | |
156 }) | |
157 .then(function(frame) { | |
158 // FIXME: When crbug.com/400602 is fixed, assert that controller | |
159 // equals the original worker. | |
160 assert_not_equals( | |
161 frame.contentWindow.navigator.serviceWorker.controller, null, | |
162 'document should have a controller'); | |
163 service_worker_unregister_and_done(t, scope); | |
164 }) | |
165 .catch(unreached_rejection(t)); | |
166 }, 'Unregister then register resurrects the registration'); | |
167 </script> | |
OLD | NEW |