OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Navigation redirection</title> | 2 <title>Service Worker: Navigation redirection</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 <body> | 7 <body> |
8 <script> | 8 <script> |
9 | |
10 var host_info = get_host_info(); | |
11 | |
12 // This test registers three Service Workers at SCOPE1, SCOPE2 and | |
13 // OTHER_ORIGIN_SCOPE. And checks the redirected page's URL and the requests | |
14 // which are intercepted by Service Worker while loading redirect page. | |
15 var BASE_URL = host_info['HTTP_ORIGIN'] + base_path(); | |
16 var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] + base_path(); | |
17 | |
18 var SCOPE1 = BASE_URL + 'resources/navigation-redirect-scope1.php?'; | |
19 var SCOPE2 = BASE_URL + 'resources/navigation-redirect-scope2.php?'; | |
20 var OUT_SCOPE = BASE_URL + 'resources/navigation-redirect-out-scope.php?'; | |
21 var SCRIPT = 'resources/navigation-redirect-worker.js'; | |
22 | |
23 var OTHER_ORIGIN_IFRAME_URL = | |
24 OTHER_BASE_URL + 'resources/navigation-redirect-other-origin.html'; | |
25 var OTHER_ORIGIN_SCOPE = | |
26 OTHER_BASE_URL + 'resources/navigation-redirect-scope1.php?'; | |
27 var OTHER_ORIGIN_OUT_SCOPE = | |
28 OTHER_BASE_URL + 'resources/navigation-redirect-out-scope.php?'; | |
29 | |
30 var workers; | |
31 var other_origin_frame; | |
32 var setup_environment_promise; | |
33 | |
34 function setup_environment(t) { | |
35 if (setup_environment_promise) | |
36 return setup_environment_promise; | |
37 setup_environment_promise = | |
38 with_iframe(OTHER_ORIGIN_IFRAME_URL) | |
39 .then(function(f) { | |
40 // In this frame we register a Service Worker at OTHER_ORIGIN_SCOPE. | |
41 // And will use this frame to communicate with the worker. | |
42 other_origin_frame = f; | |
43 return Promise.all( | |
44 [service_worker_unregister_and_register(t, SCRIPT, SCOPE1), | |
45 service_worker_unregister_and_register(t, SCRIPT, SCOPE2)]); | |
46 }) | |
47 .then(function(registrations) { | |
48 add_completion_callback(function() { | |
falken
2015/08/26 07:25:48
ahh.. that's a handy function
| |
49 registrations[0].unregister(); | |
50 registrations[1].unregister(); | |
51 send_to_iframe(other_origin_frame, 'unregister') | |
52 .then(function() { other_origin_frame.remove(); }); | |
53 }); | |
54 workers = registrations.map(get_effective_worker); | |
55 return Promise.all([ | |
56 wait_for_state(t, workers[0], 'activated'), | |
57 wait_for_state(t, workers[1], 'activated'), | |
58 // This promise will resolve when |wait_for_worker_promise| | |
59 // in OTHER_ORIGIN_IFRAME_URL resolves. | |
60 send_to_iframe(other_origin_frame, "wait_for_worker")]); | |
falken
2015/08/26 07:25:48
single quotes
horo
2015/08/28 07:05:41
Done.
| |
61 }); | |
62 return setup_environment_promise; | |
63 } | |
64 | |
9 function get_effective_worker(registration) { | 65 function get_effective_worker(registration) { |
10 if (registration.active) | 66 if (registration.active) |
11 return registration.active; | 67 return registration.active; |
12 if (registration.waiting) | 68 if (registration.waiting) |
13 return registration.waiting; | 69 return registration.waiting; |
14 if (registration.installing) | 70 if (registration.installing) |
15 return registration.installing; | 71 return registration.installing; |
16 } | 72 } |
17 | 73 |
18 var host_info = get_host_info(); | 74 function check_all_intercepted_urls(expected_urls) { |
75 return Promise.all([ | |
76 // Gets the request URLs which are intercepted by SCOPE1's SW. | |
77 get_intercepted_urls(workers[0]), | |
78 // Gets the request URLs which are intercepted by SCOPE2's SW. | |
79 get_intercepted_urls(workers[1]), | |
80 // Gets the request URLs which are intercepted by OTHER_ORIGIN_SCOPE's | |
81 // SW. This promise will resolve when get_intercepted_urls() in | |
82 // OTHER_ORIGIN_IFRAME_URL resolves. | |
83 send_to_iframe(other_origin_frame, 'get_intercepted_urls')]) | |
84 .then(function(urls) { | |
falken
2015/08/26 07:25:48
indent looks wrong
horo
2015/08/28 07:05:41
Changed the position of brackets.
| |
85 assert_object_equals( | |
86 urls, expected_urls, | |
87 'Intercepted URLs should match.'); | |
88 }); | |
89 } | |
90 | |
91 function test_redirect(url, expected_last_url, | |
92 expected_intercepted_urls) { | |
93 var message_promise = new Promise(function(resolve) { | |
94 // A message which ID is 'last_url' will be sent from the iframe. | |
95 message_resolvers['last_url'] = resolve; | |
falken
2015/08/26 07:25:48
maybe message_resolvers and the other globals shou
horo
2015/08/28 07:05:40
Done.
| |
96 }); | |
97 return with_iframe(url) | |
98 .then(function(f) { | |
99 f.remove(); | |
100 return check_all_intercepted_urls(expected_intercepted_urls); | |
101 }) | |
102 .then(function() { return message_promise; }) | |
103 .then(function(last_url) { | |
104 assert_equals( | |
105 last_url, expected_last_url, | |
106 'Last URL should match.'); | |
107 }); | |
108 } | |
19 | 109 |
20 window.addEventListener('message', on_message, false); | 110 window.addEventListener('message', on_message, false); |
21 | 111 |
22 var message_resolvers = {}; | 112 var message_resolvers = {}; |
23 var next_message_id = 0; | 113 var next_message_id = 0; |
24 | 114 |
25 function on_message(e) { | 115 function on_message(e) { |
26 if (e.origin != host_info['HTTP_REMOTE_ORIGIN'] && | 116 if (e.origin != host_info['HTTP_REMOTE_ORIGIN'] && |
27 e.origin != host_info['HTTP_ORIGIN'] ) { | 117 e.origin != host_info['HTTP_ORIGIN'] ) { |
28 console.error('invalid origin: ' + e.origin); | 118 console.error('invalid origin: ' + e.origin); |
(...skipping 15 matching lines...) Expand all Loading... | |
44 } | 134 } |
45 | 135 |
46 function get_intercepted_urls(worker) { | 136 function get_intercepted_urls(worker) { |
47 return new Promise(function(resolve) { | 137 return new Promise(function(resolve) { |
48 var channel = new MessageChannel(); | 138 var channel = new MessageChannel(); |
49 channel.port1.onmessage = function(msg) { resolve(msg.data.urls); }; | 139 channel.port1.onmessage = function(msg) { resolve(msg.data.urls); }; |
50 worker.postMessage({port: channel.port2}, [channel.port2]); | 140 worker.postMessage({port: channel.port2}, [channel.port2]); |
51 }); | 141 }); |
52 } | 142 } |
53 | 143 |
54 async_test(function(t) { | 144 // Normal redirect. |
55 // This test registers three Service Workers at SCOPE1, SCOPE2 and | 145 promise_test(function(t) { |
56 // OTHER_ORIGIN_SCOPE. And checks the redirected page's URL and the requests | 146 return setup_environment(t).then(function() { |
57 // which are intercepted by Service Worker while loading redirect page. | 147 return test_redirect( |
58 var BASE_URL = host_info['HTTP_ORIGIN'] + base_path(); | 148 OUT_SCOPE + "url=" + encodeURIComponent(SCOPE1), |
falken
2015/08/26 07:25:48
double quotes should be single quotes here and thr
horo
2015/08/28 07:05:41
Done.
| |
59 var OTHER_BASE_URL = host_info['HTTP_REMOTE_ORIGIN'] + base_path(); | 149 SCOPE1, |
60 | 150 [[SCOPE1], [], []]); |
61 var SCOPE1 = BASE_URL + 'resources/navigation-redirect-scope1.php?'; | 151 }); |
62 var SCOPE2 = BASE_URL + 'resources/navigation-redirect-scope2.php?'; | 152 }, 'Normal redirect to same-origin scope.'); |
63 var OUT_SCOPE = BASE_URL + 'resources/navigation-redirect-out-scope.php?'; | 153 promise_test(function(t) { |
64 var SCRIPT = 'resources/navigation-redirect-worker.js'; | 154 return setup_environment(t).then(function() { |
65 | 155 return test_redirect( |
66 var OTHER_ORIGIN_IFRAME_URL = | 156 OUT_SCOPE + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
67 OTHER_BASE_URL + 'resources/navigation-redirect-other-origin.html'; | 157 OTHER_ORIGIN_SCOPE, |
68 var OTHER_ORIGIN_SCOPE = | 158 [[], [], [OTHER_ORIGIN_SCOPE]]); |
69 OTHER_BASE_URL + 'resources/navigation-redirect-scope1.php?'; | 159 }); |
70 var OTHER_ORIGIN_OUT_SCOPE = | 160 }, 'Normal redirect to other-origin scope.'); |
71 OTHER_BASE_URL + 'resources/navigation-redirect-out-scope.php?'; | 161 |
72 | 162 // SW fallbacked redirect. SW doesn't handle the fetch request. |
73 var workers; | 163 promise_test(function(t) { |
74 var other_origin_frame; | 164 return setup_environment(t).then(function() { |
75 | 165 return test_redirect( |
76 function check_all_intercepted_urls(expected_urls, description) { | 166 SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE), |
77 return Promise.all([ | 167 OUT_SCOPE, |
78 // Gets the request URLs which are intercepted by SCOPE1's SW. | 168 [[SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE)], [], []]); |
79 get_intercepted_urls(workers[0]), | 169 }); |
80 // Gets the request URLs which are intercepted by SCOPE2's SW. | 170 }, 'SW-fallbacked redirect to same-origin out-scope.'); |
81 get_intercepted_urls(workers[1]), | 171 promise_test(function(t) { |
82 // Gets the request URLs which are intercepted by OTHER_ORIGIN_SCOPE's | 172 return setup_environment(t).then(function() { |
83 // SW. This promise will resolve when get_intercepted_urls() in | 173 return test_redirect( |
84 // OTHER_ORIGIN_IFRAME_URL resolves. | 174 SCOPE1 + "url=" + encodeURIComponent(SCOPE1), |
85 send_to_iframe(other_origin_frame, 'get_intercepted_urls')]) | 175 SCOPE1, |
86 .then(function(urls) { | 176 [[SCOPE1 + "url=" + encodeURIComponent(SCOPE1), SCOPE1], [], []]); |
87 assert_object_equals( | 177 }); |
88 urls, expected_urls, | 178 }, 'SW-fallbacked redirect to same-origin same-scope.'); |
89 'Intercepted URLs should match: ' + description); | 179 promise_test(function(t) { |
90 }); | 180 return setup_environment(t).then(function() { |
91 } | 181 return test_redirect( |
92 | 182 SCOPE1 + "url=" + encodeURIComponent(SCOPE2), |
93 function test_redirect(url, expected_last_url, | 183 SCOPE2, |
94 expected_intercepted_urls, description) { | 184 [[SCOPE1 + "url=" + encodeURIComponent(SCOPE2)], [SCOPE2], []]); |
95 var message_promise = new Promise(function(resolve) { | 185 }); |
96 // A message which ID is 'last_url' will be sent from the iframe. | 186 }, 'SW-fallbacked redirect to same-origin other-scope.'); |
97 message_resolvers['last_url'] = resolve; | 187 promise_test(function(t) { |
98 }); | 188 return setup_environment(t).then(function() { |
99 return with_iframe(url) | 189 return test_redirect( |
100 .then(function(f) { | 190 SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
101 f.remove(); | 191 OTHER_ORIGIN_OUT_SCOPE, |
102 return check_all_intercepted_urls(expected_intercepted_urls, | 192 [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
103 description); | 193 [], |
104 }) | 194 []]); |
105 .then(function() { return message_promise; }) | 195 }); |
106 .then(function(last_url) { | 196 }, 'SW-fallbacked redirect to other-origin out-scope.'); |
107 assert_equals( | 197 promise_test(function(t) { |
108 last_url, expected_last_url, | 198 return setup_environment(t).then(function() { |
109 'Last URL should match: ' + description); | 199 return test_redirect( |
110 }); | 200 SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
111 } | 201 OTHER_ORIGIN_SCOPE, |
112 | 202 [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
113 with_iframe(OTHER_ORIGIN_IFRAME_URL) | 203 [], |
114 .then(function(f) { | 204 [OTHER_ORIGIN_SCOPE]]); |
115 // In this frame we register a Service Worker at OTHER_ORIGIN_SCOPE. | 205 }); |
116 // And will use this frame to communicate with the worker. | 206 }, 'SW-fallbacked redirect to other-origin in-scope.'); |
117 other_origin_frame = f; | 207 |
118 return Promise.all( | 208 // SW generated redirect. |
119 [service_worker_unregister_and_register(t, SCRIPT, SCOPE1), | 209 // SW: event.respondWith(Response.redirect(params['url'])); |
120 service_worker_unregister_and_register(t, SCRIPT, SCOPE2)]); | 210 promise_test(function(t) { |
121 }) | 211 return setup_environment(t).then(function() { |
122 .then(function(registrations) { | 212 return test_redirect( |
123 workers = registrations.map(get_effective_worker); | 213 SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE), |
124 return Promise.all([ | 214 OUT_SCOPE, |
125 wait_for_state(t, workers[0], 'activated'), | 215 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE)], [], []]); |
126 wait_for_state(t, workers[1], 'activated'), | 216 }); |
127 // This promise will resolve when |wait_for_worker_promise| | 217 }, 'SW-generated redirect to same-origin out-scope.'); |
128 // in OTHER_ORIGIN_IFRAME_URL resolves. | 218 promise_test(function(t) { |
129 send_to_iframe(other_origin_frame, "wait_for_worker")]); | 219 return setup_environment(t).then(function() { |
130 }) | 220 return test_redirect( |
131 // Normal redirect. | 221 SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), |
132 .then(function() { | 222 SCOPE1, |
133 return test_redirect( | 223 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), SCOPE1], |
134 OUT_SCOPE + "url=" + encodeURIComponent(SCOPE1), | 224 [], |
135 SCOPE1, | 225 []]); |
136 [[SCOPE1], [], []], | 226 }); |
137 'Normal redirect to same-origin scope.'); | 227 }, 'SW-generated redirect to same-origin same-scope.'); |
138 }) | 228 promise_test(function(t) { |
139 .then(function() { | 229 return setup_environment(t).then(function() { |
140 return test_redirect( | 230 return test_redirect( |
141 OUT_SCOPE + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), | 231 SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2), |
142 OTHER_ORIGIN_SCOPE, | 232 SCOPE2, |
143 [[], [], [OTHER_ORIGIN_SCOPE]], | 233 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2)], |
144 'Normal redirect to other-origin scope.'); | 234 [SCOPE2], |
145 }) | 235 []]); |
146 | 236 }); |
147 // SW fallbacked redirect. SW doesn't handle the fetch request. | 237 }, 'SW-generated redirect to same-origin other-scope.'); |
148 .then(function() { | 238 promise_test(function(t) { |
149 return test_redirect( | 239 return setup_environment(t).then(function() { |
150 SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE), | 240 return test_redirect( |
151 OUT_SCOPE, | 241 SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
152 [[SCOPE1 + "url=" + encodeURIComponent(OUT_SCOPE)], | 242 OTHER_ORIGIN_OUT_SCOPE, |
153 [], | 243 [[SCOPE1 + "sw=gen&url=" + |
154 []], | 244 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
155 'SW-fallbacked redirect to same-origin out-scope.'); | 245 [], |
156 }) | 246 []]); |
157 .then(function() { | 247 }); |
158 return test_redirect( | 248 }, 'SW-generated redirect to other-origin out-scope.'); |
159 SCOPE1 + "url=" + encodeURIComponent(SCOPE1), | 249 promise_test(function(t) { |
160 SCOPE1, | 250 return setup_environment(t).then(function() { |
161 [[SCOPE1 + "url=" + encodeURIComponent(SCOPE1), SCOPE1], | 251 return test_redirect( |
162 [], | 252 SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
163 []], | 253 OTHER_ORIGIN_SCOPE, |
164 'SW-fallbacked redirect to same-origin same-scope.'); | 254 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
165 }) | 255 [], |
166 .then(function() { | 256 [OTHER_ORIGIN_SCOPE]]); |
167 return test_redirect( | 257 }); |
168 SCOPE1 + "url=" + encodeURIComponent(SCOPE2), | 258 }, 'SW-generated redirect to other-origin in-scope.'); |
169 SCOPE2, | 259 |
170 [[SCOPE1 + "url=" + encodeURIComponent(SCOPE2)], | 260 // SW fetched redirect. |
171 [SCOPE2], | 261 // SW: event.respondWith(fetch(event.request)); |
172 []], | 262 // TODO(horo): When we change Request.redirect of navigation requests to |
173 'SW-fallbacked redirect to same-origin other-scope.'); | 263 // 'manual', the expected last URL shuold be changed. (crbug.com/510650) |
174 }) | 264 // Spec Issue: https://github.com/whatwg/fetch/issues/106 |
175 .then(function() { | 265 promise_test(function(t) { |
176 return test_redirect( | 266 return setup_environment(t).then(function() { |
177 SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), | 267 return test_redirect( |
178 OTHER_ORIGIN_OUT_SCOPE, | 268 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), |
179 [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], | 269 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), |
180 [], | 270 [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE)], |
181 []], | 271 [], |
182 'SW-fallbacked redirect to other-origin out-scope.'); | 272 []]); |
183 }) | 273 }); |
184 .then(function() { | 274 }, 'SW-fetched redirect to same-origin out-scope.'); |
185 return test_redirect( | 275 promise_test(function(t) { |
186 SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), | 276 return setup_environment(t).then(function() { |
187 OTHER_ORIGIN_SCOPE, | 277 return test_redirect( |
188 [[SCOPE1 + "url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE)], | 278 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), |
189 [], | 279 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), |
190 [OTHER_ORIGIN_SCOPE]], | 280 [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1)], [], []]); |
191 'SW-fallbacked redirect to other-origin in-scope.'); | 281 }); |
192 }) | 282 }, 'SW-fetched redirect to same-origin same-scope.'); |
193 | 283 promise_test(function(t) { |
194 // SW generated redirect. | 284 return setup_environment(t).then(function() { |
195 // SW: event.respondWith(Response.redirect(params['url'])); | 285 return test_redirect( |
196 .then(function() { | 286 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), |
197 return test_redirect( | 287 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), |
198 SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE), | 288 [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2)], [], []]); |
199 OUT_SCOPE, | 289 }); |
200 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(OUT_SCOPE)], | 290 }, 'SW fetched redirect to same-origin other-scope.'); |
201 [], | 291 |
202 []], | 292 // Opaque redirect. |
203 'SW-generated redirect to same-origin out-scope.'); | 293 // SW: event.respondWith(fetch( |
204 }) | 294 // new Request(event.request.url, {redirect: 'manual'}))); |
205 .then(function() { | 295 promise_test(function(t) { |
206 return test_redirect( | 296 return setup_environment(t).then(function() { |
207 SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), | 297 return test_redirect( |
208 SCOPE1, | 298 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE), |
209 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE1), SCOPE1], | 299 OUT_SCOPE, |
210 [], | 300 [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE)], |
211 []], | 301 [], |
212 'SW-generated redirect to same-origin same-scope.'); | 302 []]); |
213 }) | 303 }); |
214 .then(function() { | 304 }, 'Redirect to same-origin out-scope with opaque redirect response.'); |
215 return test_redirect( | 305 promise_test(function(t) { |
216 SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2), | 306 return setup_environment(t).then(function() { |
217 SCOPE2, | 307 return test_redirect( |
218 [[SCOPE1 + "sw=gen&url=" + encodeURIComponent(SCOPE2)], | 308 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), |
219 [SCOPE2], | 309 SCOPE1, |
220 []], | 310 [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), SCOPE1], |
221 'SW-generated redirect to same-origin other-scope.'); | 311 [], |
222 }) | 312 []]); |
223 .then(function() { | 313 }); |
224 return test_redirect( | 314 }, 'Redirect to same-origin same-scope with opaque redirect response.'); |
225 SCOPE1 + "sw=gen&url=" + | 315 promise_test(function(t) { |
226 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), | 316 return setup_environment(t).then(function() { |
227 OTHER_ORIGIN_OUT_SCOPE, | 317 return test_redirect( |
228 [[SCOPE1 + "sw=gen&url=" + | 318 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2), |
229 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], | 319 SCOPE2, |
230 [], | 320 [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2)], |
231 []], | 321 [SCOPE2], |
232 'SW-generated redirect to other-origin out-scope.'); | 322 []]); |
233 }) | 323 }); |
234 .then(function() { | 324 }, 'Redirect to same-origin other-scope with opaque redirect response.'); |
235 return test_redirect( | 325 promise_test(function(t) { |
236 SCOPE1 + "sw=gen&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), | 326 return setup_environment(t).then(function() { |
237 OTHER_ORIGIN_SCOPE, | 327 return test_redirect( |
238 [[SCOPE1 + "sw=gen&url=" + | 328 SCOPE1 + "sw=opaque&url=" + |
239 encodeURIComponent(OTHER_ORIGIN_SCOPE)], | 329 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
240 [], | 330 OTHER_ORIGIN_OUT_SCOPE, |
241 [OTHER_ORIGIN_SCOPE]], | 331 [[SCOPE1 + "sw=opaque&url=" + |
242 'SW-generated redirect to other-origin in-scope.'); | 332 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
243 }) | 333 [], |
244 | 334 []]); |
245 // SW fetched redirect. | 335 }); |
246 // SW: event.respondWith(fetch(event.request)); | 336 }, 'Redirect to other-origin out-scope with opaque redirect response.'); |
247 // TODO(horo): When we change Request.redirect of navigation requests to | 337 promise_test(function(t) { |
248 // 'manual', the expected last URL shuold be changed. (crbug.com/510650) | 338 return setup_environment(t).then(function() { |
249 // Spec Issue: https://github.com/whatwg/fetch/issues/106 | 339 return test_redirect( |
250 .then(function() { | 340 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OTHER_ORIGIN_SCOPE), |
251 return test_redirect( | 341 OTHER_ORIGIN_SCOPE, |
252 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), | 342 [[SCOPE1 + "sw=opaque&url=" + |
253 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE), | 343 encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
254 [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(OUT_SCOPE)], | 344 [], |
255 [], | 345 [OTHER_ORIGIN_SCOPE]]); |
256 []], | 346 }); |
257 'SW-fetched redirect to same-origin out-scope.'); | 347 }, 'Redirect to other-origin in-scope with opaque redirect response.'); |
258 }) | 348 |
259 .then(function() { | 349 // Opaque redirect passed through Cache. |
260 return test_redirect( | 350 // SW responds with an opaque redirectresponse from the Cache API. |
261 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), | 351 promise_test(function(t) { |
262 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1), | 352 return setup_environment(t).then(function() { |
263 [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE1)], | 353 return test_redirect( |
264 [], | 354 SCOPE1 + "sw=opaqueThroughCache&url=" + |
265 []], | 355 encodeURIComponent(OUT_SCOPE), |
266 'SW-fetched redirect to same-origin same-scope.'); | 356 OUT_SCOPE, |
267 }) | 357 [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
268 .then(function() { | 358 encodeURIComponent(OUT_SCOPE)], |
269 return test_redirect( | 359 [], |
270 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), | 360 []]); |
271 SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2), | 361 }); |
272 [[SCOPE1 + "sw=fetch&url=" + encodeURIComponent(SCOPE2)], | 362 }, |
273 [], | 363 'Redirect to same-origin out-scope with opaque redirect response which ' + |
274 []], | 364 'is passed through Cache.'); |
275 'SW fetched redirect to same-origin other-scope.'); | 365 promise_test(function(t) { |
276 }) | 366 return setup_environment(t).then(function() { |
277 | 367 return test_redirect( |
278 // Opaque redirect. | 368 SCOPE1 + "sw=opaqueThroughCache&url=" + |
279 // SW: event.respondWith(fetch( | 369 encodeURIComponent(SCOPE1), |
280 // new Request(event.request.url, {redirect: 'manual'}))); | 370 SCOPE1, |
281 .then(function() { | 371 [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
282 return test_redirect( | 372 encodeURIComponent(SCOPE1), SCOPE1], |
283 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE), | 373 [], |
284 OUT_SCOPE, | 374 []]); |
285 [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(OUT_SCOPE)], | 375 }); |
286 [], | 376 }, |
287 []], | 377 'Redirect to same-origin same-scope with opaque redirect response which ' + |
288 'Redirect to same-origin out-scope with opaque redirect ' + | 378 'is passed through Cache.'); |
289 'response.'); | 379 promise_test(function(t) { |
290 }) | 380 return setup_environment(t).then(function() { |
291 .then(function() { | 381 return test_redirect( |
292 return test_redirect( | 382 SCOPE1 + "sw=opaqueThroughCache&url=" + |
293 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), | 383 encodeURIComponent(SCOPE2), |
294 SCOPE1, | 384 SCOPE2, |
295 [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE1), SCOPE1], | 385 [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
296 [], | 386 encodeURIComponent(SCOPE2)], |
297 []], | 387 [SCOPE2], |
298 'Redirect to same-origin same-scope with opaque redirect ' + | 388 []]); |
299 'response.'); | 389 }); |
300 }) | 390 }, |
301 .then(function() { | 391 'Redirect to same-origin other-scope with opaque redirect response which ' + |
302 return test_redirect( | 392 'is passed through Cache.'); |
303 SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2), | 393 promise_test(function(t) { |
304 SCOPE2, | 394 return setup_environment(t).then(function() { |
305 [[SCOPE1 + "sw=opaque&url=" + encodeURIComponent(SCOPE2)], | 395 return test_redirect( |
306 [SCOPE2], | 396 SCOPE1 + "sw=opaqueThroughCache&url=" + |
307 []], | 397 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), |
308 'Redirect to same-origin other-scope with opaque redirect ' + | 398 OTHER_ORIGIN_OUT_SCOPE, |
309 'response.'); | 399 [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
310 }) | 400 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], |
311 .then(function() { | 401 [], |
312 return test_redirect( | 402 []]); |
313 SCOPE1 + "sw=opaque&url=" + | 403 }); |
314 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), | 404 }, |
315 OTHER_ORIGIN_OUT_SCOPE, | 405 'Redirect to other-origin out-scope with opaque redirect response which ' + |
316 [[SCOPE1 + "sw=opaque&url=" + | 406 'is passed through Cache.'); |
317 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], | 407 promise_test(function(t) { |
318 [], | 408 return setup_environment(t).then(function() { |
319 []], | 409 return test_redirect( |
320 'Redirect to other-origin out-scope with opaque redirect ' + | 410 SCOPE1 + "sw=opaqueThroughCache&url=" + |
321 'response.'); | 411 encodeURIComponent(OTHER_ORIGIN_SCOPE), |
322 }) | 412 OTHER_ORIGIN_SCOPE, |
323 .then(function() { | 413 [[SCOPE1 + "sw=opaqueThroughCache&url=" + |
324 return test_redirect( | 414 encodeURIComponent(OTHER_ORIGIN_SCOPE)], |
325 SCOPE1 + "sw=opaque&url=" + | 415 [], |
326 encodeURIComponent(OTHER_ORIGIN_SCOPE), | 416 [OTHER_ORIGIN_SCOPE]]); |
327 OTHER_ORIGIN_SCOPE, | 417 }); |
328 [[SCOPE1 + "sw=opaque&url=" + | 418 }, |
329 encodeURIComponent(OTHER_ORIGIN_SCOPE)], | 419 'Redirect to other-origin in-scope with opaque redirect response which ' + |
330 [], | 420 'is passed through Cache.'); |
331 [OTHER_ORIGIN_SCOPE]], | |
332 'Redirect to other-origin in-scope with opaque redirect ' + | |
333 'response.'); | |
334 }) | |
335 | |
336 // Opaque redirect passed through Cache. | |
337 // SW responds with an opaque redirectresponse from the Cache API. | |
338 .then(function() { | |
339 return test_redirect( | |
340 SCOPE1 + "sw=opaqueThroughCache&url=" + | |
341 encodeURIComponent(OUT_SCOPE), | |
342 OUT_SCOPE, | |
343 [[SCOPE1 + "sw=opaqueThroughCache&url=" + | |
344 encodeURIComponent(OUT_SCOPE)], | |
345 [], | |
346 []], | |
347 'Redirect to same-origin out-scope with opaque redirect ' + | |
348 'response which is passed through Cache.'); | |
349 }) | |
350 .then(function() { | |
351 return test_redirect( | |
352 SCOPE1 + "sw=opaqueThroughCache&url=" + | |
353 encodeURIComponent(SCOPE1), | |
354 SCOPE1, | |
355 [[SCOPE1 + "sw=opaqueThroughCache&url=" + | |
356 encodeURIComponent(SCOPE1), SCOPE1], | |
357 [], | |
358 []], | |
359 'Redirect to same-origin same-scope with opaque redirect ' + | |
360 'response which is passed through Cache.'); | |
361 }) | |
362 .then(function() { | |
363 return test_redirect( | |
364 SCOPE1 + "sw=opaqueThroughCache&url=" + | |
365 encodeURIComponent(SCOPE2), | |
366 SCOPE2, | |
367 [[SCOPE1 + "sw=opaqueThroughCache&url=" + | |
368 encodeURIComponent(SCOPE2)], | |
369 [SCOPE2], | |
370 []], | |
371 'Redirect to same-origin other-scope with opaque redirect ' + | |
372 'response which is passed through Cache.'); | |
373 }) | |
374 .then(function() { | |
375 return test_redirect( | |
376 SCOPE1 + "sw=opaqueThroughCache&url=" + | |
377 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE), | |
378 OTHER_ORIGIN_OUT_SCOPE, | |
379 [[SCOPE1 + "sw=opaqueThroughCache&url=" + | |
380 encodeURIComponent(OTHER_ORIGIN_OUT_SCOPE)], | |
381 [], | |
382 []], | |
383 'Redirect to other-origin out-scope with opaque redirect ' + | |
384 'response which is passed through Cache.'); | |
385 }) | |
386 .then(function() { | |
387 return test_redirect( | |
388 SCOPE1 + "sw=opaqueThroughCache&url=" + | |
389 encodeURIComponent(OTHER_ORIGIN_SCOPE), | |
390 OTHER_ORIGIN_SCOPE, | |
391 [[SCOPE1 + "sw=opaqueThroughCache&url=" + | |
392 encodeURIComponent(OTHER_ORIGIN_SCOPE)], | |
393 [], | |
394 [OTHER_ORIGIN_SCOPE]], | |
395 'Redirect to other-origin in-scope with opaque redirect ' + | |
396 'response which is passed through Cache.'); | |
397 }) | |
398 .then(function() { | |
399 return Promise.all( | |
400 [service_worker_unregister(t, SCOPE1), | |
401 service_worker_unregister(t, SCOPE2), | |
402 send_to_iframe(other_origin_frame, 'unregister')]); | |
403 }) | |
404 .then(function() { | |
405 other_origin_frame.remove(); | |
406 t.done(); | |
407 }) | |
408 .catch(unreached_rejection(t)); | |
409 }, 'Verify the behavior of navigation redirection with Service Worker.'); | |
410 </script> | 421 </script> |
411 </body> | 422 </body> |
OLD | NEW |