Commit 63f6bb43 authored by falken@chromium.org's avatar falken@chromium.org

Service workers: Add test for HTTP to HTTPS redirect

Test for Chromium change: https://codereview.chromium.org/1315483002

BUG=522900

Review URL: https://codereview.chromium.org/1312723002

git-svn-id: svn://svn.chromium.org/blink/trunk@201054 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c8face1d
<!DOCTYPE html>
<title>register on a secure page after redirect from an non-secure url</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharness-helpers.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/get-host-info.js?pipe=sub"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
// Loads a non-secure url in an iframe, which redirects to |target_url|.
// That page then registers a service worker, and messages back with the result.
// Returns a promise that resolves with the result.
function redirect_and_register(target_url) {
var redirect_url = get_host_info()['UNAUTHENTICATED_ORIGIN'] +
'/serviceworker/resources/redirect.php?Redirect=';
var frame;
return with_iframe(redirect_url + encodeURIComponent(target_url))
.then(f => {
frame = f;
return new Promise(resolve => {
window.addEventListener('message', e => {resolve(e.data);});
});
})
.then(result => {
frame.remove();
return result;
});
}
promise_test(function(t) {
var target_url = window.location.origin +
'/serviceworker/resources/register.html';
return redirect_and_register(target_url)
.then(result => { assert_equals(result, 'OK'); });
}, 'register on a secure page after redirect from an non-secure url');
promise_test(function(t) {
var target_url = get_host_info()['UNAUTHENTICATED_ORIGIN'] +
'/serviceworker/resources/register.html';
return redirect_and_register(target_url)
.then(result => {assert_equals(result, 'FAIL: NotSupportedError');});
}, 'register on a non-secure page after redirect from an non-secure url');
</script>
</body>
<!doctype html>
<title>register</title>
<script src="test-helpers.js"></script>
<body>
<script>
navigator.serviceWorker.register('empty-worker.js', {scope: 'scope-register'})
.then(
registration => {
registration.unregister().then(() => {
window.parent.postMessage('OK', '*');
});
},
error => {
window.parent.postMessage('FAIL: ' + error.name, '*');
})
.catch(error => {
window.parent.postMessage('ERROR: ' + error.name, '*');
});
</script>
</body>
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