Files
sousa-gecko/testing/web-platform/tests/domparsing/tentative/resources/util.js
T
Noam Rosenthal 04f0d3f21b Bug 2046739 [wpt PR 60553] - Revise HTML update methods order of operations, a=testonly
Automatic update from web-platform-tests
Revise HTML update methods order of operations

Ensure a consistent order of operations for all the new HTML insertion
methods (appendHTML, prependHTML, beforeHTML, afterHTML,
replaceWithHTML)

- The trusted types createHTML test should always come first
- ChildNode methods should then ensure the parent can accept HTML, or throw
- Correctly handle <template> in all the methods
  (e.g. `template.appendHTML`, `template.content.beforeHTML`)
- Assert some edge cases in WPT (e.g. trusted types moves nodes around)

See spec PR: https://github.com/whatwg/html/pull/12528

Bug: 491743369
Change-Id: I5e587ae12faad3d706e2d993bd1aa88500b3e6be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7915261
Commit-Queue: Noam Rosenthal <nrosenthal@google.com>
Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1645229}

--

wpt-commits: 264d3bdd2145be1e35d8a8845b9b62b38fa8fc1c
wpt-pr: 60553
2026-06-16 11:35:22 +00:00

66 lines
1.8 KiB
JavaScript

function prepare_html_partial_update(target_type, ref_type, pos, t) {
let target;
let template;
if (target_type === "template.content") {
template = document.createElement("template");
target = template.content;
} else {
const div = document.createElement("div");
document.body.append(div);
t.add_cleanup(() => div.remove());
target = div;
if (target_type === "ShadowRoot") {
target = div.attachShadow({ mode: "open" });
}
}
let ref = document.createElement("span");
switch (ref_type) {
case "Element":
ref.textContent = "ref;";
break;
case "Comment":
ref = document.createComment("ref;");
break;
case "Text":
ref = document.createTextNode("ref;");
break;
case "ProcessingInstruction":
ref = document.createProcessingInstruction("ref", "");
break;
default:
throw new Error("Invalid ref_type");
}
target.append(ref);
let object;
if (["append", "prepend"].includes(pos)) {
object = (target_type === "template.content") ? template : target;
} else {
object = ref;
}
return { target, ref, object };
}
function check_position(target, pos, ref) {
switch (pos) {
case "before":
assert_equals(target.firstChild.textContent, "html;");
assert_equals(target.firstChild.nextSibling, ref);
break;
case "prepend":
assert_equals(target.textContent, "html;ref;");
break;
case "after":
assert_equals(target.lastChild.textContent, "html;");
assert_equals(target.firstChild, ref);
break;
case "append":
assert_equals(target.textContent, "ref;html;");
break;
case "replaceWith":
assert_equals(target.textContent, "html;");
assert_equals(target.firstChild, target.lastChild);
break;
}
}