Skip to content
Merged
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
78 changes: 42 additions & 36 deletions custom-elements/registries/element-mutation.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,55 @@

<script>

test(() => {
const registry = new CustomElementRegistry;
function runTests(mutation, mutationName) {
test(() => {
const registry = new CustomElementRegistry;

const element = document.createElement('new-element');
assert_equals(element.customElementRegistry, window.customElements);
const element = document.createElement('new-element');
assert_equals(element.customElementRegistry, window.customElements);

document.body.appendChild(element);
const shadow = document.createElement('div').attachShadow({mode: 'open', customElementRegistry: registry})
shadow.appendChild(element)
assert_not_equals(element.customElementRegistry, registry);
mutation(document.body, element);
const shadow = document.createElement('div').attachShadow({mode: 'open', customElementRegistry: registry})
mutation(shadow, element);
assert_not_equals(element.customElementRegistry, registry);

document.body.appendChild(element)
assert_equals(element.customElementRegistry, window.customElements);
}, "An element with global registry should not change its registry when moved into a shadow tree with scoped registry.")
mutation(document.body, element);
assert_equals(element.customElementRegistry, window.customElements);
}, "An element with global registry should not change its registry when run " + mutationName + " into a shadow tree with scoped registry.")

test(() => {
const clone = host.cloneNode(true);
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
const element = shadowRoot1.querySelector('#shadow-host-1-child');
test(() => {
const clone = host.cloneNode(true);
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
const element = shadowRoot1.querySelector('#shadow-host-1-child');

const registry1 = new CustomElementRegistry;
registry1.initialize(shadowRoot1);
assert_equals(element.customElementRegistry, registry1);
const registry1 = new CustomElementRegistry;
registry1.initialize(shadowRoot1);
assert_equals(element.customElementRegistry, registry1);

document.querySelector('#host').appendChild(element);
assert_equals(element.customElementRegistry, registry1);
}, "An element with scoped registry should not change its registry when moved out of the shadow tree.")
mutation(document.querySelector('#host'), element);
assert_equals(element.customElementRegistry, registry1);
}, "An element with scoped registry should not change its registry when run " + mutationName + " out of the shadow tree.")

test(() => {
const clone = host.cloneNode(true);
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
const shadowRoot2 = clone.querySelector('#shadow-host-2').shadowRoot;
const element = shadowRoot1.querySelector('#shadow-host-1-child');

const registry1 = new CustomElementRegistry;
const registry2 = new CustomElementRegistry;
registry1.initialize(shadowRoot1);
registry2.initialize(shadowRoot2);
assert_equals(element.customElementRegistry, registry1);

shadowRoot2.appendChild(element);
assert_equals(element.customElementRegistry, registry1);
}, "An element with scoped registry should not change its registry when moved into another shadow tree with different scoped registry.")
test(() => {
const clone = host.cloneNode(true);
const shadowRoot1 = clone.querySelector('#shadow-host-1').shadowRoot;
const shadowRoot2 = clone.querySelector('#shadow-host-2').shadowRoot;
const element = shadowRoot1.querySelector('#shadow-host-1-child');

const registry1 = new CustomElementRegistry;
const registry2 = new CustomElementRegistry;
registry1.initialize(shadowRoot1);
registry2.initialize(shadowRoot2);
assert_equals(element.customElementRegistry, registry1);

mutation(shadowRoot2, element);
assert_equals(element.customElementRegistry, registry1);
}, "An element with scoped registry should not change its registry when run " + mutationName + " into another shadow tree with different scoped registry.")
};

runTests(function (parent, child) { parent.append(child); }, "append");
runTests(function (parent, child) { parent.appendChild(child); }, "appendChild");
runTests(function (parent, child) { parent.prepend(child); }, "prepend");

test(() => {
customElements.define('x-foo', class extends HTMLElement {});
Expand Down