Skip to content

Commit

Permalink
Make changes to declarative Shadow DOM getInnerHTML API
Browse files Browse the repository at this point in the history
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] mfreed7/declarative-shadow-dom#9 (comment)

Bug: 1042130
Change-Id: Ie4a0b18a2ef28f17b97eca33c018f7479fc20de8
Cq-Do-Not-Cancel-Tryjobs: true
  • Loading branch information
mfreed7 authored and chromium-wpt-export-bot committed Apr 5, 2021
1 parent f37d80e commit 77940fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<title>getInnerHTML </title>
<title>getComposedInnerHTML </title>
<link rel='author' href='mailto:[email protected]'>
<link rel='help' href='https://github.com/whatwg/dom/issues/831'>
<script src='/resources/testharness.js'></script>
Expand Down Expand Up @@ -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}></${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() {
Expand Down
6 changes: 3 additions & 3 deletions shadow-dom/declarative/script-access.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down

0 comments on commit 77940fd

Please sign in to comment.