1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<!DOCTYPE html>
<html>
<head>
<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
<link rel="help" href="https://github.com/whatwg/html/issues/10854">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
class GlobalABElement extends HTMLElement {};
customElements.define('a-b', GlobalABElement);
test(() => {
const shadowRoot = document.createElement('div').attachShadow({mode: 'closed'});
assert_equals(shadowRoot.customElementRegistry, window.customElements);
}, 'A newly attached disconnected ShadowRoot should use the global registry by default');
test(() => {
const host = document.body.appendChild(document.createElement('div'));
const shadowRoot = host.attachShadow({mode: 'closed'});
assert_equals(shadowRoot.customElementRegistry, window.customElements);
}, 'A newly attached connected ShadowRoot should use the global registry by default');
test(() => {
const registry = new CustomElementRegistry;
const shadowRoot = document.createElement('div').attachShadow({mode: 'closed', customElementRegistry: registry});
assert_equals(shadowRoot.customElementRegistry, registry);
}, 'A newly attached disconnected ShadowRoot should use the scoped registry if explicitly specified in attachShadow');
test(() => {
const registry = new CustomElementRegistry;
const host = document.body.appendChild(document.createElement('div'));
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: registry});
assert_equals(shadowRoot.customElementRegistry, registry);
}, 'A newly attached connected ShadowRoot should use the scoped registry if explicitly specified in attachShadow');
test(() => {
const host = document.body.appendChild(document.createElement('div'));
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
assert_equals(shadowRoot.customElementRegistry, null);
}, 'attachShadow() should use null registry when customElementRegistry is null (host uses global registry)');
test(() => {
const registry = new CustomElementRegistry;
const host = document.body.appendChild(document.createElement('div', {customElementRegistry: registry}));
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
assert_equals(shadowRoot.customElementRegistry, null);
}, 'attachShadow() should use null registry when customElementRegistry is null (host uses custom registry)');
test((test) => {
const host = document.createElement('div');
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
assert_equals(shadowRoot.customElementRegistry, null);
}, `attchShadow on a builtin element with null customElementRegistry should create a ShadowRoot with null registry`);
test((test) => {
const host = document.createElement('c-d');
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
assert_equals(shadowRoot.customElementRegistry, null);
}, `attchShadow on a custom elememnt candidate with null customElementRegistry should create a ShadowRoot with null registry`);
test((test) => {
const host = document.createElement('a-b');
const shadowRoot = host.attachShadow({mode: 'closed', customElementRegistry: null});
assert_equals(shadowRoot.customElementRegistry, null);
}, `attchShadow on a custom elememnt with null customElementRegistry should create a ShadowRoot with null registry`);
test(() => {
const registry = new CustomElementRegistry;
const template = document.createElement('template');
template.innerHTML = '<div></div>';
const host = template.content.cloneNode(true).firstChild;
assert_equals(host.customElementRegistry, null);
const shadowRoot = host.attachShadow({mode: 'open', customElementRegistry: null, clonable: true});
assert_equals(shadowRoot.customElementRegistry, null);
shadowRoot.innerHTML = '<span></span>';
assert_equals(shadowRoot.querySelector('span').customElementRegistry, null);
const cloneHost = host.cloneNode(true);
assert_equals(cloneHost.customElementRegistry, null);
assert_equals(cloneHost.shadowRoot.customElementRegistry, null);
assert_equals(cloneHost.shadowRoot.querySelector('span').customElementRegistry, null);
}, 'attachShadow() should use the null registry when the shadow host uses null registry and customElementRegistry is null');
</script>
</body>
</html>
|