blob: 7b917dbf642302e0d21e5a688850d8f822f0c318 [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="trusted-types *">
</head>
<body>
<script>
var testnb = 0;
// helper functions for the tests
function testWindowOpen(t, win, nb) {
let p = createURL_policy(window, nb);
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, nb) {
let p = createURL_policy(window, nb);
assert_throws(new TypeError(), _ => {
let child_window = win.open(url, "", "");
child_window.close();
});
}
// TrustedURL assignments do not throw.
test(t => {
testWindowOpen(t, window, ++testnb);
}, "window.open via policy (successful URL transformation).");
test(t => {
testWindowOpen(t, document, ++testnb);
}, "document.open via policy (successful URL transformation).");
// String assignments throw.
test(t => {
testWindowThrows(t, 'A string', window, ++testnb);
}, "`window.open(string)` throws.");
test(t => {
testWindowThrows(t, 'A string', document, ++testnb);
}, "`document.open(string)` throws.");
// Null assignment throws.
test(t => {
testWindowThrows(t, null, window, ++testnb);
}, "`window.open(null)` throws.");
test(t => {
testWindowThrows(t, null, document, ++testnb);
}, "`document.open(null)` throws.");
</script>
</body>
</html>