| Index: LayoutTests/http/tests/fetch/resources/fetch-test-helpers.js
|
| diff --git a/LayoutTests/http/tests/fetch/resources/fetch-test-helpers.js b/LayoutTests/http/tests/fetch/resources/fetch-test-helpers.js
|
| index 4958ac0c0afd5af7c798a2bf1e5ed35357c70f70..9664a0150f79f624db3bd02213f77ad8b62ddb48 100644
|
| --- a/LayoutTests/http/tests/fetch/resources/fetch-test-helpers.js
|
| +++ b/LayoutTests/http/tests/fetch/resources/fetch-test-helpers.js
|
| @@ -126,3 +126,68 @@ var VALID_REASON_PHRASE = [
|
| // Valid strings.
|
| '', '0123456789', '404 Not Found', 'HTTP/1.1 404 Not Found', 'AZ\u00ffaz',
|
| 'x'.repeat(100000)];
|
| +
|
| +function testBlockMixedContent(mode) {
|
| + promise_test(function(t) {
|
| + return Promise.resolve()
|
| + .then(function() {
|
| + // Test 1: Must fail: blocked as mixed content.
|
| + return fetch(BASE_URL + 'test1-' + mode, {mode: mode})
|
| + .then(t.unreached_func('Test 1: Must be blocked (' +
|
| + mode + ', HTTPS->HTTP)'),
|
| + function() {});
|
| + })
|
| + .then(function() {
|
| + // Block mixed content in redirects.
|
| + // Test 2: Must fail: original fetch is not blocked but
|
| + // redirect is blocked.
|
| + return fetch(HTTPS_REDIRECT_URL +
|
| + encodeURIComponent(BASE_URL + 'test2-' + mode),
|
| + {mode: mode})
|
| + .then(t.unreached_func('Test 2: Must be blocked (' +
|
| + mode + ', HTTPS->HTTPS->HTTP)'),
|
| + function() {});
|
| + })
|
| + .then(function() {
|
| + // Test 3: Must fail: original fetch is blocked.
|
| + return fetch(REDIRECT_URL +
|
| + encodeURIComponent(HTTPS_BASE_URL + 'test3-' + mode),
|
| + {mode: mode})
|
| + .then(t.unreached_func('Test 3: Must be blocked (' +
|
| + mode + ', HTTPS->HTTP->HTTPS)'),
|
| + function() {});
|
| + })
|
| + .then(function() {
|
| + // Test 4: Must success.
|
| + // Test that the mixed contents above are not rejected due to
|
| + return fetch(HTTPS_REDIRECT_URL +
|
| + encodeURIComponent(HTTPS_BASE_URL + 'test4-' + mode),
|
| + {mode: mode})
|
| + .then(function(res) {assert_equals(res.status, 200); },
|
| + t.unreached_func('Test 4: Must success (' +
|
| + mode + ', HTTPS->HTTPS->HTTPS)'));
|
| + })
|
| + .then(function() {
|
| + // Test 5: Must success if mode is not 'same-origin'.
|
| + // Test that the mixed contents above are not rejected due to
|
| + // CORS check.
|
| + return fetch(HTTPS_OTHER_REDIRECT_URL +
|
| + encodeURIComponent(HTTPS_BASE_URL + 'test5-' + mode),
|
| + {mode: mode})
|
| + .then(function(res) {
|
| + if (mode === 'same-origin') {
|
| + assert_unreached(
|
| + 'Test 5: Cross-origin HTTPS request must fail: ' +
|
| + 'mode = ' + mode);
|
| + }
|
| + },
|
| + function() {
|
| + if (mode !== 'same-origin') {
|
| + assert_unreached(
|
| + 'Test 5: Cross-origin HTTPS request must success: ' +
|
| + 'mode = ' + mode);
|
| + }
|
| + });
|
| + });
|
| + }, 'Block fetch() as mixed content (' + mode + ')');
|
| +}
|
|
|