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/unregister-then-register-new-script-that-exists
'; | |
10 var new_worker_url = worker_url + '?new'; | |
11 var iframe; | |
12 var registration; | |
13 var new_registration; | |
14 | |
15 service_worker_unregister_and_register(t, worker_url, scope) | |
16 .then(function(r) { | |
17 registration = r; | |
18 return wait_for_state(t, r.installing, 'activated'); | |
19 }) | |
20 .then(function() { | |
21 return with_iframe(scope); | |
22 }) | |
23 .then(function(frame) { | |
24 iframe = frame; | |
25 return registration.unregister(); | |
26 }) | |
27 .then(function() { | |
28 return navigator.serviceWorker.register(new_worker_url, | |
29 { scope: scope }); | |
30 }) | |
31 .then(function(r) { | |
32 new_registration = r; | |
33 assert_equals(registration.installing.scriptURL, | |
34 normalizeURL(new_worker_url), | |
35 'before activated registration.installing'); | |
36 assert_equals(registration.waiting, null, | |
37 'before activated registration.waiting'); | |
38 assert_equals(registration.active.scriptURL, normalizeURL(worker_url), | |
39 'before activated registration.active'); | |
40 assert_equals(new_registration.installing.scriptURL, | |
41 normalizeURL(new_worker_url), | |
42 'before activated new_registration.installing'); | |
43 assert_equals(new_registration.waiting, null, | |
44 'before activated new_registration.waiting'); | |
45 assert_equals(new_registration.active.scriptURL, | |
46 normalizeURL(worker_url), | |
47 'before activated new_registration.active'); | |
48 iframe.remove(); | |
49 return wait_for_state(t, registration.installing, 'activated'); | |
50 }) | |
51 .then(function() { | |
52 assert_equals(new_registration.installing, null, | |
53 'after activated new_registration.installing'); | |
54 assert_equals(new_registration.waiting, null, | |
55 'after activated new_registration.waiting'); | |
56 assert_equals(new_registration.active.scriptURL, | |
57 normalizeURL(new_worker_url), | |
58 'after activated new_registration.active'); | |
59 return with_iframe(scope); | |
60 }) | |
61 .then(function(frame) { | |
62 assert_equals( | |
63 frame.contentWindow.navigator.serviceWorker.controller.scriptURL, | |
64 normalizeURL(new_worker_url), | |
65 'the new worker should control a new document'); | |
66 frame.remove(); | |
67 return registration.unregister(); | |
68 }) | |
69 .then(function() { | |
70 t.done(); | |
71 }) | |
72 .catch(unreached_rejection(t)); | |
73 }, 'Registering a new script URL while an unregistered registration is in use'); | |
74 | |
75 async_test(function(t) { | |
76 var scope = 'resources/scope/unregister-then-register-new-script-that-404s'; | |
77 var iframe; | |
78 var registration; | |
79 | |
80 service_worker_unregister_and_register(t, worker_url, scope) | |
81 .then(function(r) { | |
82 registration = r; | |
83 return wait_for_state(t, r.installing, 'activated'); | |
84 }) | |
85 .then(function() { | |
86 return with_iframe(scope); | |
87 }) | |
88 .then(function(frame) { | |
89 iframe = frame; | |
90 return registration.unregister(); | |
91 }) | |
92 .then(function() { | |
93 var promise = navigator.serviceWorker.register('this-will-404', | |
94 { scope: scope }); | |
95 iframe.remove(); | |
96 return promise; | |
97 }) | |
98 .then( | |
99 function() { | |
100 assert_unreached('register should reject the promise'); | |
101 }, | |
102 function() { | |
103 return with_iframe(scope); | |
104 }) | |
105 .then(function(frame) { | |
106 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | |
107 null, | |
108 'document should not load with a controller'); | |
109 frame.remove(); | |
110 t.done(); | |
111 }) | |
112 .catch(unreached_rejection(t)); | |
113 }, 'Registering a new script URL that 404s does not resurrect an ' + | |
114 'unregistered registration'); | |
115 | |
116 async_test(function(t) { | |
117 var scope = 'resources/scope/unregister-then-register-reject-install-worker'
; | |
118 var iframe; | |
119 var registration; | |
120 | |
121 service_worker_unregister_and_register(t, worker_url, scope) | |
122 .then(function(r) { | |
123 registration = r; | |
124 return wait_for_state(t, r.installing, 'activated'); | |
125 }) | |
126 .then(function() { | |
127 return with_iframe(scope); | |
128 }) | |
129 .then(function(frame) { | |
130 iframe = frame; | |
131 return registration.unregister(); | |
132 }) | |
133 .then(function() { | |
134 var promise = navigator.serviceWorker.register( | |
135 'resources/reject-install-worker.js', { scope: scope }); | |
136 iframe.remove(); | |
137 return promise; | |
138 }) | |
139 .then(function(r) { | |
140 registration = r; | |
141 return wait_for_state(t, r.installing, 'redundant'); | |
142 }) | |
143 .then(function() { | |
144 return with_iframe(scope); | |
145 }) | |
146 .then(function(frame) { | |
147 assert_equals(frame.contentWindow.navigator.serviceWorker.controller, | |
148 null, | |
149 'document should not load with a controller'); | |
150 frame.remove(); | |
151 return registration.unregister(); | |
152 }) | |
153 .then(function() { | |
154 t.done(); | |
155 }) | |
156 .catch(unreached_rejection(t)); | |
157 }, 'Registering a new script URL that fails to install does not resurrect ' + | |
158 'an unregistered registration'); | |
159 </script> | |
OLD | NEW |