From 91e42694d29c23fbc075e7c89af3c23d53101dd0 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Thu, 9 May 2024 14:13:50 +0100 Subject: [PATCH] WebKit export of https://bugs.webkit.org/show_bug.cgi?id=273412 --- .../Document-write-exception-order.xhtml | 42 +++++++++++++++++++ ...ignment-to-Element-insertAdjacentHTML.html | 35 ++++++++++++++++ ...tring-assignment-to-Element-outerHTML.html | 13 ++++++ 3 files changed, 90 insertions(+) create mode 100644 trusted-types/Document-write-exception-order.xhtml diff --git a/trusted-types/Document-write-exception-order.xhtml b/trusted-types/Document-write-exception-order.xhtml new file mode 100644 index 00000000000000..db7c0631243477 --- /dev/null +++ b/trusted-types/Document-write-exception-order.xhtml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.html b/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.html index 228887d0423d31..e4fec3a8a70dbf 100644 --- a/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.html +++ b/trusted-types/block-string-assignment-to-Element-insertAdjacentHTML.html @@ -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("

Fail

")); + }); + + 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'); @@ -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', "

Fail

"); + }); + + 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'); diff --git a/trusted-types/block-string-assignment-to-Element-outerHTML.html b/trusted-types/block-string-assignment-to-Element-outerHTML.html index 9b6cf72cb4017c..acf5a42622ca9d 100644 --- a/trusted-types/block-string-assignment-to-Element-outerHTML.html +++ b/trusted-types/block-string-assignment-to-Element-outerHTML.html @@ -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('

Content

'); + }); + }, "`outerHTML = TrustedHTML` throws NoModificationAllowedError when parent is a document."); + // String assignments throw. test(t => { var d = document.createElement('div'); @@ -38,6 +45,12 @@ container.firstChild.remove(); }, "`outerHTML = string` throws."); + test(t => { + assert_throws_js(TypeError, _ => { + document.documentElement.outerHTML = '

Content

'; + }); + }, "`outerHTML = string` throws TypeError even when parent is a document."); + // Null assignment throws. test(t => { var d = document.createElement('div');