Commit 479e2775 authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

Test invisible-static elements upgrading when created with HTML parser

Invisible-static custom elements are still upgraded when they are
constructed through HTML parser. To make it clear, we are adding test
to confirm this behavior. This CL also make the previous test's
custom element constructor to not append a child to verify upgrades.

Previous change that defer upgrades of invisible="static" elements:
https://chromium-review.googlesource.com/c/chromium/src/+/1204373

Bug: 873057
Change-Id: If25afa4c1c77ecd70988d3d29cc5ab020247b8ea
Reviewed-on: https://chromium-review.googlesource.com/1235265
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592710}
parent ff082c92
...@@ -13,10 +13,17 @@ ...@@ -13,10 +13,17 @@
<script> <script>
'use strict'; 'use strict';
let upgraded = false;
let connected = false;
class TestElement extends HTMLElement { class TestElement extends HTMLElement {
constructor() { constructor() {
super(); super();
this.innerHTML = "upgraded"; upgraded = true;
}
connectedCallback() {
connected = true;
} }
} }
...@@ -29,51 +36,98 @@ function setUp() { ...@@ -29,51 +36,98 @@ function setUp() {
normal.innerHTML = basicInvisible.innerHTML = staticInvisible.innerHTML = ""; normal.innerHTML = basicInvisible.innerHTML = staticInvisible.innerHTML = "";
basicInvisible.invisible = "invisible"; basicInvisible.invisible = "invisible";
staticInvisible.invisible = "static"; staticInvisible.invisible = "static";
connected = upgraded = false;
} }
test(() => { test(() => {
setUp(); setUp();
normal.innerHTML = testElementString; normal.innerHTML = testElementString;
assert_true(upgraded);
assert_true(connected);
setUp();
basicInvisible.innerHTML = testElementString; basicInvisible.innerHTML = testElementString;
assert_true(upgraded);
assert_true(connected);
setUp();
staticInvisible.innerHTML = testElementString; staticInvisible.innerHTML = testElementString;
assert_equals(normal.innerHTML, testElementUpgradedString); assert_false(upgraded);
assert_equals(basicInvisible.innerHTML, testElementUpgradedString); assert_false(connected);
assert_equals(staticInvisible.innerHTML, testElementString);
}, "Custom elements inside invisible-static subtree is not upgraded."); }, "Custom elements inside invisible-static subtree is not upgraded.");
test(() => { test(() => {
setUp(); setUp();
staticInvisible.removeAttribute("invisible"); staticInvisible.removeAttribute("invisible");
staticInvisible.innerHTML = testElementString; staticInvisible.innerHTML = testElementString;
assert_equals(staticInvisible.innerHTML, testElementUpgradedString); assert_true(upgraded);
assert_true(connected);
}, "Previously-static subtree should not block custom element upgrade"); }, "Previously-static subtree should not block custom element upgrade");
test(() => { test(() => {
setUp(); setUp();
staticInvisible.innerHTML = testElementString; staticInvisible.innerHTML = testElementString;
staticInvisible.invisible = "invisible"; staticInvisible.invisible = "invisible";
assert_equals(staticInvisible.innerHTML, testElementUpgradedString); assert_true(upgraded);
assert_true(connected);
}, "Making an element not invisible='static' upgrades the custom elements inside"); }, "Making an element not invisible='static' upgrades the custom elements inside");
test(() => { test(() => {
setUp(); setUp();
staticInvisible.innerHTML = testElementString; staticInvisible.innerHTML = testElementString;
assert_equals(staticInvisible.innerHTML, testElementString, "Normally not upgraded"); assert_false(upgraded);
assert_false(connected);
customElements.upgrade(staticInvisible); customElements.upgrade(staticInvisible);
assert_equals(staticInvisible.innerHTML, testElementUpgradedString, "After forcing got upgraded"); assert_true(upgraded);
assert_true(connected);
}, "Upgrade by customElements.upgrade is not deferred"); }, "Upgrade by customElements.upgrade is not deferred");
test(() => { test(() => {
setUp(); setUp();
staticInvisible.innerHTML = "<another-element></another-element>"; staticInvisible.innerHTML = "<another-element></another-element>";
let anotherUpgraded = false;
let anotherConnected = false;
customElements.define("another-element", class extends HTMLElement { customElements.define("another-element", class extends HTMLElement {
constructor() { constructor() {
super(); super();
this.innerHTML = "upgraded"; anotherUpgraded = true;
}
connectedCallback() {
anotherConnected = true;
} }
}); });
assert_equals(staticInvisible.innerHTML, "<another-element></another-element>"); assert_false(anotherUpgraded);
assert_false(anotherConnected);
staticInvisible.invisible = "invisible"; staticInvisible.invisible = "invisible";
assert_equals(staticInvisible.innerHTML, "<another-element>upgraded</another-element>"); assert_true(anotherUpgraded);
assert_true(anotherConnected);
}, "Upgrade after defined is deferred"); }, "Upgrade after defined is deferred");
setUp();
</script> </script>
<test-element id="parserEl" invisible="static"></test-element>
<script>
test(() => {
assert_true(upgraded);
assert_true(connected);
}, "Invisible static custom element is upgraded if constructed through HTML parser.");
setUp();
</script>
<div>
<test-element></test-element>
</div>
<script>
test(() => {
assert_true(upgraded);
assert_true(connected);
}, "Custom element under invisible static element made through HTML parser is upgraded.");
</script>
</body>
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