OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML> |
| 2 <script src="/resources/testharness.js"></script> |
| 3 <script src="/resources/testharnessreport.js"></script> |
| 4 <script src="/resources/get-host-info.js?pipe=sub"></script> |
| 5 <script> |
| 6 if (window.testRunner) |
| 7 testRunner.setBlockThirdPartyCookies(false); |
| 8 |
| 9 const host_info = get_host_info(); |
| 10 |
| 11 document.cookie = "TestCookie=same"; |
| 12 |
| 13 const set_cookie_promise = fetch( |
| 14 host_info['HTTP_REMOTE_ORIGIN'] + '/security/resources/set-cookie.php?name=T
estCookie&value=cross', |
| 15 {mode: 'no-cors', credentials: 'include'}); |
| 16 |
| 17 let count = 0; |
| 18 |
| 19 const test_name_prefix = 'cross-origin-redirect-credentials'; |
| 20 |
| 21 function parse_check_beacon_response(body) { |
| 22 const lines = body.split('\n'); |
| 23 |
| 24 const headers = {}; |
| 25 |
| 26 for (let line of lines) { |
| 27 const elements = line.split(': ', 2); |
| 28 const name = elements[0].toLowerCase(); |
| 29 const value = elements[1]; |
| 30 if (name in headers) { |
| 31 headers[name].push(value); |
| 32 } else { |
| 33 headers[name] = [value]; |
| 34 } |
| 35 } |
| 36 |
| 37 return headers; |
| 38 } |
| 39 |
| 40 function run_test(url, status_code, expectations) { |
| 41 const test_name = test_name_prefix + count; |
| 42 ++count; |
| 43 |
| 44 return set_cookie_promise.then(() => { |
| 45 const destination_params = new URLSearchParams(); |
| 46 destination_params.append('name', test_name); |
| 47 destination_params.append('dontclearcookies', undefined); |
| 48 |
| 49 const params = new URLSearchParams(); |
| 50 params.append('url', url + '?' + destination_params.toString()); |
| 51 params.append('code', status_code); |
| 52 |
| 53 navigator.sendBeacon('/resources/redirect.php?' + params.toString(), 'foobar
'); |
| 54 }).then(() => { |
| 55 return new Promise(resolve => { |
| 56 setTimeout(resolve, 10); |
| 57 }); |
| 58 }).then(() => { |
| 59 return fetch('resources/check-beacon.php?name=' + test_name); |
| 60 }).then(response => { |
| 61 assert_equals(response.status, 200, 'check-beacon must be successful'); |
| 62 |
| 63 return response.text(); |
| 64 }).then(responseText => { |
| 65 const headers = parse_check_beacon_response(responseText); |
| 66 |
| 67 for (let name of Object.keys(expectations)) { |
| 68 const expected_value = expectations[name]; |
| 69 if (expected_value === undefined) { |
| 70 assert_false(name in headers, 'No ' + name + ' header expected'); |
| 71 } else { |
| 72 assert_true(name in headers, name + ' header expected'); |
| 73 const actual_values = headers[name]; |
| 74 assert_equals(actual_values.length, 1, 'Just one ' + name + ' header exp
ected'); |
| 75 assert_equals(actual_values[0], |
| 76 expected_value, 'Value of ' + name + ' header should be "'
+ expected_value + '"'); |
| 77 } |
| 78 } |
| 79 }); |
| 80 } |
| 81 |
| 82 promise_test(() => { |
| 83 return run_test( |
| 84 host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php', |
| 85 301, |
| 86 { |
| 87 cookie: 'TestCookie=cross', |
| 88 'request-method': 'GET' |
| 89 }); |
| 90 }, 'Status code 301'); |
| 91 |
| 92 promise_test(() => { |
| 93 return run_test( |
| 94 host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php', |
| 95 302, |
| 96 { |
| 97 cookie: 'TestCookie=cross', |
| 98 'request-method': 'GET' |
| 99 }); |
| 100 }, 'Status code 302'); |
| 101 |
| 102 promise_test(() => { |
| 103 return run_test( |
| 104 host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php', |
| 105 303, |
| 106 { |
| 107 cookie: 'TestCookie=cross', |
| 108 'request-method': 'GET' |
| 109 }); |
| 110 }, 'Status code 303'); |
| 111 |
| 112 promise_test(() => { |
| 113 return run_test( |
| 114 host_info['HTTP_REMOTE_ORIGIN'] + '/navigation/resources/save-beacon.php', |
| 115 307, |
| 116 { |
| 117 cookie: 'TestCookie=cross', |
| 118 'request-method': 'POST' |
| 119 }); |
| 120 }, 'Status code 307'); |
| 121 |
| 122 // TODO(tyoshino): Add a test for 308. |
| 123 </script> |
OLD | NEW |