blob: 693c9f3cb265ee2976f15e58b02ce4aacdec8f09 [file] [log] [blame]
<!DOCTYPE html>
<title>Service Worker: Fetch for the frame loading.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/get-host-info.js"></script>
<script src="resources/test-helpers.js"></script>
<body>
<script>
var worker = 'resources/fetch-rewrite-worker.js';
var path = base_path() + 'resources/fetch-access-control.php';
var host_info = get_host_info();
if (window.testRunner) {
testRunner.setCanOpenWindows();
}
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/frame-basic';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
return with_iframe(
scope + '?url=' +
encodeURIComponent(host_info['HTTP_ORIGIN'] + path));
})
.then(function(frame) {
assert_equals(
frame.contentDocument.body.textContent.substr(0, 7),
'report(',
'Basic type response could be loaded in the iframe.');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'Basic type response could be loaded in the iframe.');
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/frame-cors';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
return with_iframe(
scope + '?mode=cors&url=' +
encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path +
'?ACAOrigin=' + host_info['HTTP_ORIGIN']));
})
.then(function(frame) {
assert_equals(
frame.contentDocument.body.textContent.substr(0, 7),
'report(',
'CORS type response could be loaded in the iframe.');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'CORS type response could be loaded in the iframe.');
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/frame-opaque';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
var frame = document.createElement('iframe');
frame.src =
scope + '?mode=no-cors&url=' +
encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path);
document.body.appendChild(frame);
return new Promise(function(resolve) {
frame.onload = function () { resolve(frame) };
});
})
.then(function(frame) {
assert_throws('SecurityError', _ => {
assert_equals(frame.contentDocument.body.textContent, '');
}, 'Opaque response renders error page in the iframe.');
frame.remove();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'Opaque type response could not be loaded in the iframe.');
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/window-basic';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
return new Promise(function(resolve) {
var win = window.open(
scope + '?url=' +
encodeURIComponent(host_info['HTTP_ORIGIN'] + path));
win.onload = function() { resolve(win); };
});
})
.then(function(win) {
assert_equals(
win.document.body.textContent.substr(0, 7),
'report(',
'Basic type response could be loaded in the new window.');
win.close();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'Basic type response could be loaded in the new window.');
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/window-cors';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
return new Promise(function(resolve) {
var win = window.open(
scope + '?mode=cors&url=' +
encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path +
'?ACAOrigin=' + host_info['HTTP_ORIGIN']));
win.onload = function() { resolve(win); };
});
})
.then(function(win) {
assert_equals(
win.document.body.textContent.substr(0, 7),
'report(',
'CORS type response could be loaded in the new window.');
win.close();
return service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
}, 'CORS type response could be loaded in the new window.');
async_test(function(t) {
var scope = 'resources/fetch-frame-resource/window-opaque';
service_worker_unregister_and_register(t, worker, scope)
.then(function(reg) {
return wait_for_state(t, reg.installing, 'activated');
})
.then(function() {
return window.open(
scope + '?mode=no-cors&url=' +
encodeURIComponent(host_info['HTTP_REMOTE_ORIGIN'] + path));
})
.then(function(win) {
// Give the window time to load: we won't get any error or load events
// so we'll set a timeout instead:
setTimeout(_ => {
assert_throws('SecurityError', _ => {
assert_equals(win.document.body.textContent, '');
}, 'Opaque response renders error page in the new window.');
win.close();
return service_worker_unregister_and_done(t, scope);
}, 1000);
})
// .catch(unreached_rejection(t));
}, 'Opaque type response could not be loaded in the new window.');
</script>
</body>