| <!DOCTYPE html> |
| <body> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <div id="container"></div> |
| <script> |
| test(() => { |
| class MyElement1 extends HTMLElement { |
| } |
| customElements.define('my-element1', MyElement1); |
| const container = document.querySelector('#container'); |
| |
| let element = new MyElement1(); |
| assert_true(element.attachInternals() instanceof ElementInternals, |
| 'New - 1st call'); |
| assert_throws('InvalidStateError', () => { element.attachInternals(); }, |
| 'New - 2nd call'); |
| |
| element = document.createElement('my-element1'); |
| assert_true(element.attachInternals() instanceof ElementInternals, |
| 'createElement - 1st call'); |
| assert_throws('InvalidStateError', () => { element.attachInternals(); }, |
| 'createElement - 2nd call'); |
| |
| container.innerHTML = '<my-element1></my-element1>'; |
| assert_true(container.firstChild.attachInternals() instanceof ElementInternals, |
| 'Parser - 1st call'); |
| assert_throws('InvalidStateError', () => { |
| container.firstChild.attachInternals(); |
| }, 'Parser - 2nd call'); |
| }, 'Successful attachInternals() and the second call.'); |
| |
| test(() => { |
| const builtin = document.createElement('div'); |
| assert_throws('InvalidStateError', () => { builtin.attachInternals() }); |
| |
| const undefinedCustom = document.createElement('my-element'); |
| assert_throws('InvalidStateError', () => { undefinedCustom.attachInternals() }); |
| }, 'If a custom element definition for the local name of the element doesn\'t' + |
| ' exist, throw an InvalidStateError'); |
| |
| test(() => { |
| class MyElement2 extends HTMLElement { |
| static get disabledFeatures() { return ['internals']; } |
| } |
| customElements.define('my-element2', MyElement2); |
| const container = document.querySelector('#container'); |
| |
| assert_throws('InvalidStateError', () => { |
| (new MyElement2).attachInternals(); |
| }); |
| assert_throws('InvalidStateError', () => { |
| document.createElement('my-element2').attachInternals(); |
| }); |
| assert_throws('InvalidStateError', () => { |
| container.innerHTML = '<my-element2></my-element2>'; |
| container.firstChild.attachInternals(); |
| }); |
| }, 'If a custom element definition for the local name of the element has ' + |
| 'disable internals flag, throw an InvalidStateError'); |
| </script> |
| </body> |