|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>ElementInternals.shadowRoot</title> |
| 4 | +<link rel=" author" title=" Mason Freed" href=" mailto:[email protected]" > |
| 5 | +<link rel="help" href="https://github.com/w3c/webcomponents/issues/871"> |
| 6 | +<script src="/resources/testharness.js"></script> |
| 7 | +<script src="/resources/testharnessreport.js"></script> |
| 8 | + |
| 9 | +<script> |
| 10 | + |
| 11 | +test(() => { |
| 12 | + let constructed = false; |
| 13 | + customElements.define('custom-open', class extends HTMLElement { |
| 14 | + constructor() { |
| 15 | + super(); |
| 16 | + const elementInternals = this.attachInternals(); |
| 17 | + assert_equals(elementInternals.shadowRoot, null); |
| 18 | + const shadow = this.attachShadow({mode: 'open'}); |
| 19 | + assert_equals(elementInternals.shadowRoot, shadow); |
| 20 | + constructed = true; |
| 21 | + } |
| 22 | + }); |
| 23 | + const element = document.createElement('custom-open'); |
| 24 | + assert_true(constructed); |
| 25 | +}, 'ElementInternals.shadowRoot allows access to open shadow root'); |
| 26 | + |
| 27 | +test(() => { |
| 28 | + let constructed = false; |
| 29 | + customElements.define('custom-closed', class extends HTMLElement { |
| 30 | + constructor() { |
| 31 | + super(); |
| 32 | + const elementInternals = this.attachInternals(); |
| 33 | + assert_equals(elementInternals.shadowRoot, null); |
| 34 | + const shadow = this.attachShadow({mode: 'closed'}); |
| 35 | + assert_equals(elementInternals.shadowRoot, shadow); |
| 36 | + assert_equals(this.shadowRoot, null); |
| 37 | + constructed = true; |
| 38 | + } |
| 39 | + }); |
| 40 | + const element = document.createElement('custom-closed'); |
| 41 | + assert_true(constructed); |
| 42 | +}, 'ElementInternals.shadowRoot allows access to closed shadow root'); |
| 43 | + |
| 44 | +</script> |
0 commit comments