| OLD | NEW |
| 1 <script src="../../resources/get-host-info.js?pipe=sub"></script> | 1 <script src="../resources/get-host-info.sub.js"></script> |
| 2 <script src="test-helpers.js"></script> | 2 <script src="test-helpers.sub.js?pipe=sub"></script> |
| 3 <script> | 3 <script> |
| 4 var path = base_path() + 'fetch-access-control.php'; | 4 var path = base_path() + 'fetch-access-control.py'; |
| 5 var host_info = get_host_info(); | 5 var host_info = get_host_info(); |
| 6 var SUCCESS = 'SUCCESS'; | 6 var SUCCESS = 'SUCCESS'; |
| 7 var FAIL = 'FAIL'; | 7 var FAIL = 'FAIL'; |
| 8 | 8 |
| 9 function create_test_case_promise(url, with_credentials) { | 9 function create_test_case_promise(url, with_credentials) { |
| 10 return new Promise(function(resolve) { | 10 return new Promise(function(resolve) { |
| 11 var xhr = new XMLHttpRequest(); | 11 var xhr = new XMLHttpRequest(); |
| 12 xhr.onload = function() { | 12 xhr.onload = function() { |
| 13 if (xhr.status == 200) { | 13 if (xhr.status == 200) { |
| 14 resolve(SUCCESS); | 14 resolve(SUCCESS); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 test_cases.forEach(function(test_case) { | 47 test_cases.forEach(function(test_case) { |
| 48 promise = promise.then(function() { | 48 promise = promise.then(function() { |
| 49 return create_test_promise(test_case[0], test_case[1], test_case[2]); | 49 return create_test_promise(test_case[0], test_case[1], test_case[2]); |
| 50 }); | 50 }); |
| 51 }); | 51 }); |
| 52 return promise; | 52 return promise; |
| 53 } | 53 } |
| 54 | 54 |
| 55 window.addEventListener('message', function(evt) { | 55 window.addEventListener('message', function(evt) { |
| 56 var port = evt.ports[0]; | 56 var port = evt.ports[0]; |
| 57 var url = host_info['HTTP_ORIGIN'] + path; | 57 var url = host_info['HTTPS_ORIGIN'] + path; |
| 58 var remote_url = host_info['HTTP_REMOTE_ORIGIN'] + path; | 58 var remote_url = host_info['HTTPS_REMOTE_ORIGIN'] + path; |
| 59 // If the 4th value of the item of TEST_CASES is true, the test case outputs | 59 // If the 4th value of the item of TEST_CASES is true, the test case outputs |
| 60 // warning messages. So such tests must be executed in serial to match the | 60 // warning messages. So such tests must be executed in serial to match the |
| 61 // expected output text. | 61 // expected output text. |
| 62 var TEST_CASES = [ | 62 var TEST_CASES = [ |
| 63 // Reject tests | 63 // Reject tests |
| 64 [url + '?reject', false, FAIL], | 64 [url + '?reject', false, FAIL], |
| 65 [url + '?reject', true, FAIL], | 65 [url + '?reject', true, FAIL], |
| 66 [remote_url + '?reject', false, FAIL], | 66 [remote_url + '?reject', false, FAIL], |
| 67 [remote_url + '?reject', true, FAIL], | 67 [remote_url + '?reject', true, FAIL], |
| 68 // Event handler exception tests |
| 69 [url + '?throw', false, FAIL], |
| 70 [url + '?throw', true, FAIL], |
| 71 [remote_url + '?throw', false, FAIL], |
| 72 [remote_url + '?throw', true, FAIL], |
| 68 // Reject(resolve-null) tests | 73 // Reject(resolve-null) tests |
| 69 [url + '?resolve-null', false, FAIL], | 74 [url + '?resolve-null', false, FAIL], |
| 70 [url + '?resolve-null', true, FAIL], | 75 [url + '?resolve-null', true, FAIL], |
| 71 [remote_url + '?resolve-null', false, FAIL], | 76 [remote_url + '?resolve-null', false, FAIL], |
| 72 [remote_url + '?resolve-null', true, FAIL], | 77 [remote_url + '?resolve-null', true, FAIL], |
| 73 // Fallback tests | 78 // Fallback tests |
| 74 [url + '?ignore', false, SUCCESS], | 79 [url + '?ignore', false, SUCCESS], |
| 75 [url + '?ignore', true, SUCCESS], | 80 [url + '?ignore', true, SUCCESS], |
| 76 [remote_url + '?ignore', false, FAIL, true], // Executed in serial. | 81 [remote_url + '?ignore', false, FAIL, true], // Executed in serial. |
| 77 [remote_url + '?ignore', true, FAIL, true], // Executed in serial. | 82 [remote_url + '?ignore', true, FAIL, true], // Executed in serial. |
| 78 [ | 83 [ |
| 79 remote_url + '?ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore', | 84 remote_url + '?ACAOrigin=' + host_info['HTTPS_ORIGIN'] + '&ignore', |
| 80 false, SUCCESS | 85 false, SUCCESS |
| 81 ], | 86 ], |
| 82 [ | 87 [ |
| 83 remote_url + '?ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore', | 88 remote_url + '?ACAOrigin=' + host_info['HTTPS_ORIGIN'] + '&ignore', |
| 84 true, FAIL, true // Executed in serial. | 89 true, FAIL, true // Executed in serial. |
| 85 ], | 90 ], |
| 86 [ | 91 [ |
| 87 remote_url + '?ACAOrigin=' + host_info['HTTP_ORIGIN'] + | 92 remote_url + '?ACAOrigin=' + host_info['HTTPS_ORIGIN'] + |
| 88 '&ACACredentials=true&ignore', | 93 '&ACACredentials=true&ignore', |
| 89 true, SUCCESS | 94 true, SUCCESS |
| 90 ], | 95 ], |
| 91 // Credential test (fallback) | 96 // Credential test (fallback) |
| 92 [url + '?Auth&ignore', false, SUCCESS], | 97 [url + '?Auth&ignore', false, SUCCESS], |
| 93 [url + '?Auth&ignore', true, SUCCESS], | 98 [url + '?Auth&ignore', true, SUCCESS], |
| 94 [remote_url + '?Auth&ignore', false, FAIL, true], // Executed in serial. | 99 [remote_url + '?Auth&ignore', false, FAIL, true], // Executed in serial. |
| 95 [remote_url + '?Auth&ignore', true, FAIL, true], // Executed in serial. | 100 [remote_url + '?Auth&ignore', true, FAIL, true], // Executed in serial. |
| 96 [ | 101 [ |
| 97 remote_url + '?Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore', | 102 remote_url + '?Auth&ACAOrigin=' + host_info['HTTPS_ORIGIN'] + '&ignore', |
| 98 false, 'STATUS401' | 103 false, 'STATUS401' |
| 99 ], | 104 ], |
| 100 [ | 105 [ |
| 101 remote_url + '?Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] + '&ignore', | 106 remote_url + '?Auth&ACAOrigin=' + host_info['HTTPS_ORIGIN'] + '&ignore', |
| 102 true, FAIL, true // Executed in serial. | 107 true, FAIL, true // Executed in serial. |
| 103 ], | 108 ], |
| 104 [ | 109 [ |
| 105 remote_url + '?Auth&ACAOrigin=' + host_info['HTTP_ORIGIN'] + | 110 remote_url + '?Auth&ACAOrigin=' + host_info['HTTPS_ORIGIN'] + |
| 106 '&ACACredentials=true&ignore', | 111 '&ACACredentials=true&ignore', |
| 107 true, SUCCESS | 112 true, SUCCESS |
| 108 ], | 113 ], |
| 109 // Basic response | 114 // Basic response |
| 110 [ | 115 [ |
| 111 url + '?mode=same-origin&url=' + encodeURIComponent(url), | 116 url + '?mode=same-origin&url=' + encodeURIComponent(url), |
| 112 false, SUCCESS | 117 false, SUCCESS |
| 113 ], | 118 ], |
| 114 [ | 119 [ |
| 115 url + '?mode=same-origin&url=' + encodeURIComponent(url), | 120 url + '?mode=same-origin&url=' + encodeURIComponent(url), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 137 false, FAIL | 142 false, FAIL |
| 138 ], | 143 ], |
| 139 [ | 144 [ |
| 140 remote_url + '?mode=no-cors&url=' + encodeURIComponent(remote_url), | 145 remote_url + '?mode=no-cors&url=' + encodeURIComponent(remote_url), |
| 141 false, FAIL | 146 false, FAIL |
| 142 ], | 147 ], |
| 143 // CORS response | 148 // CORS response |
| 144 [ | 149 [ |
| 145 url + '?mode=cors&url=' + | 150 url + '?mode=cors&url=' + |
| 146 encodeURIComponent(remote_url + '?ACAOrigin=' + | 151 encodeURIComponent(remote_url + '?ACAOrigin=' + |
| 147 host_info['HTTP_ORIGIN']), | 152 host_info['HTTPS_ORIGIN']), |
| 148 false, SUCCESS | 153 false, SUCCESS |
| 149 ], | 154 ], |
| 150 [ | 155 [ |
| 151 url + '?mode=cors&url=' + | 156 url + '?mode=cors&url=' + |
| 152 encodeURIComponent(remote_url + '?ACAOrigin=' + | 157 encodeURIComponent(remote_url + '?ACAOrigin=' + |
| 153 host_info['HTTP_ORIGIN']), | 158 host_info['HTTPS_ORIGIN']), |
| 159 true, FAIL |
| 160 ], |
| 161 [ |
| 162 url + '?mode=cors&url=' + |
| 163 encodeURIComponent(remote_url + '?ACAOrigin=' + |
| 164 host_info['HTTPS_ORIGIN'] + |
| 165 '&ACACredentials=true'), |
| 154 true, SUCCESS | 166 true, SUCCESS |
| 155 ], | 167 ], |
| 156 [ | 168 [ |
| 157 remote_url + '?mode=cors&url=' + | 169 remote_url + '?mode=cors&url=' + |
| 158 encodeURIComponent(remote_url + '?ACAOrigin=' + | 170 encodeURIComponent(remote_url + '?ACAOrigin=' + |
| 159 host_info['HTTP_ORIGIN']), | 171 host_info['HTTPS_ORIGIN']), |
| 160 false, SUCCESS | 172 false, SUCCESS |
| 161 ], | 173 ], |
| 162 [ | 174 [ |
| 163 remote_url + | 175 remote_url + |
| 164 '?mode=cors&url=' + | 176 '?mode=cors&url=' + |
| 165 encodeURIComponent(remote_url + '?ACAOrigin=' + | 177 encodeURIComponent(remote_url + '?ACAOrigin=' + |
| 166 host_info['HTTP_ORIGIN']), | 178 host_info['HTTPS_ORIGIN']), |
| 179 true, FAIL |
| 180 ], |
| 181 [ |
| 182 remote_url + |
| 183 '?mode=cors&url=' + |
| 184 encodeURIComponent(remote_url + '?ACAOrigin=' + |
| 185 host_info['HTTPS_ORIGIN'] + |
| 186 '&ACACredentials=true'), |
| 167 true, SUCCESS | 187 true, SUCCESS |
| 168 ] | 188 ] |
| 169 ]; | 189 ]; |
| 170 var promises = []; | 190 var promises = []; |
| 171 var serial_tests = []; | 191 var serial_tests = []; |
| 172 for (var i = 0; i < TEST_CASES.length ; ++i) { | 192 for (var i = 0; i < TEST_CASES.length ; ++i) { |
| 173 if (!TEST_CASES[i][3]) { | 193 if (!TEST_CASES[i][3]) { |
| 174 promises.push(create_test_promise(TEST_CASES[i][0], | 194 promises.push(create_test_promise(TEST_CASES[i][0], |
| 175 TEST_CASES[i][1], | 195 TEST_CASES[i][1], |
| 176 TEST_CASES[i][2])); | 196 TEST_CASES[i][2])); |
| 177 } else { | 197 } else { |
| 178 serial_tests.push(TEST_CASES[i]); | 198 serial_tests.push(TEST_CASES[i]); |
| 179 } | 199 } |
| 180 } | 200 } |
| 181 promises.push(create_serial_promise(serial_tests)); | 201 promises.push(create_serial_promise(serial_tests)); |
| 182 Promise.all(promises) | 202 Promise.all(promises) |
| 183 .then(function() { | 203 .then(function() { |
| 184 port.postMessage({results: 'finish'}); | 204 port.postMessage({results: 'finish'}); |
| 185 }) | 205 }) |
| 186 .catch(function(e) { | 206 .catch(function(e) { |
| 187 port.postMessage({results: 'failure:' + e}); | 207 port.postMessage({results: 'failure:' + e}); |
| 188 }); | 208 }); |
| 189 }, false); | 209 }, false); |
| 190 </script> | 210 </script> |
| OLD | NEW |