Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebKit export of https://bugs.webkit.org/show_bug.cgi?id=273412 #46185

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions trusted-types/Document-write-exception-order.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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-for 'script';" />
</head>
<body>
<script>
test(t => {
const old = document.body.innerText;
assert_throws_js(TypeError, _ => {
document.write('A string');
});
assert_equals(document.body.innerText, old);
}, "`document.write(string)` throws TypeError");

let p = createHTML_policy(window, 1);
test(t => {
const old = document.body.innerText;
assert_throws_dom("InvalidStateError", _ => {
document.write(p.createHTML('A string'));
});
assert_equals(document.body.innerText, old);
}, "`document.write(TrustedHTML)` throws InvalidStateError");

let default_policy = trustedTypes.createPolicy('default',
{ createHTML: createHTMLJS }, true );

test(t => {
const old = document.body.innerText;
assert_throws_dom("InvalidStateError", _ => {
document.write('A string');
});
assert_equals(document.body.innerText, old);
}, "`document.write(string)` w/ default policy throws InvalidStateError");
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
container.firstChild.remove();
}, "insertAdjacentHTML with html assigned via policy (successful HTML transformation).");

test(t => {
let p = createHTML_policy(window, 1);
var d = document.createElement('div');
container.appendChild(d);

assert_throws_dom("SyntaxError", _ => {
d.insertAdjacentHTML('invalid', p.createHTML("<p>Fail</p>"));
});

assert_equals(d.previousSibling, null);
assert_equals(d.firstChild, null);
assert_equals(d.lastChild, null);
assert_equals(d.nextSibling, null);

while (container.firstChild)
container.firstChild.remove();
}, "insertAdjacentHTML(TrustedHTML) throws SyntaxError DOMException when position invalid.");

// String assignments throw.
test(t => {
var d = document.createElement('div');
Expand Down Expand Up @@ -67,6 +85,23 @@
container.firstChild.remove();
}, "`insertAdjacentHTML(string)` throws.");

test(t => {
var d = document.createElement('div');
container.appendChild(d);

assert_throws_js(TypeError, _ => {
d.insertAdjacentHTML('invalid', "<p>Fail</p>");
});

assert_equals(d.previousSibling, null);
assert_equals(d.firstChild, null);
assert_equals(d.lastChild, null);
assert_equals(d.nextSibling, null);

while (container.firstChild)
container.firstChild.remove();
}, "`insertAdjacentHTML(string)` still throws TypeError when position invalid.");

// Null assignment throws.
test(t => {
var d = document.createElement('div');
Expand Down
13 changes: 13 additions & 0 deletions trusted-types/block-string-assignment-to-Element-outerHTML.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
container.firstChild.remove();
}, "outerHTML with html assigned via policy (successful HTML transformation).");

test(t => {
let p = createHTML_policy(window, 1);
assert_throws_dom("NoModificationAllowedError", _ => {
document.documentElement.outerHTML = p.createHTML('<p>Content</p>');
});
}, "`outerHTML = TrustedHTML` throws NoModificationAllowedError when parent is a document.");

// String assignments throw.
test(t => {
var d = document.createElement('div');
Expand All @@ -38,6 +45,12 @@
container.firstChild.remove();
}, "`outerHTML = string` throws.");

test(t => {
assert_throws_js(TypeError, _ => {
document.documentElement.outerHTML = '<p>Content</p>';
});
}, "`outerHTML = string` throws TypeError even when parent is a document.");

// Null assignment throws.
test(t => {
var d = document.createElement('div');
Expand Down