From 77940fdc18d9b489e47523ac131f86b8ce32f629 Mon Sep 17 00:00:00 2001 From: Mason Freed Date: Mon, 5 Apr 2021 12:24:19 -0700 Subject: [PATCH] Make changes to declarative Shadow DOM getInnerHTML API See [1] for more context, but this CL makes the following changes to the declarative Shadow DOM getInnerHTML API: 1. Rename getInnerHTML to getComposedInnerHTML 2. Rename includeShadowRoots to includeOpenShadowRoots 3. Rename closedRoots to shadowRoots 4. Change behavior so that the options are more independent, and either can be used without the other. Mostly, the above is a rename operation, with the exception of #4. There, the logic change is relatively minor, mostly happening in markup_accumulator.cc around line 564. Note: this also fixes the MeasureAs vs. RuntimeCallStats. [1] https://github.com/mfreed7/declarative-shadow-dom/issues/9#issuecomment-809793894 Bug: 1042130 Change-Id: Ie4a0b18a2ef28f17b97eca33c018f7479fc20de8 Cq-Do-Not-Cancel-Tryjobs: true --- ...ml => getcomposedinnerhtml.tentative.html} | 27 ++++++++++--------- .../declarative/script-access.tentative.html | 6 ++--- 2 files changed, 18 insertions(+), 15 deletions(-) rename shadow-dom/declarative/{getinnerhtml.tentative.html => getcomposedinnerhtml.tentative.html} (58%) diff --git a/shadow-dom/declarative/getinnerhtml.tentative.html b/shadow-dom/declarative/getcomposedinnerhtml.tentative.html similarity index 58% rename from shadow-dom/declarative/getinnerhtml.tentative.html rename to shadow-dom/declarative/getcomposedinnerhtml.tentative.html index 52a484760d9567..5f559bac866678 100644 --- a/shadow-dom/declarative/getinnerhtml.tentative.html +++ b/shadow-dom/declarative/getcomposedinnerhtml.tentative.html @@ -1,5 +1,5 @@ -getInnerHTML +getComposedInnerHTML @@ -35,24 +35,27 @@ shadowRoot.appendChild(document.createElement('slot')); if (isOpen) { // We can only test this for open roots - assert_equals(wrapper.getInnerHTML(),correctHtml,'The default for includeShadowRoots should be true'); + assert_equals(wrapper.getComposedInnerHTML(),correctHtml,'The default for includeOpenShadowRoots should be true'); } else { - // Closed shadow roots should not be returned unless closedRoots contains the shadow root: + // Closed shadow roots should not be returned unless shadowRoots array contains the shadow root: const emptyElement = `<${elementType}>`; - assert_equals(wrapper.getInnerHTML({includeShadowRoots: true}), emptyElement); - assert_equals(wrapper.getInnerHTML({includeShadowRoots: true, closedRoots: []}), emptyElement); + assert_equals(wrapper.getComposedInnerHTML({includeOpenShadowRoots: true}), emptyElement); + assert_equals(wrapper.getComposedInnerHTML({includeOpenShadowRoots: true, shadowRoots: []}), emptyElement); } - assert_equals(wrapper.getInnerHTML({includeShadowRoots: true, closedRoots: [shadowRoot]}),correctHtml); + // If shadowRoots contains the shadow root, open or closed, it should be serialized. + assert_equals(wrapper.getComposedInnerHTML({includeOpenShadowRoots: true, shadowRoots: [shadowRoot]}),correctHtml); + assert_equals(wrapper.getComposedInnerHTML({includeOpenShadowRoots: false, shadowRoots: [shadowRoot]}),correctHtml); + assert_equals(wrapper.getComposedInnerHTML({shadowRoots: [shadowRoot]}),correctHtml); } else { - // For non-shadow hosts, getInnerHTML() should also match .innerHTML - assert_equals(wrapper.getInnerHTML({includeShadowRoots: true}),wrapper.innerHTML); - assert_equals(wrapper.getInnerHTML(),wrapper.innerHTML); + // For non-shadow hosts, getComposedInnerHTML() should also match .innerHTML + assert_equals(wrapper.getComposedInnerHTML({includeOpenShadowRoots: true}),wrapper.innerHTML); + assert_equals(wrapper.getComposedInnerHTML(),wrapper.innerHTML); } - // Either way, make sure getInnerHTML({includeShadowRoots: false}) matches .innerHTML - assert_equals(wrapper.getInnerHTML({includeShadowRoots: false}),wrapper.innerHTML,'getInnerHTML() with includeShadowRoots false should return the same as .innerHTML'); + // Either way, make sure getComposedInnerHTML({includeOpenShadowRoots: false}) matches .innerHTML + assert_equals(wrapper.getComposedInnerHTML({includeOpenShadowRoots: false}),wrapper.innerHTML,'getComposedInnerHTML() with includeOpenShadowRoots false should return the same as .innerHTML'); - }, `${applyToShadow ? 'ShadowRoot' : 'Element'}.getInnerHTML() on <${elementType}>${allowsShadowDom ? `, with mode=${mode}, delegatesFocus=${delegatesFocus}.` : ''}`); + }, `${applyToShadow ? 'ShadowRoot' : 'Element'}.getComposedInnerHTML() on <${elementType}>${allowsShadowDom ? `, with mode=${mode}, delegatesFocus=${delegatesFocus}.` : ''}`); } function runAllTests() { diff --git a/shadow-dom/declarative/script-access.tentative.html b/shadow-dom/declarative/script-access.tentative.html index 66d4b948cbbaec..4fa9f2b63d82ba 100644 --- a/shadow-dom/declarative/script-access.tentative.html +++ b/shadow-dom/declarative/script-access.tentative.html @@ -20,13 +20,13 @@ assert_in_array(shadowroot, ['open','closed'], 'Declarative template should have shadowroot attribute'); assert_equals(n.content, null, 'Declarative template content should be null'); assert_equals(n.innerHTML, "", 'Declarative template innerHTML should be empty'); - assert_equals(n.getInnerHTML({includeShadowRoots: true}), "", 'Declarative template getInnerHTML() should be empty'); + assert_equals(n.getComposedInnerHTML({includeOpenShadowRoots: true}), "", 'Declarative template getComposedInnerHTML() should be empty'); // Make sure removing the shadowroot attribute doesn't affect things. n.removeAttribute('shadowroot'); assert_equals(n.content, null, 'Declarative template content should *still* be null'); assert_equals(n.innerHTML, "", 'Declarative template innerHTML should *still* be empty'); - assert_equals(n.getInnerHTML({includeShadowRoots: true}), "", 'Declarative template getInnerHTML() should *still* be empty'); + assert_equals(n.getComposedInnerHTML({includeOpenShadowRoots: true}), "", 'Declarative template getComposedInnerHTML() should *still* be empty'); // Try cloning the in-progress declarative template - shouldn't work. const clone = n.cloneNode(true); @@ -39,7 +39,7 @@ n.setAttribute('shadowroot','open'); assert_not_equals(n.content, null, 'Regular template should have content, even after adding shadowroot attribute'); assert_not_equals(n.innerHTML, "", 'Regular template should have innerHTML, even after adding shadowroot attribute'); - assert_not_equals(n.getInnerHTML({includeShadowRoots: true}), "", 'Regular template should have getInnerHTML(), even after adding shadowroot attribute'); + assert_not_equals(n.getComposedInnerHTML({includeOpenShadowRoots: true}), "", 'Regular template should have getComposedInnerHTML(), even after adding shadowroot attribute'); break; default: assert_unreached('Unrecognized template');