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