OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: FetchEvent for resources</title> | 2 <title>Service Worker: FetchEvent for resources</title> |
3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
5 <script src="../resources/get-host-info.js?pipe=sub"></script> | 5 <script src="../resources/get-host-info.js?pipe=sub"></script> |
6 <script src="resources/test-helpers.js"></script> | 6 <script src="resources/test-helpers.js"></script> |
7 <script> | 7 <script> |
8 | 8 |
9 function assert_resolves(promise, description) { | 9 function assert_resolves(promise, description) { |
10 return promise.catch(function(reason) { | 10 return promise.catch(function(reason) { |
11 throw new Error(description + ' - ' + reason.message); | 11 throw new Error(description + ' - ' + reason.message); |
12 }); | 12 }); |
13 } | 13 } |
14 | 14 |
15 function assert_rejects(promise, description) { | 15 function assert_rejects(promise, description) { |
16 return promise.then( | 16 return promise.then( |
17 function() { throw new Error(description); }, | 17 function() { throw new Error(description); }, |
18 function() {}); | 18 function() {}); |
19 } | 19 } |
20 | 20 |
21 function iframe_test(url) { | 21 function iframe_test(url, timeout_enabled) { |
22 return new Promise(function(resolve, reject) { | 22 return new Promise(function(resolve, reject) { |
23 var frame = document.createElement('iframe'); | 23 var frame = document.createElement('iframe'); |
24 frame.src = url; | 24 frame.src = url; |
| 25 if (timeout_enabled) { |
| 26 // We can't catch the network error on iframe. So we use the timer for |
| 27 // failure detection. |
| 28 var timer = setTimeout(function() { |
| 29 reject(new Error('iframe load timeout')); |
| 30 frame.remove(); |
| 31 }, 1000); |
| 32 } |
25 frame.onload = function() { | 33 frame.onload = function() { |
| 34 if (timeout_enabled) |
| 35 clearTimeout(timer); |
26 if (frame.contentDocument.body.textContent == 'Hello world\n') | 36 if (frame.contentDocument.body.textContent == 'Hello world\n') |
27 resolve(); | 37 resolve(); |
28 else | 38 else |
29 reject(new Error('content mismatch')); | 39 reject(new Error('content mismatch')); |
30 frame.remove(); | 40 frame.remove(); |
31 }; | 41 }; |
32 document.body.appendChild(frame); | 42 document.body.appendChild(frame); |
33 }); | 43 }); |
34 } | 44 } |
35 | 45 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 'Normal iframe loading should succeed.'), | 149 'Normal iframe loading should succeed.'), |
140 assert_resolves( | 150 assert_resolves( |
141 iframe_test(REDIRECT_TO_HTML_URL), | 151 iframe_test(REDIRECT_TO_HTML_URL), |
142 'Normal redirected iframe loading should succeed.'), | 152 'Normal redirected iframe loading should succeed.'), |
143 assert_resolves( | 153 assert_resolves( |
144 iframe_test(SCOPE + '?url=' + | 154 iframe_test(SCOPE + '?url=' + |
145 encodeURIComponent(REDIRECT_TO_HTML_URL) + | 155 encodeURIComponent(REDIRECT_TO_HTML_URL) + |
146 '&redirect-mode=follow'), | 156 '&redirect-mode=follow'), |
147 'Redirected iframe loading with Request.redirect=follow should'+ | 157 'Redirected iframe loading with Request.redirect=follow should'+ |
148 ' succeed.'), | 158 ' succeed.'), |
149 | |
150 /* | |
151 TODO(horo): iframe load failure detection is unreliable. | |
152 Rework these. crbug.com/522587 | |
153 assert_rejects( | 159 assert_rejects( |
154 iframe_test(SCOPE + '?url=' + | 160 iframe_test(SCOPE + '?url=' + |
155 encodeURIComponent(REDIRECT_TO_HTML_URL) + | 161 encodeURIComponent(REDIRECT_TO_HTML_URL) + |
156 '&redirect-mode=error'), | 162 '&redirect-mode=error', |
| 163 true /* timeout_enabled */), |
157 'Redirected iframe loading with Request.redirect=error should '+ | 164 'Redirected iframe loading with Request.redirect=error should '+ |
158 'fail.'), | 165 'fail.'), |
159 assert_resolves( | 166 assert_resolves( |
160 iframe_test(SCOPE + '?url=' + | 167 iframe_test(SCOPE + '?url=' + |
161 encodeURIComponent(REDIRECT_TO_HTML_URL) + | 168 encodeURIComponent(REDIRECT_TO_HTML_URL) + |
162 '&redirect-mode=manual'), | 169 '&redirect-mode=manual', |
| 170 true /* timeout_enabled */), |
163 'Redirected iframe loading with Request.redirect=manual should'+ | 171 'Redirected iframe loading with Request.redirect=manual should'+ |
164 ' succeed.'), | 172 ' succeed.'), |
165 */ | |
166 ]); | 173 ]); |
167 }) | 174 }) |
168 .then(function() { | 175 .then(function() { |
169 frame.remove(); | 176 frame.remove(); |
170 service_worker_unregister_and_done(t, SCOPE); | 177 service_worker_unregister_and_done(t, SCOPE); |
171 }); | 178 }); |
172 }, 'Verify redirect mode of Fetch API and ServiceWorker FetchEvent.'); | 179 }, 'Verify redirect mode of Fetch API and ServiceWorker FetchEvent.'); |
173 </script> | 180 </script> |
OLD | NEW |