From e03faa12a86fced56d076740e95fc7557db5eac4 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Wed, 26 Jul 2023 17:29:49 -0700 Subject: [PATCH] Fix cloning of templates with DOM Parts, and improve testing This CL improves the testing of template cloning with Parts, testing these four cases: 1. Main document parsing 2. Template (content fragment) parsing 3. Template/fragment cloning 4. Declarative Shadow DOM parsing and cloning This CL fixes the behavior for #3 above, but leaves #4 broken. The following changes in behavior are made: 1. Part::MoveToRoot() can be used to change the root(), including to set it to nullptr. This happens when a Node tree is removed from the DOM, and it contains Parts that refer to the old root. 2. IsDocumentPartRoot() is now virtual, because during a tree move, the root() for a Part can be made nullptr even when it's a ChildNodePart. 3. Part::disconnected_ is added to keep track of whether the Part has been disconnected, since root() can now be nullptr. 4. (This is a bug fix) When using ChildNodePart::setNextSibling(), the new sibling node wasn't having its Part registered with NodeRareData, which caused a CHECK failure when trying to subsequently clone that Part. This is caught in the new test which clones declaratively-built templates containing Parts. Bug: 1453291 Change-Id: Ic1c1475431cf6bd658f191db78003204412ef78f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4713668 Reviewed-by: David Baron Auto-Submit: Mason Freed Commit-Queue: Mason Freed Cr-Commit-Position: refs/heads/main@{#1175782} --- .../basic-dom-part-objects.tentative.html | 162 +++++++++++++----- 1 file changed, 115 insertions(+), 47 deletions(-) diff --git a/dom/parts/basic-dom-part-objects.tentative.html b/dom/parts/basic-dom-part-objects.tentative.html index ee35298e5dabbb..3dda4e492c2198 100644 --- a/dom/parts/basic-dom-part-objects.tentative.html +++ b/dom/parts/basic-dom-part-objects.tentative.html @@ -30,6 +30,8 @@ B-sub2 C + + @@ -258,11 +281,12 @@
- Declarative syntax - The template below (with id=declarative) should have - IDENTICAL STRUCTURE. There are three cases to test: + Declarative syntax - The *two* templates below should have IDENTICAL STRUCTURE + to this one. There are four cases to test: 1. Main document parsing (this chunk) - 2. Template parsing (the template below) - 3. Template/fragment cloning (the clone of the template below) + 2. Template parsing (the template below with id=declarative) + 3. Template/fragment cloning (a clone of the template with id=declarative) + 4. Declarative Shadow DOM parsing (template with id=declarative_shadow_dom and shadowrootmode attribute)

First @@ -277,7 +301,7 @@

-

+
+
+ +