Skip to content

Commit

Permalink
Bug 1902153 [wpt PR 46723] - Add a DOM Parts mode that does not cache…
Browse files Browse the repository at this point in the history
… parts at all, a=testonly

Automatic update from web-platform-tests
Add a DOM Parts mode that does not cache parts at all

This CL adds a new (default-off) feature flag called
DOMPartsAPIMinimal, which when enabled eliminates caching of the
parts list at all times. This should minimize the overhead of
cloning and appending DOM that contains DOM Parts, while lengthening
the time required for getParts().

This patch only supports NodeParts and ChildNodeParts, but not
AttributeParts. For that reason, many of the tests fail, when
AttributeParts are involved.

Bug: 40271855
Change-Id: If0103138144a24a0930978fc0bcd8e8d6006516c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5605785
Reviewed-by: David Baron <dbaron@chromium.org>
Commit-Queue: Mason Freed <masonf@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1314364}

--

wpt-commits: aa5fb603d51ab03ca00384fbc4a92a053ee47eeb
wpt-pr: 46723
  • Loading branch information
mfreed7 authored and moz-wptsync-bot committed Jun 18, 2024
1 parent b880c5f commit ef6402e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
</div>

<script>
function assertIsComment(node,commentText) {
function assertIsComment(node, commentText) {
assert_true(node instanceof Comment);
assert_equals(node.textContent,commentText);
// TODO(crbug.com/40271855): While developing alternative syntax, the comment might be empty or it might be "S"/"E".
assert_true(node.textContent === '' || node.textContent === commentText);
}

const declarativeOpenerNoParseparts = '<h1>';
Expand All @@ -32,21 +33,21 @@
const root = contextEl.content ? contextEl.content.getPartRoot() : document.getPartRoot();
assert_equals(root.getParts().length,0,'Should start with no parts');
t.add_cleanup(() => {
contextEl.replaceChildren();
(contextEl.content || contextEl).replaceChildren();
root.getParts().forEach(part => part.disconnect());
});
contextEl.innerHTML = content;
if (expectParts) {
let expectedRootParts = [{type:'ChildNodePart',metadata:[]}];
assertEqualParts(root.getParts(),expectedRootParts,0,'declarative root missing parts');
const childPart1 = root.getParts()[0];
assertIsComment(childPart1.previousSibling,'');
assertIsComment(childPart1.nextSibling,'');
assertIsComment(childPart1.previousSibling,'S');
assertIsComment(childPart1.nextSibling,'E');
const expectedChild1Parts = [{type:'ChildNodePart',metadata:[]}];
assertEqualParts(childPart1.getParts(),expectedChild1Parts,0,'First level childpart should just have one child part');
const childPart2 = childPart1.getParts()[0];
assertIsComment(childPart2.previousSibling,'');
assertIsComment(childPart2.nextSibling,'');
assertIsComment(childPart2.previousSibling,'S');
assertIsComment(childPart2.nextSibling,'E');
const expectedChild2Parts = [{type:'NodePart',metadata:[]}];
assertEqualParts(childPart2.getParts(),expectedChild2Parts,0,'Second level childpart should have just the node part');
assert_true(childPart2.getParts()[0].node instanceof HTMLSpanElement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ function assertEqualParts(parts,partDescriptions,expectedParts,description) {
for(let i=0;i<parts.length;++i) {
assert_true(parts[i] instanceof Part,`${description}: not a Part`);
assert_true(parts[i] instanceof window[partDescriptions[i].type],`${description}: index ${i} expected ${partDescriptions[i].type}`);
assert_array_equals(parts[i].metadata,partDescriptions[i].metadata,`${description}: index ${i} wrong metadata`);
// TODO(crbug.com/40271855): While developing alternative syntax, we aren't comparing the metadata:
// assert_array_equals(parts[i].metadata,partDescriptions[i].metadata,`${description}: index ${i} wrong metadata`);
if (expectedParts) {
assert_equals(parts[i],expectedParts[i],`${description}: index ${i} object equality`);
// TODO(crbug.com/40271855): While developing alternative syntax, we aren't comparing equality of the Part objects:
// assert_equals(parts[i],expectedParts[i],`${description}: index ${i} object equality`);
assert_equals(parts[i].root.getPartNode(i),parts[i].node || parts[i].previousSibling,'getPartNode() should return the same node as getParts().node/previousSibling');
}
}
Expand Down

0 comments on commit ef6402e

Please sign in to comment.