|
|
|
|
| 71 |
|
71 |
|
| 72 |
|
72 |
|
| 73 |
let host_info = get_host_info(); |
73 |
let host_info = get_host_info(); |
| 74 |
const REDIRECT_URL = host_info['HTTPS_ORIGIN'] + base_path() + |
74 |
const REDIRECT_URL = host_info['HTTPS_ORIGIN'] + base_path() + |
| 75 |
'resources/redirect.py?Redirect='; |
75 |
'resources/redirect.py?Redirect='; |
| 76 |
const TARGET_URL = host_info['HTTPS_ORIGIN'] + base_path() + |
76 |
const TARGET_URL = host_info['HTTPS_ORIGIN'] + base_path() + |
| 77 |
'resources/simple.txt?'; |
77 |
'resources/simple.txt?'; |
| 78 |
const REDIRECT_TO_TARGET_URL = REDIRECT_URL + encodeURIComponent(TARGET_URL); |
78 |
const REDIRECT_TO_TARGET_URL = REDIRECT_URL + encodeURIComponent(TARGET_URL); |
|
|
79 |
const REMOTE_TARGET_URL = host_info['HTTPS_REMOTE_ORIGIN'] + base_path() + |
| 80 |
'resources/simple-cors.txt?'; |
| 79 |
let frame; |
81 |
let frame; |
| 80 |
let cache; |
82 |
let cache; |
| 81 |
let setup; |
83 |
let setup; |
| 82 |
let worker; |
84 |
let worker; |
| 83 |
|
85 |
|
| 84 |
promise_test(t => { |
86 |
promise_test(t => { |
| 85 |
const SCOPE = 'resources/blank.html?redirected-response'; |
87 |
const SCOPE = 'resources/blank.html?redirected-response'; |
| 86 |
const SCRIPT = 'resources/redirect-worker.js'; |
88 |
const SCRIPT = 'resources/redirect-worker.js'; |
|
|
| 294 |
fetch_option: {redirect: 'manual'}, |
296 |
fetch_option: {redirect: 'manual'}, |
| 295 |
fetch_method: frame.contentWindow.fetch, |
297 |
fetch_method: frame.contentWindow.fetch, |
| 296 |
expected_type: 'opaqueredirect', |
298 |
expected_type: 'opaqueredirect', |
| 297 |
expected_redirected: false, |
299 |
expected_redirected: false, |
| 298 |
expected_intercepted_urls: [url]}) |
300 |
expected_intercepted_urls: [url]}) |
| 299 |
}), |
301 |
}), |
| 300 |
'mode: "manual", generated redirect response'); |
302 |
'mode: "manual", generated redirect response'); |
| 301 |
|
303 |
|
|
|
304 |
promise_test(t => setup_and_clean() |
| 305 |
.then(() => { |
| 306 |
const url = host_info['HTTPS_ORIGIN'] + base_path() + |
| 307 |
'dummy?url=' + encodeURIComponent(REMOTE_TARGET_URL) + |
| 308 |
'&original-redirect-mode=follow&sw=gen'; |
| 309 |
return redirected_test({url: url, |
| 310 |
fetch_option: {redirect: 'follow'}, |
| 311 |
fetch_method: frame.contentWindow.fetch, |
| 312 |
expected_type: 'cors', |
| 313 |
expected_redirected: true, |
| 314 |
expected_intercepted_urls: [url, TARGET_URL]}) |
| 315 |
}), |
| 316 |
'mode: "follow", cors generated cross-origin redirect response'); |
| 317 |
|
| 318 |
promise_test(t => setup_and_clean() |
| 319 |
.then(() => { |
| 320 |
const url = host_info['HTTPS_ORIGIN'] + base_path() + |
| 321 |
'dummy?url=' + encodeURIComponent(REMOTE_TARGET_URL) + |
| 322 |
'&original-redirect-mode=error&sw=gen'; |
| 323 |
return promise_rejects( |
| 324 |
t, new TypeError(), |
| 325 |
frame.contentWindow.fetch(url, {redirect: 'error'}), |
| 326 |
'The generated redirect response from the service worker should ' + |
| 327 |
'be treated as an error when the redirect flag of request was' + |
| 328 |
' \'error\'.') |
| 329 |
.then(() => check_intercepted_urls([url])); |
| 330 |
}), |
| 331 |
'mode: "error", cors generated cross-origin redirect response'); |
| 332 |
|
| 333 |
promise_test(t => setup_and_clean() |
| 334 |
.then(() => { |
| 335 |
const url = host_info['HTTPS_ORIGIN'] + base_path() + |
| 336 |
'dummy?url=' + encodeURIComponent(REMOTE_TARGET_URL) + |
| 337 |
'&original-redirect-mode=follow&sw=gen'; |
| 338 |
return redirected_test({url: url, |
| 339 |
fetch_option: {redirect: 'manual'}, |
| 340 |
fetch_method: frame.contentWindow.fetch, |
| 341 |
expected_type: 'opaqueredirect', |
| 342 |
expected_redirected: false, |
| 343 |
expected_intercepted_urls: [url]}) |
| 344 |
}), |
| 345 |
'mode: "manual", cors generated cross-origin redirect response'); |
| 346 |
|
| 347 |
promise_test(t => setup_and_clean() |
| 348 |
.then(() => { |
| 349 |
const url = host_info['HTTPS_ORIGIN'] + base_path() + |
| 350 |
'dummy?url=' + encodeURIComponent(REMOTE_TARGET_URL) + |
| 351 |
'&original-redirect-mode=follow&sw=gen'; |
| 352 |
return redirected_test({url: url, |
| 353 |
fetch_option: {mode: 'no-cors', redirect: 'follow'}, |
| 354 |
fetch_method: frame.contentWindow.fetch, |
| 355 |
expected_type: 'opaque', |
| 356 |
expected_redirected: true, |
| 357 |
expected_intercepted_urls: [url, TARGET_URL]}) |
| 358 |
}), |
| 359 |
'mode: "follow", no-cors generated cross-origin redirect response'); |
| 360 |
|
| 361 |
promise_test(t => setup_and_clean() |
| 362 |
.then(() => { |
| 363 |
const url = host_info['HTTPS_ORIGIN'] + base_path() + |
| 364 |
'dummy?url=' + encodeURIComponent(REMOTE_TARGET_URL) + |
| 365 |
'&original-redirect-mode=error&sw=gen'; |
| 366 |
return promise_rejects( |
| 367 |
t, new TypeError(), |
| 368 |
frame.contentWindow.fetch(url, {mode: 'no-cors', redirect: 'error'}), |
| 369 |
'The generated redirect response from the service worker should ' + |
| 370 |
'be treated as an error when the redirect flag of request was' + |
| 371 |
' \'error\'.') |
| 372 |
.then(() => check_intercepted_urls([url])); |
| 373 |
}), |
| 374 |
'mode: "error", no-cors generated cross-origin redirect response'); |
| 375 |
|
| 376 |
promise_test(t => setup_and_clean() |
| 377 |
.then(() => { |
| 378 |
const url = host_info['HTTPS_ORIGIN'] + base_path() + |
| 379 |
'dummy?url=' + encodeURIComponent(REMOTE_TARGET_URL) + |
| 380 |
'&original-redirect-mode=follow&sw=gen'; |
| 381 |
return redirected_test({url: url, |
| 382 |
fetch_option: {mode: 'no-cors', redirect: 'manual'}, |
| 383 |
fetch_method: frame.contentWindow.fetch, |
| 384 |
expected_type: 'opaqueredirect', |
| 385 |
expected_redirected: false, |
| 386 |
expected_intercepted_urls: [url]}) |
| 387 |
}), |
| 388 |
'mode: "manual", no-cors generated cross-origin redirect response'); |
| 389 |
|
| 302 |
// ======================================================= |
390 |
// ======================================================= |
| 303 |
// Tests for requests that are in-scope of the service worker. The service |
391 |
// Tests for requests that are in-scope of the service worker. The service |
| 304 |
// worker returns a generated redirect response. And the fetch follows the |
392 |
// worker returns a generated redirect response. And the fetch follows the |
| 305 |
// redirection multiple times. |
393 |
// redirection multiple times. |
| 306 |
// ======================================================= |
394 |
// ======================================================= |
| 307 |
promise_test(t => setup_and_clean() |
395 |
promise_test(t => setup_and_clean() |
| 308 |
.then(() => { |
396 |
.then(() => { |
| 309 |
// The Fetch spec says: "If request’s redirect count is twenty, return a |
397 |
// The Fetch spec says: "If request’s redirect count is twenty, return a |