blob: 86bce7994d6e9e43bddc590519126f4ee266cf06 [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>
// TrustedURL assignments do not throw.
test(t => {
let p = createURL_policy(window, 1);
let url = p.createURL(location.href + "#xxx");
location.href = url;
assert_equals("" + url, location.href, "location href");
}, "location.href assigned via policy (successful URL transformation).");
// String assignments throw.
test(t => {
let href = location.href;
assert_throws(new TypeError(), _ => {
location.href = 'A string';
});
assert_equals(location.href, href);
}, "`location.href = string` throws");
// Null assignment throws.
test(t => {
let href = location.href;
assert_throws(new TypeError(), _ => {
location.href = null;
});
assert_equals(location.href, href);
}, "`location.href = null` throws");
// Create default policy. Applies to all subsequent tests.
let p = window.TrustedTypes.createPolicy("default",
{ createURL: createLocationURLJS }, true);
// After default policy creation string assignment implicitly calls createURL.
test(t => {
location.href = "xxxx";
assert_true(location.href.endsWith("#xxxx"));
}, "`location.href = string` via default policy (successful URL transformation).");
// After default policy creation null assignment implicitly calls createURL.
test(t => {
location.href = null;
assert_true(location.href.endsWith("#null"));
}, "`location.href = null` assigned via default policy does not throw.");
</script>