blob: f5712295d30d7b1d680ad6753dd401d21c0409f9 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/helper.sub.js"></script>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types">
</head>
<body>
<script>
// helper functions for the tests
function testWindowOpen(t, win) {
createURL_policy(window)
.then(t.step_func_done(p => {
let url = p.createURL(INPUTS.URL);
let child_window = win.open(url, "", "");
child_window.onload = t.step_func_done(_ => {
assert_equals(child_window.location.href, "" + url);
child_window.close();
});
}));
}
function testWindowThrows(t, url, win) {
createURL_policy(window)
.then(t.step_func_done(p => {
assert_throws(new TypeError(), _ => {
let child_window = win.open(url, "", "");
child_window.close();
});
}));
}
// TrustedURL assignments do not throw.
async_test(t => {
testWindowOpen(t, window);
}, "window.open via policy (successful URL transformation).");
async_test(t => {
testWindowOpen(t, document);
}, "document.open via policy (successful URL transformation).");
// String assignments throw.
async_test(t => {
testWindowThrows(t, 'A string', window);
}, "`window.open(string)` throws.");
async_test(t => {
testWindowThrows(t, 'A string', document);
}, "`document.open(string)` throws.");
// Null assignment throws.
async_test(t => {
testWindowThrows(t, null, window);
}, "`window.open(null)` throws.");
async_test(t => {
testWindowThrows(t, null, document);
}, "`document.open(null)` throws.");
</script>
</body>
</html>