Commit 403403ee authored by Mason Freed's avatar Mason Freed Committed by Commit Bot

Serialize delegatesFocus in getInnerHTML()

Prior to this CL, the getInnerHTML() call with includeShadowRoots=true
would not return markup with the shadowrootdelegatesfocus attribute.
Now, it does, and testing has been added to verify this behavior.

Bug: 1042130
Change-Id: Ibd859af110328b965e4c9a0074095a5a1e5251b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285288
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Auto-Submit: Mason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786393}
parent ed050878
...@@ -45,10 +45,6 @@ ...@@ -45,10 +45,6 @@
namespace blink { namespace blink {
namespace {
const char kShadowRootAttributeName[] = "shadowroot";
}
class MarkupAccumulator::NamespaceContext final { class MarkupAccumulator::NamespaceContext final {
USING_FAST_MALLOC(MarkupAccumulator::NamespaceContext); USING_FAST_MALLOC(MarkupAccumulator::NamespaceContext);
...@@ -572,9 +568,11 @@ std::pair<Node*, Element*> MarkupAccumulator::GetAuxiliaryDOMTree( ...@@ -572,9 +568,11 @@ std::pair<Node*, Element*> MarkupAccumulator::GetAuxiliaryDOMTree(
// element. // element.
auto* template_element = MakeGarbageCollected<Element>( auto* template_element = MakeGarbageCollected<Element>(
html_names::kTemplateTag, &(element.GetDocument())); html_names::kTemplateTag, &(element.GetDocument()));
template_element->setAttribute( template_element->setAttribute(html_names::kShadowrootAttr, shadowroot_type);
QualifiedName(g_null_atom, kShadowRootAttributeName, g_null_atom), if (shadow_root->delegatesFocus()) {
shadowroot_type); template_element->SetBooleanAttribute(
html_names::kShadowrootdelegatesfocusAttr, true);
}
return std::pair<Node*, Element*>(shadow_root, template_element); return std::pair<Node*, Element*>(shadow_root, template_element);
} }
......
...@@ -38,6 +38,7 @@ function testElementType(allowed, nochildren, elementType, mode, delegatesFocus) ...@@ -38,6 +38,7 @@ function testElementType(allowed, nochildren, elementType, mode, delegatesFocus)
// TODO(masonfreed): Add a check for ElementInternals.shadowRoot once that exists. // TODO(masonfreed): Add a check for ElementInternals.shadowRoot once that exists.
assert_true(!!element.shadowRoot, 'Shadow root should be present'); assert_true(!!element.shadowRoot, 'Shadow root should be present');
assert_equals(element.shadowRoot.innerHTML, shadowContent, 'Correct shadow content'); assert_equals(element.shadowRoot.innerHTML, shadowContent, 'Correct shadow content');
assert_equals(element.shadowRoot.delegatesFocus,delegatesFocus,'Correct delegatesFocus')
originalShadowRoot = element.shadowRoot; originalShadowRoot = element.shadowRoot;
} }
......
...@@ -20,7 +20,8 @@ function testElementType(allowsShadowDom, elementType, mode, delegatesFocus) { ...@@ -20,7 +20,8 @@ function testElementType(allowsShadowDom, elementType, mode, delegatesFocus) {
const isOpen = mode === 'open'; const isOpen = mode === 'open';
if (allowsShadowDom) { if (allowsShadowDom) {
const correctShadowHtml = `<template shadowroot="${mode}"><slot></slot></template>`; const delegatesAttr = delegatesFocus ? ' shadowrootdelegatesfocus=""' : '';
const correctShadowHtml = `<template shadowroot="${mode}"${delegatesAttr}><slot></slot></template>`;
const correctHtml = `<${elementType}>${correctShadowHtml}</${elementType}>`; const correctHtml = `<${elementType}>${correctShadowHtml}</${elementType}>`;
const shadowRoot = element.attachShadow({mode: mode, delegatesFocus: delegatesFocus}); const shadowRoot = element.attachShadow({mode: mode, delegatesFocus: delegatesFocus});
shadowRoot.appendChild(document.createElement('slot')); shadowRoot.appendChild(document.createElement('slot'));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment