Skip to content

add tests around shadowroot element creation in scoped registries #46170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<meta name="author" title="Westbrook Johnson" href="mailto:[email protected]">
<meta name="assert" content="Custom Elements should upgrade createElements without conflicts">
<link rel="help" href="https://wicg.github.io/webcomponents/proposals/Scoped-Custom-Element-Registries">
<link rel="help" href="https://github.com/WICG/webcomponents/issues/969">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id="testdiv"></div>

<script>
class TestAutonomousGlobal extends HTMLElement {};
customElements.define('test-element', TestAutonomousGlobal);

class TestAutonomousScoped extends HTMLElement {};

function attachShadowForTest(t, registry) {
const host = document.createElement('div');
const shadow = host.attachShadow({mode: 'open', registry});
document.body.appendChild(host);
t.add_cleanup(() => host.remove());
return shadow;
}

test(t => {
const registry = new CustomElementRegistry;
registry.define('test-element', TestAutonomousScoped);

const shadow = attachShadowForTest(t, registry);
assert_true(shadow.createElement('test-element') instanceof TestAutonomousScoped);

}, 'Upgrade into autonomous custom element when inserted via innerHTML');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<meta name="author" title="Westbrook Johnson" href="mailto:[email protected]">
<meta name="assert" content="Custom Elements in scoped registries take precedence over global scope">
<link rel="help" href="https://wicg.github.io/webcomponents/proposals/Scoped-Custom-Element-Registries">
<link rel="help" href="https://github.com/WICG/webcomponents/issues/969">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<div id="testdiv"></div>

<script>
class TestAutonomousGlobal extends HTMLElement {};
customElements.define('test-element', TestAutonomousGlobal);

class TestAutonomousScoped extends HTMLElement {};

function attachShadowForTest(t, registry) {
const host = document.createElement('div');
const shadow = host.attachShadow({mode: 'open', registry});
document.body.appendChild(host);
t.add_cleanup(() => host.remove());
return shadow;
}

test(t => {
const registry = new CustomElementRegistry;
registry.define('test-element', TestAutonomousScoped);

const shadow = attachShadowForTest(t, registry);
shadow.innerHTML = '<test-element></test-element>';
assert_true(shadow.firstChild instanceof TestAutonomousScoped, 'should be TestAutonomousScoped');

}, 'Update into autonomous custom element should not use the global registry when scoped element is defined');

</script>