Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /trusted-types/trusted-types-tojson.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta http-equiv="Content-Security-Policy" content="trusted-types foo">
</head>
<body>
<script>
test(t => {
let policy = trustedTypes.createPolicy("foo", {
createHTML: h => h,
createScript: s => s,
createScriptURL: u => u,
});
assert_equals(JSON.stringify({"x": policy.createHTML("<p>foo</p>")}),
"{\"x\":\"<p>foo</p>\"}");
assert_equals(JSON.stringify({"x": policy.createScript("foo(bar)")}),
"{\"x\":\"foo(bar)\"}");
}, "toJSON");
</script>
</body>