| 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 var client_id1, client_id2; |
| 75 service_worker_unregister_and_register(t, worker, scope) |
| 76 .then(function(reg) { |
| 77 return wait_for_state(t, reg.installing, 'activated'); |
| 78 }) |
| 79 .then(function() { return with_iframe(scope); }) |
| 80 .then(function(f) { |
| 81 frame = f; |
| 82 assert_equals( |
| 83 frame.contentDocument.body.textContent.substr(0, 19), |
| 84 'Client ID Not Found', |
| 85 'Service Worker should respond to navigation fetch with no ' + |
| 86 'client id'); |
| 87 return frame.contentWindow.fetch('resources/other.html?clientId'); |
| 88 }) |
| 89 .then(function(response) { return response.text(); }) |
| 90 .then(function(response_text) { |
| 91 client_id1 = response_text.substr(17, 36); |
| 92 assert_equals( |
| 93 response_text.substr(0, 15), |
| 94 'Client ID Found', |
| 95 'Service Worker should respond to fetch with a client id'); |
| 96 return frame.contentWindow.fetch('resources/other.html?clientId'); |
| 97 }) |
| 98 .then(function(response) { return response.text(); }) |
| 99 .then(function(response_text) { |
| 100 client_id2 = response_text.substr(17, 36); |
| 101 assert_equals( |
| 102 client_id1, |
| 103 client_id2, |
| 104 'Service Worker should respond to another fetch from the same ' + |
| 105 'client with the same client id'); |
| 106 frame.remove(); |
| 107 return service_worker_unregister_and_done(t, scope); |
| 108 }) |
| 109 .catch(unreached_rejection(t)); |
| 110 }, 'Service Worker responds to fetch event with a client id'); |
| 111 |
| 112 async_test(function(t) { |
| 72 var scope = 'resources/simple.html?ignore'; | 113 var scope = 'resources/simple.html?ignore'; |
| 73 service_worker_unregister_and_register(t, worker, scope) | 114 service_worker_unregister_and_register(t, worker, scope) |
| 74 .then(function(reg) { | 115 .then(function(reg) { |
| 75 return wait_for_state(t, reg.installing, 'activated'); | 116 return wait_for_state(t, reg.installing, 'activated'); |
| 76 }) | 117 }) |
| 77 .then(function() { return with_iframe(scope); }) | 118 .then(function() { return with_iframe(scope); }) |
| 78 .then(function(frame) { | 119 .then(function(frame) { |
| 79 assert_equals(frame.contentDocument.body.textContent, | 120 assert_equals(frame.contentDocument.body.textContent, |
| 80 'Here\'s a simple html file.\n', | 121 'Here\'s a simple html file.\n', |
| 81 'Response should come from fallback to native fetch'); | 122 '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); | 189 document.body.appendChild(form); |
| 149 frame.onload = function() { | 190 frame.onload = function() { |
| 150 document.body.removeChild(form); | 191 document.body.removeChild(form); |
| 151 resolve(frame); | 192 resolve(frame); |
| 152 }; | 193 }; |
| 153 form.submit(); | 194 form.submit(); |
| 154 }); | 195 }); |
| 155 }) | 196 }) |
| 156 .then(function(frame) { | 197 .then(function(frame) { |
| 157 assert_equals(frame.contentDocument.body.textContent, | 198 assert_equals(frame.contentDocument.body.textContent, |
| 158 'POST:testName1=testValue1&testName2=testValue2'); | 199 'POST:application/x-www-form-urlencoded:' + |
| 159 document.body.removeChild(frame); | 200 'testName1=testValue1&testName2=testValue2'); |
| 201 frame.remove(); |
| 160 return service_worker_unregister_and_done(t, scope); | 202 return service_worker_unregister_and_done(t, scope); |
| 161 }) | 203 }) |
| 162 .catch(unreached_rejection(t)); | 204 .catch(unreached_rejection(t)); |
| 163 }, 'Service Worker responds to fetch event with POST form'); | 205 }, 'Service Worker responds to fetch event with POST form'); |
| 164 | 206 |
| 165 async_test(function(t) { | 207 async_test(function(t) { |
| 166 var scope = 'resources/simple.html?multiple-respond-with'; | 208 var scope = 'resources/simple.html?multiple-respond-with'; |
| 167 service_worker_unregister_and_register(t, worker, scope) | 209 service_worker_unregister_and_register(t, worker, scope) |
| 168 .then(function(reg) { | 210 .then(function(reg) { |
| 169 return wait_for_state(t, reg.installing, 'activated'); | 211 return wait_for_state(t, reg.installing, 'activated'); |
| 170 }) | 212 }) |
| 171 .then(function() { return with_iframe(scope); }) | 213 .then(function() { return with_iframe(scope); }) |
| 172 .then(function(frame) { | 214 .then(function(frame) { |
| 173 assert_equals( | 215 assert_equals( |
| 174 frame.contentDocument.body.textContent, | 216 frame.contentDocument.body.textContent, |
| 175 '(0)', | 217 '(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.'); | 218 'Multiple calls of respondWith must throw InvalidStateErrors.'); |
| 185 frame.remove(); | 219 frame.remove(); |
| 186 return service_worker_unregister_and_done(t, scope); | 220 return service_worker_unregister_and_done(t, scope); |
| 187 }) | 221 }) |
| 188 .catch(unreached_rejection(t)); | 222 .catch(unreached_rejection(t)); |
| 189 }, 'Multiple calls of respondWith must throw InvalidStateErrors'); | 223 }, 'Multiple calls of respondWith must throw InvalidStateErrors'); |
| 190 | 224 |
| 191 async_test(function(t) { | 225 async_test(function(t) { |
| 192 var scope = 'resources/simple.html?used-check'; | 226 var scope = 'resources/simple.html?used-check'; |
| 227 var first_frame; |
| 193 service_worker_unregister_and_register(t, worker, scope) | 228 service_worker_unregister_and_register(t, worker, scope) |
| 194 .then(function(reg) { | 229 .then(function(reg) { |
| 195 return wait_for_state(t, reg.installing, 'activated'); | 230 return wait_for_state(t, reg.installing, 'activated'); |
| 196 }) | 231 }) |
| 197 .then(function() { return with_iframe(scope); }) | 232 .then(function() { return with_iframe(scope); }) |
| 198 .then(function(frame) { | 233 .then(function(frame) { |
| 199 assert_equals(frame.contentDocument.body.textContent, | 234 assert_equals(frame.contentDocument.body.textContent, |
| 200 'Here\'s an other html file.\n', | 235 'Here\'s an other html file.\n', |
| 201 'Response should come from fetched other file'); | 236 'Response should come from fetched other file'); |
| 202 frame.remove(); | 237 first_frame = frame; |
| 203 return with_iframe(scope); | 238 return with_iframe(scope); |
| 204 }) | 239 }) |
| 205 .then(function(frame) { | 240 .then(function(frame) { |
| 206 // When we access to the scope in the second time, the content of the | 241 // When we access to the scope in the second time, the content of the |
| 207 // response is generated inside the ServiceWorker. The body contains | 242 // response is generated inside the ServiceWorker. The body contains |
| 208 // the value of bodyUsed of the first response which is already | 243 // the value of bodyUsed of the first response which is already |
| 209 // consumed by FetchEvent.respondWith method. | 244 // consumed by FetchEvent.respondWith method. |
| 210 assert_equals( | 245 assert_equals( |
| 211 frame.contentDocument.body.textContent, | 246 frame.contentDocument.body.textContent, |
| 212 'bodyUsed: true', | 247 'bodyUsed: true', |
| 213 'event.respondWith must set the used flag.'); | 248 'event.respondWith must set the used flag.'); |
| 249 first_frame.remove(); |
| 214 frame.remove(); | 250 frame.remove(); |
| 215 return service_worker_unregister_and_done(t, scope); | 251 return service_worker_unregister_and_done(t, scope); |
| 216 }) | 252 }) |
| 217 .catch(unreached_rejection(t)); | 253 .catch(unreached_rejection(t)); |
| 218 }, 'Service Worker event.respondWith must set the used flag'); | 254 }, 'Service Worker event.respondWith must set the used flag'); |
| 219 | 255 |
| 220 </script> | 256 </script> |
| 221 </body> | 257 </body> |
| OLD | NEW |