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.js"></script> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 var worker = 'resources/fetch-event-test-worker.js'; | 7 var worker = 'resources/fetch-event-test-worker.js'; |
8 | 8 |
9 async_test(function(t) { | 9 async_test(function(t) { |
10 var scope = 'resources/simple.html?string'; | 10 var scope = 'resources/simple.html?string'; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 frame.contentDocument.body.textContent, | 62 frame.contentDocument.body.textContent, |
63 'Referrer: ' + document.location.href, | 63 'Referrer: ' + document.location.href, |
64 'Service Worker should respond to fetch with the referrer URL'); | 64 'Service Worker should respond to fetch with the referrer URL'); |
65 frame.remove(); | 65 frame.remove(); |
66 return service_worker_unregister_and_done(t, scope); | 66 return service_worker_unregister_and_done(t, scope); |
67 }) | 67 }) |
68 .catch(unreached_rejection(t)); | 68 .catch(unreached_rejection(t)); |
69 }, 'Service Worker responds to fetch event with the referrer URL'); | 69 }, 'Service Worker responds to fetch event with the referrer URL'); |
70 | 70 |
71 async_test(function(t) { | 71 async_test(function(t) { |
72 var scope = 'resources/simple.html?clientId'; | |
73 var frame; | |
74 service_worker_unregister_and_register(t, worker, scope) | |
75 .then(function(reg) { | |
76 return wait_for_state(t, reg.installing, 'activated'); | |
77 }) | |
78 .then(function() { return with_iframe(scope); }) | |
79 .then(function(f) { | |
80 frame = f; | |
81 assert_equals( | |
82 frame.contentDocument.body.textContent.substr(0, 19), | |
83 'Client ID Not Found', | |
84 'Service Worker should respond to navigation fetch with null'); | |
falken
2016/01/13 09:06:53
"no client id"
jungkees
2016/01/13 10:55:18
Done.
| |
85 return frame.contentWindow.fetch('resources/other.html?clientId'); | |
86 }) | |
87 .then(function(response) { return response.text(); }) | |
88 .then(function(response_text) { | |
89 var client_id = response_text.substr(15); | |
90 assert_equals( | |
91 response_text.substr(0, 15), | |
92 'Client ID Found', | |
93 'Service Worker should respond to fetch with an existing client id') ; | |
falken
2016/01/13 09:06:53
"with a client id"
Then we should do another fetc
jungkees
2016/01/13 10:55:18
Done.
| |
94 frame.remove(); | |
95 return service_worker_unregister_and_done(t, scope); | |
96 }) | |
97 .catch(unreached_rejection(t)); | |
98 }, 'Service Worker responds to fetch event with an existing client id'); | |
falken
2016/01/13 09:06:53
"a client id"
jungkees
2016/01/13 10:55:18
Done.
| |
99 | |
100 async_test(function(t) { | |
72 var scope = 'resources/simple.html?ignore'; | 101 var scope = 'resources/simple.html?ignore'; |
73 service_worker_unregister_and_register(t, worker, scope) | 102 service_worker_unregister_and_register(t, worker, scope) |
74 .then(function(reg) { | 103 .then(function(reg) { |
75 return wait_for_state(t, reg.installing, 'activated'); | 104 return wait_for_state(t, reg.installing, 'activated'); |
76 }) | 105 }) |
77 .then(function() { return with_iframe(scope); }) | 106 .then(function() { return with_iframe(scope); }) |
78 .then(function(frame) { | 107 .then(function(frame) { |
79 assert_equals(frame.contentDocument.body.textContent, | 108 assert_equals(frame.contentDocument.body.textContent, |
80 'Here\'s a simple html file.\n', | 109 'Here\'s a simple html file.\n', |
81 'Response should come from fallback to native fetch'); | 110 'Response should come from fallback to native fetch'); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 document.body.appendChild(form); | 177 document.body.appendChild(form); |
149 frame.onload = function() { | 178 frame.onload = function() { |
150 document.body.removeChild(form); | 179 document.body.removeChild(form); |
151 resolve(frame); | 180 resolve(frame); |
152 }; | 181 }; |
153 form.submit(); | 182 form.submit(); |
154 }); | 183 }); |
155 }) | 184 }) |
156 .then(function(frame) { | 185 .then(function(frame) { |
157 assert_equals(frame.contentDocument.body.textContent, | 186 assert_equals(frame.contentDocument.body.textContent, |
158 'POST:testName1=testValue1&testName2=testValue2'); | 187 'POST:application/x-www-form-urlencoded:' + |
159 document.body.removeChild(frame); | 188 'testName1=testValue1&testName2=testValue2'); |
189 frame.remove(); | |
160 return service_worker_unregister_and_done(t, scope); | 190 return service_worker_unregister_and_done(t, scope); |
161 }) | 191 }) |
162 .catch(unreached_rejection(t)); | 192 .catch(unreached_rejection(t)); |
163 }, 'Service Worker responds to fetch event with POST form'); | 193 }, 'Service Worker responds to fetch event with POST form'); |
164 | 194 |
165 async_test(function(t) { | 195 async_test(function(t) { |
166 var scope = 'resources/simple.html?multiple-respond-with'; | 196 var scope = 'resources/simple.html?multiple-respond-with'; |
167 service_worker_unregister_and_register(t, worker, scope) | 197 service_worker_unregister_and_register(t, worker, scope) |
168 .then(function(reg) { | 198 .then(function(reg) { |
169 return wait_for_state(t, reg.installing, 'activated'); | 199 return wait_for_state(t, reg.installing, 'activated'); |
170 }) | 200 }) |
171 .then(function() { return with_iframe(scope); }) | 201 .then(function() { return with_iframe(scope); }) |
172 .then(function(frame) { | 202 .then(function(frame) { |
173 assert_equals( | 203 assert_equals( |
174 frame.contentDocument.body.textContent, | 204 frame.contentDocument.body.textContent, |
175 '(0)', | 205 '(0)(1)[InvalidStateError](2)[InvalidStateError]', |
176 'Response should be the argument of the first respondWith() call.'); | |
177 frame.remove(); | |
178 return with_iframe(scope); | |
179 }) | |
180 .then(function(frame) { | |
181 assert_equals( | |
182 frame.contentDocument.body.textContent, | |
183 '(0)(1)[InvalidStateError](2)[InvalidStateError](0)', | |
184 'Multiple calls of respondWith must throw InvalidStateErrors.'); | 206 'Multiple calls of respondWith must throw InvalidStateErrors.'); |
185 frame.remove(); | 207 frame.remove(); |
186 return service_worker_unregister_and_done(t, scope); | 208 return service_worker_unregister_and_done(t, scope); |
187 }) | 209 }) |
188 .catch(unreached_rejection(t)); | 210 .catch(unreached_rejection(t)); |
189 }, 'Multiple calls of respondWith must throw InvalidStateErrors'); | 211 }, 'Multiple calls of respondWith must throw InvalidStateErrors'); |
190 | 212 |
191 async_test(function(t) { | 213 async_test(function(t) { |
192 var scope = 'resources/simple.html?used-check'; | 214 var scope = 'resources/simple.html?used-check'; |
215 var first_frame; | |
193 service_worker_unregister_and_register(t, worker, scope) | 216 service_worker_unregister_and_register(t, worker, scope) |
194 .then(function(reg) { | 217 .then(function(reg) { |
195 return wait_for_state(t, reg.installing, 'activated'); | 218 return wait_for_state(t, reg.installing, 'activated'); |
196 }) | 219 }) |
197 .then(function() { return with_iframe(scope); }) | 220 .then(function() { return with_iframe(scope); }) |
198 .then(function(frame) { | 221 .then(function(frame) { |
199 assert_equals(frame.contentDocument.body.textContent, | 222 assert_equals(frame.contentDocument.body.textContent, |
200 'Here\'s an other html file.\n', | 223 'Here\'s an other html file.\n', |
201 'Response should come from fetched other file'); | 224 'Response should come from fetched other file'); |
202 frame.remove(); | 225 first_frame = frame; |
203 return with_iframe(scope); | 226 return with_iframe(scope); |
204 }) | 227 }) |
205 .then(function(frame) { | 228 .then(function(frame) { |
206 // When we access to the scope in the second time, the content of the | 229 // When we access to the scope in the second time, the content of the |
207 // response is generated inside the ServiceWorker. The body contains | 230 // response is generated inside the ServiceWorker. The body contains |
208 // the value of bodyUsed of the first response which is already | 231 // the value of bodyUsed of the first response which is already |
209 // consumed by FetchEvent.respondWith method. | 232 // consumed by FetchEvent.respondWith method. |
210 assert_equals( | 233 assert_equals( |
211 frame.contentDocument.body.textContent, | 234 frame.contentDocument.body.textContent, |
212 'bodyUsed: true', | 235 'bodyUsed: true', |
213 'event.respondWith must set the used flag.'); | 236 'event.respondWith must set the used flag.'); |
237 first_frame.remove(); | |
214 frame.remove(); | 238 frame.remove(); |
215 return service_worker_unregister_and_done(t, scope); | 239 return service_worker_unregister_and_done(t, scope); |
216 }) | 240 }) |
217 .catch(unreached_rejection(t)); | 241 .catch(unreached_rejection(t)); |
218 }, 'Service Worker event.respondWith must set the used flag'); | 242 }, 'Service Worker event.respondWith must set the used flag'); |
219 | 243 |
220 </script> | 244 </script> |
221 </body> | 245 </body> |
OLD | NEW |