| OLD | NEW |
| 1 if (self.importScripts) { | 1 if (self.importScripts) { |
| 2 importScripts('/resources/testharness.js'); | 2 importScripts('/resources/testharness.js'); |
| 3 importScripts('/serviceworker/resources/test-helpers.js'); | 3 importScripts('/serviceworker/resources/test-helpers.js'); |
| 4 importScripts('/fetch/resources/fetch-test-options.js'); | 4 importScripts('/fetch/resources/fetch-test-options.js'); |
| 5 } | 5 } |
| 6 | 6 |
| 7 function getContentType(headers) { | 7 function getContentType(headers) { |
| 8 var content_type = ''; | 8 var content_type = ''; |
| 9 for (var header of headers) { | 9 for (var header of headers) { |
| 10 if (header[0] == 'content-type') | 10 if (header[0] == 'content-type') |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 function size(headers) { | 146 function size(headers) { |
| 147 var count = 0; | 147 var count = 0; |
| 148 for (var header of headers) { | 148 for (var header of headers) { |
| 149 ++count; | 149 ++count; |
| 150 } | 150 } |
| 151 return count; | 151 return count; |
| 152 } | 152 } |
| 153 | 153 |
| 154 function testBlockMixedContent(mode) { | 154 function testBlockMixedContent(mode) { |
| 155 promise_test(function(t) { | 155 promise_test(t => { |
| 156 return Promise.resolve() | 156 // Must fail: blocked as mixed content. |
| 157 .then(function() { | 157 return fetch(BASE_URL + 'test1-' + mode, {mode: mode}) |
| 158 // Test 1: Must fail: blocked as mixed content. | 158 .then(unreached_fulfillment(t), () => {}); |
| 159 return fetch(BASE_URL + 'test1-' + mode, {mode: mode}) | 159 }, `Mixed content fetch (${mode}, HTTPS->HTTP)`); |
| 160 .then(t.unreached_func('Test 1: Must be blocked (' + | 160 |
| 161 mode + ', HTTPS->HTTP)'), | 161 promise_test(t => { |
| 162 function() {}); | 162 // Must fail: original fetch is not blocked but redirect is blocked. |
| 163 }) | 163 return fetch(HTTPS_REDIRECT_URL + |
| 164 .then(function() { | 164 encodeURIComponent(BASE_URL + 'test2-' + mode), {mode: mode}) |
| 165 // Block mixed content in redirects. | 165 .then(unreached_fulfillment(t), () => {}); |
| 166 // Test 2: Must fail: original fetch is not blocked but | 166 }, `Mixed content redirect (${mode}, HTTPS->HTTPS->HTTP)`); |
| 167 // redirect is blocked. | 167 |
| 168 return fetch(HTTPS_REDIRECT_URL + | 168 promise_test(t => { |
| 169 encodeURIComponent(BASE_URL + 'test2-' + mode), | 169 // Must fail: original fetch is blocked. |
| 170 {mode: mode}) | 170 return fetch(REDIRECT_URL + |
| 171 .then(t.unreached_func('Test 2: Must be blocked (' + | 171 encodeURIComponent(HTTPS_BASE_URL + 'test3-' + mode), |
| 172 mode + ', HTTPS->HTTPS->HTTP)'), | 172 {mode: mode}).then(unreached_fulfillment(t), () => {}); |
| 173 function() {}); | 173 }, `Mixed content redirect ${mode}, HTTPS->HTTP->HTTPS)`); |
| 174 }) | 174 |
| 175 .then(function() { | 175 promise_test(() => { |
| 176 // Test 3: Must fail: original fetch is blocked. | 176 // Must success. |
| 177 return fetch(REDIRECT_URL + | 177 // Test that the mixed contents above are not rejected due to CORS check. |
| 178 encodeURIComponent(HTTPS_BASE_URL + 'test3-' + mode), | 178 return fetch(HTTPS_REDIRECT_URL + |
| 179 {mode: mode}) | 179 encodeURIComponent(HTTPS_BASE_URL + 'test4-' + mode), |
| 180 .then(t.unreached_func('Test 3: Must be blocked (' + | 180 {mode: mode}).then(res => { |
| 181 mode + ', HTTPS->HTTP->HTTPS)'), | 181 assert_equals(res.status, mode === 'no-cors' ? 0 : 200); |
| 182 function() {}); | 182 }); |
| 183 }) | 183 }, `Same origin redirect (${mode}, HTTPS->HTTPS->HTTPS)`); |
| 184 .then(function() { | 184 |
| 185 // Test 4: Must success. | 185 promise_test(() => { |
| 186 // Test that the mixed contents above are not rejected due to | 186 // Must success if mode is not 'same-origin'. |
| 187 return fetch(HTTPS_REDIRECT_URL + | 187 // Test that the mixed contents above are not rejected due to CORS check. |
| 188 encodeURIComponent(HTTPS_BASE_URL + 'test4-' + mode), | 188 return fetch(HTTPS_OTHER_REDIRECT_URL + |
| 189 {mode: mode}) | 189 encodeURIComponent(HTTPS_BASE_URL + 'test5-' + mode), |
| 190 .then(function(res) {assert_equals(res.status, mode == 'no-cors' ?
0 : 200); }, | 190 {mode: mode}) |
| 191 t.unreached_func('Test 4: Must success (' + | 191 .then(res => { |
| 192 mode + ', HTTPS->HTTPS->HTTPS)')); | 192 assert_not_equals(mode, 'same-origin'); |
| 193 }) | 193 }, () => { |
| 194 .then(function() { | 194 assert_equals(mode, 'same-origin'); |
| 195 // Test 5: Must success if mode is not 'same-origin'. | |
| 196 // Test that the mixed contents above are not rejected due to | |
| 197 // CORS check. | |
| 198 return fetch(HTTPS_OTHER_REDIRECT_URL + | |
| 199 encodeURIComponent(HTTPS_BASE_URL + 'test5-' + mode), | |
| 200 {mode: mode}) | |
| 201 .then(function(res) { | |
| 202 if (mode === 'same-origin') { | |
| 203 assert_unreached( | |
| 204 'Test 5: Cross-origin HTTPS request must fail: ' + | |
| 205 'mode = ' + mode); | |
| 206 } | |
| 207 }, | |
| 208 function() { | |
| 209 if (mode !== 'same-origin') { | |
| 210 assert_unreached( | |
| 211 'Test 5: Cross-origin HTTPS request must success: ' + | |
| 212 'mode = ' + mode); | |
| 213 } | |
| 214 }); | |
| 215 }); | 195 }); |
| 216 }, 'Block fetch() as mixed content (' + mode + ')'); | 196 }, `Cross origin redirect (${mode}, HTTPS->HTTPS->HTTPS`); |
| 217 } | 197 } |
| 218 | 198 |
| 219 function add_referrer_tests(tests, global) { | 199 function add_referrer_tests(tests, global) { |
| 220 global = global || self; | 200 global = global || self; |
| 221 for (let test of tests) { | 201 for (let test of tests) { |
| 222 let url = test[0]; | 202 let url = test[0]; |
| 223 let referrer = test[1]; | 203 let referrer = test[1]; |
| 224 let policy = test[2]; | 204 let policy = test[2]; |
| 225 let expected = test[3]; | 205 let expected = test[3]; |
| 226 promise_test(t => { | 206 promise_test(t => { |
| 227 var request = new Request(url, | 207 var request = new Request(url, |
| 228 {referrer: referrer, referrerPolicy: policy, mode: 'cors'}); | 208 {referrer: referrer, referrerPolicy: policy, mode: 'cors'}); |
| 229 return global.fetch(new Request(url, request)).then(res => { | 209 return global.fetch(new Request(url, request)).then(res => { |
| 230 return res.json(); | 210 return res.json(); |
| 231 }).then(json => { | 211 }).then(json => { |
| 232 assert_equals(json.referrer, expected, 'referrer'); | 212 assert_equals(json.referrer, expected, 'referrer'); |
| 233 }); | 213 }); |
| 234 }, | 214 }, |
| 235 `referrer test: url = ${url}, referrer = ${referrer}, policy = ${policy}`); | 215 `referrer test: url = ${url}, referrer = ${referrer}, policy = ${policy}`); |
| 236 } | 216 } |
| 237 } | 217 } |
| OLD | NEW |