Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: LayoutTests/http/tests/serviceworker/fetch-event.html

Issue 531423002: ServiceWorker: Clean up fetch-event.html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: introduce wait_fo_activated Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/resources/test-helpers.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(registration) { 18 .then(function(reg) { return wait_for_activated(t, reg); })
19 return wait_for_update(t, registration); 19 .then(function() { return with_iframe(scope); })
20 }) 20 .then(function(frame) {
21 .then(t.step_func(function(sw) {
22 return wait_for_state(t, sw, 'activated');
23 }))
24 .then(t.step_func(function() { return with_iframe(scope); }))
25 .then(t.step_func(function(frame) {
26 assert_equals( 21 assert_equals(
27 frame.contentDocument.body.textContent, 22 frame.contentDocument.body.textContent,
28 'Test string', 23 'Test string',
29 'Service Worker should respond to fetch with a test string'); 24 'Service Worker should respond to fetch with a test string');
30 assert_equals( 25 assert_equals(
31 frame.contentDocument.contentType, 26 frame.contentDocument.contentType,
32 'text/plain', 27 'text/plain',
33 'The content type of the response created with a string should be te xt/plain'); 28 'The content type of the response created with a string should be te xt/plain');
34 assert_equals( 29 assert_equals(
35 frame.contentDocument.characterSet, 30 frame.contentDocument.characterSet,
36 'UTF-8', 31 'UTF-8',
37 'The character set of the response created with a string should be U TF-8'); 32 'The character set of the response created with a string should be U TF-8');
33 unload_iframe(frame);
38 return service_worker_unregister_and_done(t, scope); 34 return service_worker_unregister_and_done(t, scope);
39 })) 35 })
40 .catch(unreached_rejection(t)); 36 .catch(unreached_rejection(t));
41 }, 'Service Worker responds to fetch event with string', properties); 37 }, 'Service Worker responds to fetch event with string', properties);
42 38
43 async_test(function(t) { 39 async_test(function(t) {
44 var scope = 'resources/simple.html?blob'; 40 var scope = 'resources/simple.html?blob';
45 service_worker_unregister_and_register(t, worker, scope) 41 service_worker_unregister_and_register(t, worker, scope)
46 .then(function(registration) { 42 .then(function(reg) { return wait_for_activated(t, reg); })
47 return wait_for_update(t, registration); 43 .then(function() { return with_iframe(scope); })
48 }) 44 .then(function(frame) {
49 .then(t.step_func(function(sw) {
50 return wait_for_state(t, sw, 'activated');
51 }))
52 .then(t.step_func(function() { return with_iframe(scope); }))
53 .then(t.step_func(function(frame) {
54 assert_equals( 45 assert_equals(
55 frame.contentDocument.body.textContent, 46 frame.contentDocument.body.textContent,
56 'Test blob', 47 'Test blob',
57 'Service Worker should respond to fetch with a test string'); 48 'Service Worker should respond to fetch with a test string');
49 unload_iframe(frame);
58 return service_worker_unregister_and_done(t, scope); 50 return service_worker_unregister_and_done(t, scope);
59 })) 51 })
60 .catch(unreached_rejection(t)); 52 .catch(unreached_rejection(t));
61 }, 'Service Worker responds to fetch event with blob body', properties); 53 }, 'Service Worker responds to fetch event with blob body', properties);
62 54
63 async_test(function(t) { 55 async_test(function(t) {
64 var scope = 'resources/simple.html?referrer'; 56 var scope = 'resources/simple.html?referrer';
65 service_worker_unregister_and_register(t, worker, scope) 57 service_worker_unregister_and_register(t, worker, scope)
66 .then(function(registration) { 58 .then(function(reg) { return wait_for_activated(t, reg); })
67 return wait_for_update(t, registration); 59 .then(function() { return with_iframe(scope); })
68 }) 60 .then(function(frame) {
69 .then(t.step_func(function(sw) {
70 return wait_for_state(t, sw, 'activated');
71 }))
72 .then(t.step_func(function() { return with_iframe(scope); }))
73 .then(t.step_func(function(frame) {
74 assert_equals( 61 assert_equals(
75 frame.contentDocument.body.textContent, 62 frame.contentDocument.body.textContent,
76 'Referrer: ' + document.location.href, 63 'Referrer: ' + document.location.href,
77 'Service Worker should respond to fetch with the referrer URL'); 64 'Service Worker should respond to fetch with the referrer URL');
65 unload_iframe(frame);
78 return service_worker_unregister_and_done(t, scope); 66 return service_worker_unregister_and_done(t, scope);
79 })) 67 })
80 .catch(unreached_rejection(t)); 68 .catch(unreached_rejection(t));
81 }, 'Service Worker responds to fetch event with the referrer URL', properties) ; 69 }, 'Service Worker responds to fetch event with the referrer URL', properties) ;
82 70
83 async_test(function(t) { 71 async_test(function(t) {
84 var scope = 'resources/simple.html?ignore'; 72 var scope = 'resources/simple.html?ignore';
85 service_worker_unregister_and_register(t, worker, scope) 73 service_worker_unregister_and_register(t, worker, scope)
86 .then(function(registration) { 74 .then(function(reg) { return wait_for_activated(t, reg); })
87 return wait_for_update(t, registration); 75 .then(function() { return with_iframe(scope); })
88 }) 76 .then(function(frame) {
89 .then(t.step_func(function(sw) {
90 return wait_for_state(t, sw, 'activated');
91 }))
92 .then(t.step_func(function() { return with_iframe(scope); }))
93 .then(t.step_func(function(frame) {
94 assert_equals(frame.contentDocument.body.textContent, 77 assert_equals(frame.contentDocument.body.textContent,
95 'Here\'s a simple html file.\n', 78 'Here\'s a simple html file.\n',
96 'Response should come from fallback to native fetch'); 79 'Response should come from fallback to native fetch');
80 unload_iframe(frame);
97 return service_worker_unregister_and_done(t, scope); 81 return service_worker_unregister_and_done(t, scope);
98 })) 82 })
99 .catch(unreached_rejection(t)); 83 .catch(unreached_rejection(t));
100 }, 'Service Worker does not respond to fetch event', properties); 84 }, 'Service Worker does not respond to fetch event', properties);
101 85
102 async_test(function(t) { 86 async_test(function(t) {
103 var scope = 'resources/simple.html?null'; 87 var scope = 'resources/simple.html?null';
104 service_worker_unregister_and_register(t, worker, scope) 88 service_worker_unregister_and_register(t, worker, scope)
105 .then(function(registration) { 89 .then(function(reg) { return wait_for_activated(t, reg); })
106 return wait_for_update(t, registration); 90 .then(function() { return with_iframe(scope); })
107 }) 91 .then(function(frame) {
108 .then(t.step_func(function(sw) {
109 return wait_for_state(t, sw, 'activated');
110 }))
111 .then(t.step_func(function() { return with_iframe(scope); }))
112 .then(t.step_func(function(frame) {
113 assert_equals(frame.contentDocument.body.textContent, 92 assert_equals(frame.contentDocument.body.textContent,
114 '', 93 '',
115 'Response should be the empty string'); 94 'Response should be the empty string');
95 unload_iframe(frame);
116 return service_worker_unregister_and_done(t, scope); 96 return service_worker_unregister_and_done(t, scope);
117 })) 97 })
118 .catch(unreached_rejection(t)); 98 .catch(unreached_rejection(t));
119 }, 'Service Worker responds to fetch event with null response body', propertie s); 99 }, 'Service Worker responds to fetch event with null response body', propertie s);
120 100
121 async_test(function(t) { 101 async_test(function(t) {
122 var scope = 'resources/simple.html?reject'; 102 var scope = 'resources/simple.html?reject';
123 service_worker_unregister_and_register(t, worker, scope) 103 service_worker_unregister_and_register(t, worker, scope)
124 .then(function(registration) { 104 .then(function(reg) { return wait_for_activated(t, reg); })
125 return wait_for_update(t, registration); 105 .then(function() { return with_iframe(scope); })
126 }) 106 .then(function(frame) {
127 .then(t.step_func(function(sw) {
128 return wait_for_state(t, sw, 'activated');
129 }))
130 .then(t.step_func(function() { return with_iframe(scope); }))
131 .then(t.step_func(function(frame) {
132 assert_equals(frame.contentDocument.body.textContent, 107 assert_equals(frame.contentDocument.body.textContent,
133 'Here\'s a simple html file.\n', 108 'Here\'s a simple html file.\n',
134 'Response should come from fallback to native fetch'); 109 'Response should come from fallback to native fetch');
110 unload_iframe(frame);
135 return service_worker_unregister_and_done(t, scope); 111 return service_worker_unregister_and_done(t, scope);
136 })) 112 })
137 .catch(unreached_rejection(t)); 113 .catch(unreached_rejection(t));
138 }, 'Service Worker rejects fetch event', properties); 114 }, 'Service Worker rejects fetch event', properties);
139 115
140 async_test(function(t) { 116 async_test(function(t) {
141 var scope = 'resources/simple.html?fetch'; 117 var scope = 'resources/simple.html?fetch';
142 service_worker_unregister_and_register(t, worker, scope) 118 service_worker_unregister_and_register(t, worker, scope)
143 .then(function(registration) { 119 .then(function(reg) { return wait_for_activated(t, reg); })
144 return wait_for_update(t, registration); 120 .then(function() { return with_iframe(scope); })
145 }) 121 .then(function(frame) {
146 .then(t.step_func(function(sw) {
147 return wait_for_state(t, sw, 'activated');
148 }))
149 .then(t.step_func(function() { return with_iframe(scope); }))
150 .then(t.step_func(function(frame) {
151 assert_equals(frame.contentDocument.body.textContent, 122 assert_equals(frame.contentDocument.body.textContent,
152 'Here\'s an other html file.\n', 123 'Here\'s an other html file.\n',
153 'Response should come from fetched other file'); 124 'Response should come from fetched other file');
125 unload_iframe(frame);
154 return service_worker_unregister_and_done(t, scope); 126 return service_worker_unregister_and_done(t, scope);
155 })) 127 })
156 .catch(unreached_rejection(t)); 128 .catch(unreached_rejection(t));
157 }, 'Service Worker fetches other file in fetch event', properties); 129 }, 'Service Worker fetches other file in fetch event', properties);
158 130
159 async_test(function(t) { 131 async_test(function(t) {
160 var scope = 'resources/simple.html?form-post'; 132 var scope = 'resources/simple.html?form-post';
161 var frame_name = 'xhr-post-frame'; 133 var frame_name = 'xhr-post-frame';
162 service_worker_unregister_and_register(t, worker, scope) 134 service_worker_unregister_and_register(t, worker, scope)
163 .then(function(registration) { 135 .then(function(reg) { return wait_for_activated(t, reg); })
164 return wait_for_update(t, registration); 136 .then(function(sw) {
165 })
166 .then(t.step_func(function(sw) {
167 return wait_for_state(t, sw, 'activated');
168 }))
169 .then(t.step_func(function(sw) {
170 return new Promise(function(resolve) { 137 return new Promise(function(resolve) {
171 var frame = document.createElement('iframe'); 138 var frame = document.createElement('iframe');
172 frame.name = frame_name; 139 frame.name = frame_name;
173 document.body.appendChild(frame); 140 document.body.appendChild(frame);
174 var form = document.createElement('form'); 141 var form = document.createElement('form');
175 form.target = frame_name; 142 form.target = frame_name;
176 form.action = scope; 143 form.action = scope;
177 form.method = 'post'; 144 form.method = 'post';
178 var input1 = document.createElement('input'); 145 var input1 = document.createElement('input');
179 input1.type = 'text'; 146 input1.type = 'text';
180 input1.value = 'testValue1'; 147 input1.value = 'testValue1';
181 input1.name = 'testName1' 148 input1.name = 'testName1'
182 form.appendChild(input1); 149 form.appendChild(input1);
183 var input2 = document.createElement('input'); 150 var input2 = document.createElement('input');
184 input2.type = 'text'; 151 input2.type = 'text';
185 input2.value = 'testValue2'; 152 input2.value = 'testValue2';
186 input2.name = 'testName2' 153 input2.name = 'testName2'
187 form.appendChild(input2); 154 form.appendChild(input2);
188 document.body.appendChild(form); 155 document.body.appendChild(form);
189 frame.onload = function() { 156 frame.onload = function() {
190 document.body.removeChild(form); 157 document.body.removeChild(form);
191 resolve(frame); 158 resolve(frame);
192 }; 159 };
193 form.submit(); 160 form.submit();
194 }); 161 });
195 })) 162 })
196 .then(t.step_func(function(frame) { 163 .then(function(frame) {
197 assert_equals(frame.contentDocument.body.textContent, 164 assert_equals(frame.contentDocument.body.textContent,
198 'POST:testName1=testValue1&testName2=testValue2'); 165 'POST:testName1=testValue1&testName2=testValue2');
199 document.body.removeChild(frame); 166 document.body.removeChild(frame);
200 return service_worker_unregister_and_done(t, scope); 167 return service_worker_unregister_and_done(t, scope);
201 })) 168 })
202 .catch(unreached_rejection(t)); 169 .catch(unreached_rejection(t));
203 }, 'Service Worker responds to fetch event with POST form', properties); 170 }, 'Service Worker responds to fetch event with POST form', properties);
204 171
205 async_test(function(t) { 172 async_test(function(t) {
206 var scope = 'resources/simple.html?multiple-respond-with'; 173 var scope = 'resources/simple.html?multiple-respond-with';
207 service_worker_unregister_and_register(t, worker, scope) 174 service_worker_unregister_and_register(t, worker, scope)
208 .then(function(registration) { 175 .then(function(reg) { return wait_for_activated(t, reg); })
209 return wait_for_update(t, registration);
210 })
211 .then(function(sw) { return wait_for_state(t, sw, 'activated'); })
212 .then(function() { return with_iframe(scope); }) 176 .then(function() { return with_iframe(scope); })
213 .then(function(frame) { 177 .then(function(frame) {
214 assert_equals( 178 assert_equals(
215 frame.contentDocument.body.textContent, 179 frame.contentDocument.body.textContent,
216 '(0)', 180 '(0)',
217 'Response should be the argument of the first respondWith() call.'); 181 'Response should be the argument of the first respondWith() call.');
218 unload_iframe(frame); 182 unload_iframe(frame);
219 return with_iframe(scope); 183 return with_iframe(scope);
220 }) 184 })
221 .then(function(frame) { 185 .then(function(frame) {
222 assert_equals( 186 assert_equals(
223 frame.contentDocument.body.textContent, 187 frame.contentDocument.body.textContent,
224 '(0)(1)[InvalidStateError](2)[InvalidStateError](0)', 188 '(0)(1)[InvalidStateError](2)[InvalidStateError](0)',
225 'Multiple calls of respondWith must throw InvalidStateErrors.'); 189 'Multiple calls of respondWith must throw InvalidStateErrors.');
226 unload_iframe(frame); 190 unload_iframe(frame);
227 return service_worker_unregister_and_done(t, scope); 191 return service_worker_unregister_and_done(t, scope);
228 }) 192 })
229 .catch(unreached_rejection(t)); 193 .catch(unreached_rejection(t));
230 }, 'Multiple calls of respondWith must throw InvalidStateErrors', properties); 194 }, 'Multiple calls of respondWith must throw InvalidStateErrors', properties);
231 195
232 </script> 196 </script>
233 </body> 197 </body>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/resources/test-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698