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 var url_count = 0; | 8 var url_count = 0; |
9 var expected_results = {}; | 9 var expected_results = {}; |
10 | 10 |
11 function image_test(frame, url, cross_origin, | 11 function image_test(frame, url, cross_origin, |
12 expected_mode, expected_credentials) { | 12 expected_mode, expected_credentials) { |
13 var actual_url = url + (++url_count); | 13 var actual_url = url + (++url_count); |
14 expected_results[actual_url] = { | 14 expected_results[actual_url] = { |
15 cross_origin: cross_origin, | |
16 mode: expected_mode, | 15 mode: expected_mode, |
17 credentials: expected_credentials, | 16 credentials: expected_credentials, |
18 redirect: 'follow', | 17 redirect: 'follow', |
19 message: 'Image load (url:' + | 18 message: 'Image load (url:' + |
20 actual_url + ' cross_origin:' + cross_origin + ')' | 19 actual_url + ' cross_origin:' + cross_origin + ')' |
21 }; | 20 }; |
22 return frame.contentWindow.load_image(actual_url, cross_origin); | 21 return frame.contentWindow.load_image(actual_url, cross_origin); |
23 } | 22 } |
24 | 23 |
25 function script_test(frame, url, cross_origin, | 24 function script_test(frame, url, cross_origin, |
26 expected_mode, expected_credentials) { | 25 expected_mode, expected_credentials) { |
27 var actual_url = url + (++url_count); | 26 var actual_url = url + (++url_count); |
28 expected_results[actual_url] = { | 27 expected_results[actual_url] = { |
29 cross_origin: cross_origin, | |
30 mode: expected_mode, | 28 mode: expected_mode, |
31 credentials: expected_credentials, | 29 credentials: expected_credentials, |
32 redirect: 'follow', | 30 redirect: 'follow', |
33 message: 'Script load (url:' + | 31 message: 'Script load (url:' + |
34 actual_url + ' cross_origin:' + cross_origin + ')' | 32 actual_url + ' cross_origin:' + cross_origin + ')' |
35 }; | 33 }; |
36 return frame.contentWindow.load_script(actual_url, cross_origin); | 34 return frame.contentWindow.load_script(actual_url, cross_origin); |
37 } | 35 } |
38 | 36 |
39 function css_test(frame, url, cross_origin, | 37 function css_test(frame, url, cross_origin, |
40 expected_mode, expected_credentials) { | 38 expected_mode, expected_credentials) { |
41 var actual_url = url + (++url_count); | 39 var actual_url = url + (++url_count); |
42 expected_results[actual_url] = { | 40 expected_results[actual_url] = { |
43 cross_origin: cross_origin, | |
44 mode: expected_mode, | 41 mode: expected_mode, |
45 credentials: expected_credentials, | 42 credentials: expected_credentials, |
46 redirect: 'follow', | 43 redirect: 'follow', |
47 message: 'CSS load (url:' + | 44 message: 'CSS load (url:' + |
48 actual_url + ' cross_origin:' + cross_origin + ')' | 45 actual_url + ' cross_origin:' + cross_origin + ')' |
49 }; | 46 }; |
50 return frame.contentWindow.load_css(actual_url, cross_origin); | 47 return frame.contentWindow.load_css(actual_url, cross_origin); |
51 } | 48 } |
52 | 49 |
53 function font_face_test(frame, url, expected_mode, | 50 function font_face_test(frame, url, expected_mode, |
(...skipping 28 matching lines...) Expand all Loading... |
82 expected_results[actual_url] = { | 79 expected_results[actual_url] = { |
83 url: actual_url, | 80 url: actual_url, |
84 mode: expected_mode, | 81 mode: expected_mode, |
85 credentials: expected_credentials, | 82 credentials: expected_credentials, |
86 redirect: 'follow', | 83 redirect: 'follow', |
87 message: 'CSSImageSet load (url:' + actual_url + ' type:' + type + ')' | 84 message: 'CSSImageSet load (url:' + actual_url + ' type:' + type + ')' |
88 }; | 85 }; |
89 return frame.contentWindow.load_css_image_set(actual_url, type); | 86 return frame.contentWindow.load_css_image_set(actual_url, type); |
90 } | 87 } |
91 | 88 |
| 89 function fetch_test(frame, url, mode, credentials, |
| 90 expected_mode, expected_credentials) { |
| 91 var actual_url = url + (++url_count); |
| 92 expected_results[actual_url] = { |
| 93 mode: expected_mode, |
| 94 credentials: expected_credentials, |
| 95 redirect: 'follow', |
| 96 message: 'fetch (url:' + actual_url + ' mode:' + mode + ' credentials:' + |
| 97 credentials + ')' |
| 98 }; |
| 99 return frame.contentWindow.fetch( |
| 100 new Request(actual_url, {mode: mode, credentials: credentials})); |
| 101 } |
| 102 |
| 103 function audio_test(frame, url, cross_origin, |
| 104 expected_mode, expected_credentials) { |
| 105 var actual_url = url + (++url_count); |
| 106 expected_results[actual_url] = { |
| 107 mode: expected_mode, |
| 108 credentials: expected_credentials, |
| 109 redirect: 'follow', |
| 110 message: 'Audio load (url:' + actual_url + ' cross_origin:' + |
| 111 cross_origin + ')' |
| 112 }; |
| 113 return frame.contentWindow.load_audio(actual_url, cross_origin); |
| 114 } |
| 115 |
92 async_test(function(t) { | 116 async_test(function(t) { |
93 var SCOPE = 'resources/fetch-request-resources-iframe.html'; | 117 var SCOPE = 'resources/fetch-request-resources-iframe.html'; |
94 var SCRIPT = 'resources/fetch-request-resources-worker.js'; | 118 var SCRIPT = 'resources/fetch-request-resources-worker.js'; |
95 var host_info = get_host_info(); | 119 var host_info = get_host_info(); |
96 var LOCAL_URL = | 120 var LOCAL_URL = |
97 host_info['HTTP_ORIGIN'] + base_path() + 'resources/dummy?test'; | 121 host_info['HTTP_ORIGIN'] + base_path() + 'resources/dummy?test'; |
98 var REMOTE_URL = | 122 var REMOTE_URL = |
99 host_info['HTTP_REMOTE_ORIGIN'] + base_path() + 'resources/dummy?test'; | 123 host_info['HTTP_REMOTE_ORIGIN'] + base_path() + 'resources/dummy?test'; |
100 var worker; | 124 var worker; |
101 var frame; | 125 var frame; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 service_worker_unregister_and_done(t, SCOPE); | 160 service_worker_unregister_and_done(t, SCOPE); |
137 } | 161 } |
138 }); | 162 }); |
139 worker.postMessage( | 163 worker.postMessage( |
140 {port: channel.port2}, [channel.port2]); | 164 {port: channel.port2}, [channel.port2]); |
141 }); | 165 }); |
142 }) | 166 }) |
143 .then(function() { return with_iframe(SCOPE); }) | 167 .then(function() { return with_iframe(SCOPE); }) |
144 .then(function(f) { | 168 .then(function(f) { |
145 frame = f; | 169 frame = f; |
146 image_test(f, LOCAL_URL, '', 'no-cors', 'same-origin'); | 170 image_test(f, LOCAL_URL, '', 'no-cors', 'include'); |
147 image_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); | 171 image_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); |
148 image_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); | 172 image_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); |
149 image_test(f, REMOTE_URL, '', 'no-cors', 'same-origin'); | 173 image_test(f, REMOTE_URL, '', 'no-cors', 'include'); |
150 image_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); | 174 image_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); |
151 image_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); | 175 image_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); |
152 | 176 |
153 script_test(f, LOCAL_URL, '', 'no-cors', 'same-origin'); | 177 script_test(f, LOCAL_URL, '', 'no-cors', 'include'); |
154 script_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); | 178 script_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); |
155 script_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); | 179 script_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); |
156 script_test(f, REMOTE_URL, '', 'no-cors', 'same-origin'); | 180 script_test(f, REMOTE_URL, '', 'no-cors', 'include'); |
157 script_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); | 181 script_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); |
158 script_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); | 182 script_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); |
159 | 183 |
160 css_test(f, LOCAL_URL, '', 'no-cors', 'same-origin'); | 184 css_test(f, LOCAL_URL, '', 'no-cors', 'include'); |
161 css_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); | 185 css_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); |
162 css_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); | 186 css_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); |
163 css_test(f, REMOTE_URL, '', 'no-cors', 'same-origin'); | 187 css_test(f, REMOTE_URL, '', 'no-cors', 'include'); |
164 css_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); | 188 css_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); |
165 css_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); | 189 css_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); |
166 | 190 |
167 font_face_test(f, LOCAL_URL, 'cors', 'same-origin'); | 191 font_face_test(f, LOCAL_URL, 'cors', 'same-origin'); |
168 font_face_test(f, REMOTE_URL, 'cors', 'same-origin'); | 192 font_face_test(f, REMOTE_URL, 'cors', 'same-origin'); |
169 | 193 |
170 css_image_test(f, LOCAL_URL, 'backgroundImage', | 194 css_image_test(f, LOCAL_URL, 'backgroundImage', 'no-cors', 'include'); |
171 'no-cors', 'same-origin'); | 195 css_image_test(f, REMOTE_URL, 'backgroundImage', 'no-cors', 'include'); |
172 css_image_test(f, REMOTE_URL, 'backgroundImage', | |
173 'no-cors', 'same-origin'); | |
174 css_image_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'same-origin'); | 196 css_image_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'same-origin'); |
175 css_image_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'same-origin'); | 197 css_image_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'same-origin'); |
176 | 198 |
177 css_image_set_test(f, LOCAL_URL, 'backgroundImage', | 199 css_image_set_test(f, LOCAL_URL, 'backgroundImage', |
178 'no-cors', 'same-origin'); | 200 'no-cors', 'include'); |
179 css_image_set_test(f, REMOTE_URL, 'backgroundImage', | 201 css_image_set_test(f, REMOTE_URL, 'backgroundImage', |
180 'no-cors', 'same-origin'); | 202 'no-cors', 'include'); |
181 css_image_set_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'same-origin'); | 203 css_image_set_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'same-origin'); |
182 css_image_set_test(f, REMOTE_URL, 'shapeOutside', | 204 css_image_set_test(f, REMOTE_URL, 'shapeOutside', |
183 'cors', 'same-origin'); | 205 'cors', 'same-origin'); |
184 | 206 |
| 207 fetch_test(f, LOCAL_URL, 'same-origin', 'omit', 'same-origin', 'omit'); |
| 208 fetch_test(f, LOCAL_URL, 'same-origin', 'same-origin', |
| 209 'same-origin', 'same-origin'); |
| 210 fetch_test(f, LOCAL_URL, 'same-origin', 'include', |
| 211 'same-origin', 'include'); |
| 212 fetch_test(f, LOCAL_URL, 'no-cors', 'omit', 'no-cors', 'omit'); |
| 213 fetch_test(f, LOCAL_URL, 'no-cors', 'same-origin', |
| 214 'no-cors', 'same-origin'); |
| 215 fetch_test(f, LOCAL_URL, 'no-cors', 'include', 'no-cors', 'include'); |
| 216 fetch_test(f, LOCAL_URL, 'cors', 'omit', 'cors', 'omit'); |
| 217 fetch_test(f, LOCAL_URL, 'cors', 'same-origin', 'cors', 'same-origin'); |
| 218 fetch_test(f, LOCAL_URL, 'cors', 'include', 'cors', 'include'); |
| 219 fetch_test(f, REMOTE_URL, 'no-cors', 'omit', 'no-cors', 'omit'); |
| 220 fetch_test(f, REMOTE_URL, 'no-cors', 'same-origin', |
| 221 'no-cors', 'same-origin'); |
| 222 fetch_test(f, REMOTE_URL, 'no-cors', 'include', 'no-cors', 'include'); |
| 223 fetch_test(f, REMOTE_URL, 'cors', 'omit', 'cors', 'omit'); |
| 224 fetch_test(f, REMOTE_URL, 'cors', 'same-origin', 'cors', 'same-origin'); |
| 225 fetch_test(f, REMOTE_URL, 'cors', 'include', 'cors', 'include'); |
| 226 |
| 227 audio_test(f, LOCAL_URL, '', 'no-cors', 'include'); |
| 228 audio_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin'); |
| 229 audio_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include'); |
| 230 audio_test(f, REMOTE_URL, '', 'no-cors', 'include'); |
| 231 audio_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin'); |
| 232 audio_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include'); |
185 }) | 233 }) |
186 .catch(unreached_rejection(t)); | 234 .catch(unreached_rejection(t)); |
187 }, 'Verify FetchEvent for resources.'); | 235 }, 'Verify FetchEvent for resources.'); |
188 </script> | 236 </script> |
OLD | NEW |