<!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, url, win) {
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) {
let child_window = win.open(TrustedURL.create(URLS.safe), "", "");
child_window.onload = t.step_func_done(_ => {
assert_throws(new TypeError(), _ => {
child_window = win.open(url, "", "");
child_window.close();
});
});
}
//TrustedURL assignments do not throw
async_test(t => {
testWindowOpen(t, TrustedURL.create(URLS.safe), window);
}, "window.open: safe URL, safe construction.");
async_test(t => {
testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), window);
}, "window.open: safe URL, unsafe construction.");
async_test(t => {
testWindowOpen(t, TrustedURL.create(URLS.safe), document);
}, "document.open: safe URL, safe construction.");
async_test(t => {
testWindowOpen(t, TrustedURL.unsafelyCreate(URLS.safe), document);
}, "document.open: safe URL, unsafe construction.");
//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.");
//Null assignment throws
async_test(t => {
testWindowThrows(t, null, document);
}, "`document.open(null)` throws.");
</script>
</body>
</html>