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 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness | 7 // Temporary measure to diagnose timeouts on Win XP. Let the W3C harness |
8 // timeout before run-webkit-tests does, so it can report the particular | 8 // timeout before run-webkit-tests does, so it can report the particular |
9 // test that timed out. | 9 // test that timed out. |
10 // FIXME: Remove after the cause of timeout is fixed. | 10 // FIXME: Remove after the cause of timeout is fixed. |
11 var properties = {timeout: 5500}; | 11 var properties = {timeout: 5500}; |
12 | 12 |
13 var worker = 'resources/fetch-event-test-worker.js'; | 13 var worker = 'resources/fetch-event-test-worker.js'; |
14 | 14 |
15 async_test(function(t) { | 15 async_test(function(t) { |
16 var scope = 'resources/simple.html?string'; | 16 var scope = 'resources/simple.html?string'; |
17 service_worker_unregister_and_register(t, worker, scope) | 17 service_worker_unregister_and_register(t, worker, scope) |
18 .then(function(reg) { return wait_for_activated(t, reg); }) | 18 .then(function(reg) { |
| 19 return wait_for_state(t, reg.installing, 'activated'); |
| 20 }) |
19 .then(function() { return with_iframe(scope); }) | 21 .then(function() { return with_iframe(scope); }) |
20 .then(function(frame) { | 22 .then(function(frame) { |
21 assert_equals( | 23 assert_equals( |
22 frame.contentDocument.body.textContent, | 24 frame.contentDocument.body.textContent, |
23 'Test string', | 25 'Test string', |
24 'Service Worker should respond to fetch with a test string'); | 26 'Service Worker should respond to fetch with a test string'); |
25 assert_equals( | 27 assert_equals( |
26 frame.contentDocument.contentType, | 28 frame.contentDocument.contentType, |
27 'text/plain', | 29 'text/plain', |
28 'The content type of the response created with a string should be te
xt/plain'); | 30 'The content type of the response created with a string should be te
xt/plain'); |
29 assert_equals( | 31 assert_equals( |
30 frame.contentDocument.characterSet, | 32 frame.contentDocument.characterSet, |
31 'UTF-8', | 33 'UTF-8', |
32 'The character set of the response created with a string should be U
TF-8'); | 34 'The character set of the response created with a string should be U
TF-8'); |
33 unload_iframe(frame); | 35 unload_iframe(frame); |
34 return service_worker_unregister_and_done(t, scope); | 36 return service_worker_unregister_and_done(t, scope); |
35 }) | 37 }) |
36 .catch(unreached_rejection(t)); | 38 .catch(unreached_rejection(t)); |
37 }, 'Service Worker responds to fetch event with string', properties); | 39 }, 'Service Worker responds to fetch event with string', properties); |
38 | 40 |
39 async_test(function(t) { | 41 async_test(function(t) { |
40 var scope = 'resources/simple.html?blob'; | 42 var scope = 'resources/simple.html?blob'; |
41 service_worker_unregister_and_register(t, worker, scope) | 43 service_worker_unregister_and_register(t, worker, scope) |
42 .then(function(reg) { return wait_for_activated(t, reg); }) | 44 .then(function(reg) { |
| 45 return wait_for_state(t, reg.installing, 'activated'); |
| 46 }) |
43 .then(function() { return with_iframe(scope); }) | 47 .then(function() { return with_iframe(scope); }) |
44 .then(function(frame) { | 48 .then(function(frame) { |
45 assert_equals( | 49 assert_equals( |
46 frame.contentDocument.body.textContent, | 50 frame.contentDocument.body.textContent, |
47 'Test blob', | 51 'Test blob', |
48 'Service Worker should respond to fetch with a test string'); | 52 'Service Worker should respond to fetch with a test string'); |
49 unload_iframe(frame); | 53 unload_iframe(frame); |
50 return service_worker_unregister_and_done(t, scope); | 54 return service_worker_unregister_and_done(t, scope); |
51 }) | 55 }) |
52 .catch(unreached_rejection(t)); | 56 .catch(unreached_rejection(t)); |
53 }, 'Service Worker responds to fetch event with blob body', properties); | 57 }, 'Service Worker responds to fetch event with blob body', properties); |
54 | 58 |
55 async_test(function(t) { | 59 async_test(function(t) { |
56 var scope = 'resources/simple.html?referrer'; | 60 var scope = 'resources/simple.html?referrer'; |
57 service_worker_unregister_and_register(t, worker, scope) | 61 service_worker_unregister_and_register(t, worker, scope) |
58 .then(function(reg) { return wait_for_activated(t, reg); }) | 62 .then(function(reg) { |
| 63 return wait_for_state(t, reg.installing, 'activated'); |
| 64 }) |
59 .then(function() { return with_iframe(scope); }) | 65 .then(function() { return with_iframe(scope); }) |
60 .then(function(frame) { | 66 .then(function(frame) { |
61 assert_equals( | 67 assert_equals( |
62 frame.contentDocument.body.textContent, | 68 frame.contentDocument.body.textContent, |
63 'Referrer: ' + document.location.href, | 69 'Referrer: ' + document.location.href, |
64 'Service Worker should respond to fetch with the referrer URL'); | 70 'Service Worker should respond to fetch with the referrer URL'); |
65 unload_iframe(frame); | 71 unload_iframe(frame); |
66 return service_worker_unregister_and_done(t, scope); | 72 return service_worker_unregister_and_done(t, scope); |
67 }) | 73 }) |
68 .catch(unreached_rejection(t)); | 74 .catch(unreached_rejection(t)); |
69 }, 'Service Worker responds to fetch event with the referrer URL', properties)
; | 75 }, 'Service Worker responds to fetch event with the referrer URL', properties)
; |
70 | 76 |
71 async_test(function(t) { | 77 async_test(function(t) { |
72 var scope = 'resources/simple.html?ignore'; | 78 var scope = 'resources/simple.html?ignore'; |
73 service_worker_unregister_and_register(t, worker, scope) | 79 service_worker_unregister_and_register(t, worker, scope) |
74 .then(function(reg) { return wait_for_activated(t, reg); }) | 80 .then(function(reg) { |
| 81 return wait_for_state(t, reg.installing, 'activated'); |
| 82 }) |
75 .then(function() { return with_iframe(scope); }) | 83 .then(function() { return with_iframe(scope); }) |
76 .then(function(frame) { | 84 .then(function(frame) { |
77 assert_equals(frame.contentDocument.body.textContent, | 85 assert_equals(frame.contentDocument.body.textContent, |
78 'Here\'s a simple html file.\n', | 86 'Here\'s a simple html file.\n', |
79 'Response should come from fallback to native fetch'); | 87 'Response should come from fallback to native fetch'); |
80 unload_iframe(frame); | 88 unload_iframe(frame); |
81 return service_worker_unregister_and_done(t, scope); | 89 return service_worker_unregister_and_done(t, scope); |
82 }) | 90 }) |
83 .catch(unreached_rejection(t)); | 91 .catch(unreached_rejection(t)); |
84 }, 'Service Worker does not respond to fetch event', properties); | 92 }, 'Service Worker does not respond to fetch event', properties); |
85 | 93 |
86 async_test(function(t) { | 94 async_test(function(t) { |
87 var scope = 'resources/simple.html?null'; | 95 var scope = 'resources/simple.html?null'; |
88 service_worker_unregister_and_register(t, worker, scope) | 96 service_worker_unregister_and_register(t, worker, scope) |
89 .then(function(reg) { return wait_for_activated(t, reg); }) | 97 .then(function(reg) { |
| 98 return wait_for_state(t, reg.installing, 'activated'); |
| 99 }) |
90 .then(function() { return with_iframe(scope); }) | 100 .then(function() { return with_iframe(scope); }) |
91 .then(function(frame) { | 101 .then(function(frame) { |
92 assert_equals(frame.contentDocument.body.textContent, | 102 assert_equals(frame.contentDocument.body.textContent, |
93 '', | 103 '', |
94 'Response should be the empty string'); | 104 'Response should be the empty string'); |
95 unload_iframe(frame); | 105 unload_iframe(frame); |
96 return service_worker_unregister_and_done(t, scope); | 106 return service_worker_unregister_and_done(t, scope); |
97 }) | 107 }) |
98 .catch(unreached_rejection(t)); | 108 .catch(unreached_rejection(t)); |
99 }, 'Service Worker responds to fetch event with null response body', propertie
s); | 109 }, 'Service Worker responds to fetch event with null response body', propertie
s); |
100 | 110 |
101 async_test(function(t) { | 111 async_test(function(t) { |
102 var scope = 'resources/simple.html?fetch'; | 112 var scope = 'resources/simple.html?fetch'; |
103 service_worker_unregister_and_register(t, worker, scope) | 113 service_worker_unregister_and_register(t, worker, scope) |
104 .then(function(reg) { return wait_for_activated(t, reg); }) | 114 .then(function(reg) { |
| 115 return wait_for_state(t, reg.installing, 'activated'); |
| 116 }) |
105 .then(function() { return with_iframe(scope); }) | 117 .then(function() { return with_iframe(scope); }) |
106 .then(function(frame) { | 118 .then(function(frame) { |
107 assert_equals(frame.contentDocument.body.textContent, | 119 assert_equals(frame.contentDocument.body.textContent, |
108 'Here\'s an other html file.\n', | 120 'Here\'s an other html file.\n', |
109 'Response should come from fetched other file'); | 121 'Response should come from fetched other file'); |
110 unload_iframe(frame); | 122 unload_iframe(frame); |
111 return service_worker_unregister_and_done(t, scope); | 123 return service_worker_unregister_and_done(t, scope); |
112 }) | 124 }) |
113 .catch(unreached_rejection(t)); | 125 .catch(unreached_rejection(t)); |
114 }, 'Service Worker fetches other file in fetch event', properties); | 126 }, 'Service Worker fetches other file in fetch event', properties); |
115 | 127 |
116 async_test(function(t) { | 128 async_test(function(t) { |
117 var scope = 'resources/simple.html?form-post'; | 129 var scope = 'resources/simple.html?form-post'; |
118 var frame_name = 'xhr-post-frame'; | 130 var frame_name = 'xhr-post-frame'; |
119 service_worker_unregister_and_register(t, worker, scope) | 131 service_worker_unregister_and_register(t, worker, scope) |
120 .then(function(reg) { return wait_for_activated(t, reg); }) | 132 .then(function(reg) { |
| 133 return wait_for_state(t, reg.installing, 'activated'); |
| 134 }) |
121 .then(function(sw) { | 135 .then(function(sw) { |
122 return new Promise(function(resolve) { | 136 return new Promise(function(resolve) { |
123 var frame = document.createElement('iframe'); | 137 var frame = document.createElement('iframe'); |
124 frame.name = frame_name; | 138 frame.name = frame_name; |
125 document.body.appendChild(frame); | 139 document.body.appendChild(frame); |
126 var form = document.createElement('form'); | 140 var form = document.createElement('form'); |
127 form.target = frame_name; | 141 form.target = frame_name; |
128 form.action = scope; | 142 form.action = scope; |
129 form.method = 'post'; | 143 form.method = 'post'; |
130 var input1 = document.createElement('input'); | 144 var input1 = document.createElement('input'); |
(...skipping 19 matching lines...) Expand all Loading... |
150 'POST:testName1=testValue1&testName2=testValue2'); | 164 'POST:testName1=testValue1&testName2=testValue2'); |
151 document.body.removeChild(frame); | 165 document.body.removeChild(frame); |
152 return service_worker_unregister_and_done(t, scope); | 166 return service_worker_unregister_and_done(t, scope); |
153 }) | 167 }) |
154 .catch(unreached_rejection(t)); | 168 .catch(unreached_rejection(t)); |
155 }, 'Service Worker responds to fetch event with POST form', properties); | 169 }, 'Service Worker responds to fetch event with POST form', properties); |
156 | 170 |
157 async_test(function(t) { | 171 async_test(function(t) { |
158 var scope = 'resources/simple.html?multiple-respond-with'; | 172 var scope = 'resources/simple.html?multiple-respond-with'; |
159 service_worker_unregister_and_register(t, worker, scope) | 173 service_worker_unregister_and_register(t, worker, scope) |
160 .then(function(reg) { return wait_for_activated(t, reg); }) | 174 .then(function(reg) { |
| 175 return wait_for_state(t, reg.installing, 'activated'); |
| 176 }) |
161 .then(function() { return with_iframe(scope); }) | 177 .then(function() { return with_iframe(scope); }) |
162 .then(function(frame) { | 178 .then(function(frame) { |
163 assert_equals( | 179 assert_equals( |
164 frame.contentDocument.body.textContent, | 180 frame.contentDocument.body.textContent, |
165 '(0)', | 181 '(0)', |
166 'Response should be the argument of the first respondWith() call.'); | 182 'Response should be the argument of the first respondWith() call.'); |
167 unload_iframe(frame); | 183 unload_iframe(frame); |
168 return with_iframe(scope); | 184 return with_iframe(scope); |
169 }) | 185 }) |
170 .then(function(frame) { | 186 .then(function(frame) { |
171 assert_equals( | 187 assert_equals( |
172 frame.contentDocument.body.textContent, | 188 frame.contentDocument.body.textContent, |
173 '(0)(1)[InvalidStateError](2)[InvalidStateError](0)', | 189 '(0)(1)[InvalidStateError](2)[InvalidStateError](0)', |
174 'Multiple calls of respondWith must throw InvalidStateErrors.'); | 190 'Multiple calls of respondWith must throw InvalidStateErrors.'); |
175 unload_iframe(frame); | 191 unload_iframe(frame); |
176 return service_worker_unregister_and_done(t, scope); | 192 return service_worker_unregister_and_done(t, scope); |
177 }) | 193 }) |
178 .catch(unreached_rejection(t)); | 194 .catch(unreached_rejection(t)); |
179 }, 'Multiple calls of respondWith must throw InvalidStateErrors', properties); | 195 }, 'Multiple calls of respondWith must throw InvalidStateErrors', properties); |
180 | 196 |
181 async_test(function(t) { | 197 async_test(function(t) { |
182 var scope = 'resources/simple.html?used-check'; | 198 var scope = 'resources/simple.html?used-check'; |
183 service_worker_unregister_and_register(t, worker, scope) | 199 service_worker_unregister_and_register(t, worker, scope) |
184 .then(function(reg) { return wait_for_activated(t, reg); }) | 200 .then(function(reg) { |
| 201 return wait_for_state(t, reg.installing, 'activated'); |
| 202 }) |
185 .then(function() { return with_iframe(scope); }) | 203 .then(function() { return with_iframe(scope); }) |
186 .then(function(frame) { | 204 .then(function(frame) { |
187 assert_equals(frame.contentDocument.body.textContent, | 205 assert_equals(frame.contentDocument.body.textContent, |
188 'Here\'s an other html file.\n', | 206 'Here\'s an other html file.\n', |
189 'Response should come from fetched other file'); | 207 'Response should come from fetched other file'); |
190 unload_iframe(frame); | 208 unload_iframe(frame); |
191 return with_iframe(scope); | 209 return with_iframe(scope); |
192 }) | 210 }) |
193 .then(function(frame) { | 211 .then(function(frame) { |
194 // When we access to the scope in the second time, the content of the | 212 // When we access to the scope in the second time, the content of the |
195 // response is generated inside the ServiceWorker. The body contains | 213 // response is generated inside the ServiceWorker. The body contains |
196 // the value of bodyUsed of the first response which is already | 214 // the value of bodyUsed of the first response which is already |
197 // consumed by FetchEvent.respondWith method. | 215 // consumed by FetchEvent.respondWith method. |
198 assert_equals( | 216 assert_equals( |
199 frame.contentDocument.body.textContent, | 217 frame.contentDocument.body.textContent, |
200 'bodyUsed: true', | 218 'bodyUsed: true', |
201 'event.respondWith must set the used flag.'); | 219 'event.respondWith must set the used flag.'); |
202 unload_iframe(frame); | 220 unload_iframe(frame); |
203 return service_worker_unregister_and_done(t, scope); | 221 return service_worker_unregister_and_done(t, scope); |
204 }) | 222 }) |
205 .catch(unreached_rejection(t)); | 223 .catch(unreached_rejection(t)); |
206 }, 'Service Worker event.respondWith must set the used flag', properties); | 224 }, 'Service Worker event.respondWith must set the used flag', properties); |
207 | 225 |
208 </script> | 226 </script> |
209 </body> | 227 </body> |
OLD | NEW |