blob: 9b8cabe58359e664e1ad9d8c43f604f88c7b3784 [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 replacements do not throw.
test(t => {
let p = createURL_policy(window, 1);
let url = p.createURL(location.href + "#xxx");
location.replace(url);
assert_equals("" + url, location.href, "location href");
}, "location.replace via policy (successful URL transformation).");
// String replacements throw.
test(t => {
assert_throws(new TypeError(), _ => {
location.replace("A string");
});
}, "`location.replace = string` throws");
// Null replacement throws.
test(t => {
assert_throws(new TypeError(), _ => {
location.replace(null);
});
}, "`location.replace = 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.replace("potato");
assert_true(location.href.endsWith("#potato"));
}, "`location.replace = string` via default policy (successful URL transformation).");
// After default policy creation null assignment implicitly calls createURL.
test(t => {
location.replace(null);
assert_true(location.href.endsWith("#null"));
}, "`location.replace = null` via default policy (successful URL transformation).");
</script>