blob: 43ea55a67e08ce1c3086775f0df89f464e505e03 [file] [log] [blame]
TAMURA, Kent4c70b5a2019-02-21 10:06:441<!DOCTYPE html>
2<body>
3<script src="/resources/testharness.js"></script>
4<script src="/resources/testharnessreport.js"></script>
5<link rel="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#dom-attachinternals">
6<div id="container"></div>
7<script>
8test(() => {
9 class MyElement1 extends HTMLElement {
10 }
11 customElements.define('my-element1', MyElement1);
12 const container = document.querySelector('#container');
13
14 let element = new MyElement1();
15 assert_true(element.attachInternals() instanceof ElementInternals,
16 'New - 1st call');
Stephen McGruerd5103042020-01-23 21:45:4517 assert_throws_dom('NotSupportedError', () => { element.attachInternals(); },
Stephen McGruer63c2f712020-01-25 14:26:1618 'New - 2nd call');
TAMURA, Kent4c70b5a2019-02-21 10:06:4419
20 element = document.createElement('my-element1');
21 assert_true(element.attachInternals() instanceof ElementInternals,
22 'createElement - 1st call');
Stephen McGruerd5103042020-01-23 21:45:4523 assert_throws_dom('NotSupportedError', () => { element.attachInternals(); },
Stephen McGruer63c2f712020-01-25 14:26:1624 'createElement - 2nd call');
TAMURA, Kent4c70b5a2019-02-21 10:06:4425
26 container.innerHTML = '<my-element1></my-element1>';
27 assert_true(container.firstChild.attachInternals() instanceof ElementInternals,
28 'Parser - 1st call');
Stephen McGruerd5103042020-01-23 21:45:4529 assert_throws_dom('NotSupportedError', () => {
TAMURA, Kent4c70b5a2019-02-21 10:06:4430 container.firstChild.attachInternals();
31 }, 'Parser - 2nd call');
32}, 'Successful attachInternals() and the second call.');
33
34test(() => {
35 class MyDiv extends HTMLDivElement {}
36 customElements.define('my-div', MyDiv, { extends: 'div' });
37 const customizedBuiltin = document.createElement('div', { is: 'my-div'});
Stephen McGruerd5103042020-01-23 21:45:4538 assert_throws_dom('NotSupportedError', () => { customizedBuiltin.attachInternals() });
TAMURA, Kent4c70b5a2019-02-21 10:06:4439}, 'attachInternals() throws a NotSupportedError if it is called for ' +
40 'a customized built-in element');
41
42test(() => {
43 const builtin = document.createElement('div');
Stephen McGruerd5103042020-01-23 21:45:4544 assert_throws_dom('NotSupportedError', () => { builtin.attachInternals() });
TAMURA, Kent4c70b5a2019-02-21 10:06:4445
46 const doc = document.implementation.createDocument('foo', null);
47 const span = doc.appendChild(doc.createElementNS('http://www.w3.org/1999/xhtml', 'html:span'));
48 assert_true(span instanceof HTMLElement);
Stephen McGruerd5103042020-01-23 21:45:4549 assert_throws_dom('NotSupportedError', () => { span.attachInternals(); });
TAMURA, Kent4c70b5a2019-02-21 10:06:4450
51 const undefinedCustom = document.createElement('undefined-element');
Stephen McGruerd5103042020-01-23 21:45:4552 assert_throws_dom('NotSupportedError', () => { undefinedCustom.attachInternals() });
TAMURA, Kent4c70b5a2019-02-21 10:06:4453}, 'If a custom element definition for the local name of the element doesn\'t' +
Domenic Denicoladc4519e2019-05-15 23:30:2054 ' exist, throw an NotSupportedError');
TAMURA, Kent4c70b5a2019-02-21 10:06:4455
56test(() => {
57 class MyElement2 extends HTMLElement {
58 static get disabledFeatures() { return ['internals']; }
59 }
60 customElements.define('my-element2', MyElement2);
61 const container = document.querySelector('#container');
62
Stephen McGruerd5103042020-01-23 21:45:4563 assert_throws_dom('NotSupportedError', () => {
TAMURA, Kent4c70b5a2019-02-21 10:06:4464 (new MyElement2).attachInternals();
65 });
Stephen McGruerd5103042020-01-23 21:45:4566 assert_throws_dom('NotSupportedError', () => {
TAMURA, Kent4c70b5a2019-02-21 10:06:4467 document.createElement('my-element2').attachInternals();
68 });
Stephen McGruerd5103042020-01-23 21:45:4569 assert_throws_dom('NotSupportedError', () => {
TAMURA, Kent4c70b5a2019-02-21 10:06:4470 container.innerHTML = '<my-element2></my-element2>';
71 container.firstChild.attachInternals();
72 });
73
74 class MyElement3 extends HTMLElement {
75 static get disabledFeatures() { return ['INTERNALS']; }
76 }
77 customElements.define('my-element3', MyElement3);
78 assert_true((new MyElement3).attachInternals() instanceof ElementInternals);
79}, 'If a custom element definition for the local name of the element has ' +
80 'disable internals flag, throw a NotSupportedError');
81</script>
82</body>