|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>Declarative Shadow DOM Element Attachment</title> |
| 3 | +<link rel=' author' href=' mailto:[email protected]' > |
| 4 | +<link rel='help' href='https://github.com/whatwg/dom/issues/1235'> |
| 5 | +<link rel='help' href='https://github.com/whatwg/html/pull/10069'> |
| 6 | +<link rel='help' href='https://github.com/whatwg/dom/pull/1246'> |
| 7 | + |
| 8 | +<script src='/resources/testharness.js'></script> |
| 9 | +<script src='/resources/testharnessreport.js'></script> |
| 10 | +<script src='../../html/resources/common.js'></script> |
| 11 | +<script src="support/helpers.js"></script> |
| 12 | + |
| 13 | +<div id=multiple1> |
| 14 | + <template shadowrootmode=open>Open</template> |
| 15 | + <template shadowrootmode=closed>Closed</template> |
| 16 | +</div> |
| 17 | + |
| 18 | +<div id=multiple2> |
| 19 | + <template shadowrootmode=closed>Closed</template> |
| 20 | + <template shadowrootmode=open>Open</template> |
| 21 | +</div> |
| 22 | + |
| 23 | +<script> |
| 24 | +test((t) => { |
| 25 | + let shadow = multiple1.shadowRoot; |
| 26 | + assert_true(!!shadow,'Remaining shadow root should be open'); |
| 27 | + assert_equals(shadow.textContent,"Open"); |
| 28 | + shadow = multiple2.shadowRoot; |
| 29 | + assert_false(!!shadow,'Remaining shadow root should be closed'); |
| 30 | + multiple1.remove(); // Cleanup |
| 31 | + multiple2.remove(); |
| 32 | +},'Repeated declarative shadow roots keep only the first'); |
| 33 | +</script> |
| 34 | + |
| 35 | +<div id=open1> |
| 36 | + <template shadowrootmode=open>Open</template> |
| 37 | +</div> |
| 38 | + |
| 39 | +<script> |
| 40 | +test((t) => { |
| 41 | + assert_throws_dom("NotSupportedError",() => { |
| 42 | + open1.attachShadow({mode: "closed"}); |
| 43 | + },'Mismatched shadow root type should throw'); |
| 44 | + const initialShadow = open1.shadowRoot; |
| 45 | + const shadow = open1.attachShadow({mode: "open"}); // Shouldn't throw |
| 46 | + assert_equals(shadow,initialShadow,'Same shadow should be returned'); |
| 47 | + assert_equals(shadow.textContent,'','Shadow should be empty'); |
| 48 | +},'Calling attachShadow() on declarative shadow root must match type'); |
| 49 | +</script> |
| 50 | + |
| 51 | +<div id=open2> |
| 52 | + <template shadowrootmode=open shadowrootdelegatesfocus> |
| 53 | + Open, delegates focus (not the default), named slot assignment (the default) |
| 54 | + </template> |
| 55 | +</div> |
| 56 | + |
| 57 | +<script> |
| 58 | +test((t) => { |
| 59 | + assert_throws_dom("NotSupportedError",() => { |
| 60 | + open2.attachShadow({mode: "closed", delegatesFocus: true, slotAssignment: "named"}); |
| 61 | + },'Mismatched shadow root type should throw'); |
| 62 | + assert_throws_dom("NotSupportedError",() => { |
| 63 | + open2.attachShadow({mode: "open", delegatesFocus: false, slotAssignment: "named"}); |
| 64 | + },'Mismatched shadow root delegatesFocus should throw'); |
| 65 | + assert_throws_dom("NotSupportedError",() => { |
| 66 | + open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "manual"}); |
| 67 | + },'Mismatched shadow root slotAssignment should throw'); |
| 68 | + const initialShadow = open2.shadowRoot; |
| 69 | + const shadow = open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named"}); // Shouldn't throw |
| 70 | + assert_equals(shadow,initialShadow,'Same shadow should be returned'); |
| 71 | + assert_equals(shadow.textContent,'','Shadow should be empty'); |
| 72 | +},'Calling attachShadow() on declarative shadow root must match all parameters'); |
| 73 | +</script> |
0 commit comments