Commit 4d4cfc11 authored by yhirano's avatar yhirano Committed by Commit bot

Split a mixed-content promise test into separate ones.

BUG=None

Review-Url: https://codereview.chromium.org/2543643006
Cr-Commit-Position: refs/heads/master@{#443153}
parent aae2a1b1
......@@ -152,68 +152,48 @@ function size(headers) {
}
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, mode == 'no-cors' ? 0 : 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);
}
});
promise_test(t => {
// Must fail: blocked as mixed content.
return fetch(BASE_URL + 'test1-' + mode, {mode: mode})
.then(unreached_fulfillment(t), () => {});
}, `Mixed content fetch (${mode}, HTTPS->HTTP)`);
promise_test(t => {
// Must fail: original fetch is not blocked but redirect is blocked.
return fetch(HTTPS_REDIRECT_URL +
encodeURIComponent(BASE_URL + 'test2-' + mode), {mode: mode})
.then(unreached_fulfillment(t), () => {});
}, `Mixed content redirect (${mode}, HTTPS->HTTPS->HTTP)`);
promise_test(t => {
// Must fail: original fetch is blocked.
return fetch(REDIRECT_URL +
encodeURIComponent(HTTPS_BASE_URL + 'test3-' + mode),
{mode: mode}).then(unreached_fulfillment(t), () => {});
}, `Mixed content redirect ${mode}, HTTPS->HTTP->HTTPS)`);
promise_test(() => {
// Must success.
// Test that the mixed contents above are not rejected due to CORS check.
return fetch(HTTPS_REDIRECT_URL +
encodeURIComponent(HTTPS_BASE_URL + 'test4-' + mode),
{mode: mode}).then(res => {
assert_equals(res.status, mode === 'no-cors' ? 0 : 200);
});
}, `Same origin redirect (${mode}, HTTPS->HTTPS->HTTPS)`);
promise_test(() => {
// 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(res => {
assert_not_equals(mode, 'same-origin');
}, () => {
assert_equals(mode, 'same-origin');
});
}, 'Block fetch() as mixed content (' + mode + ')');
}, `Cross origin redirect (${mode}, HTTPS->HTTPS->HTTPS`);
}
function add_referrer_tests(tests, global) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment