|
46 | 46 | assert_equals(shadow,initialShadow,'Same shadow should be returned');
|
47 | 47 | assert_equals(shadow.textContent,'','Shadow should be empty');
|
48 | 48 | },'Calling attachShadow() on declarative shadow root must match type');
|
49 |
| -</script> |
50 | 49 |
|
51 |
| -<div id=open2> |
52 |
| - <template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable> |
53 |
| - Open, delegates focus (not the default), clonable (not the default) |
54 |
| - named slot assignment (the default) |
55 |
| - </template> |
56 |
| -</div> |
| 50 | +function getDeclarativeHost(t) { |
| 51 | + const div = document.createElement('div'); |
| 52 | + div.setHTMLUnsafe(` |
| 53 | + <template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable serializable> |
| 54 | + Open, delegates focus (not the default), clonable (not the default) |
| 55 | + serializable (not the default), named slot assignment (the default) |
| 56 | + </template> |
| 57 | + `); |
| 58 | + t.add_cleanup(() => div.remove()); |
| 59 | + document.body.appendChild(div); |
| 60 | + return div; |
| 61 | +} |
57 | 62 |
|
58 |
| -<script> |
59 | 63 | test((t) => {
|
| 64 | + // Changing the type should throw. |
| 65 | + let host = getDeclarativeHost(t); |
60 | 66 | assert_throws_dom("NotSupportedError",() => {
|
61 |
| - open2.attachShadow({mode: "closed", delegatesFocus: true, slotAssignment: "named", clonable: true}); |
| 67 | + host.attachShadow({mode: "closed"}); |
62 | 68 | },'Mismatched shadow root type should throw');
|
63 | 69 | assert_throws_dom("NotSupportedError",() => {
|
64 |
| - open2.attachShadow({mode: "open", delegatesFocus: false, slotAssignment: "named", clonable: true}); |
65 |
| - },'Mismatched shadow root delegatesFocus should throw'); |
66 |
| - assert_throws_dom("NotSupportedError",() => { |
67 |
| - open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "manual", clonable: true}); |
68 |
| - },'Mismatched shadow root slotAssignment should throw'); |
69 |
| - assert_throws_dom("NotSupportedError",() => { |
70 |
| - open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: false}); |
71 |
| - },'Mismatched shadow root clonable should throw'); |
| 70 | + host.attachShadow({mode: "closed", delegatesFocus: true, slotAssignment: "named", clonable: true, serializable: true}); |
| 71 | + },'Mismatched shadow root type should throw (explicit args)'); |
72 | 72 |
|
73 |
| - const initialShadow = open2.shadowRoot; |
74 |
| - const shadow = open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: true}); // Shouldn't throw |
75 |
| - assert_equals(shadow,initialShadow,'Same shadow should be returned'); |
| 73 | + // Changing other things should not throw, and should not change the shadow root's settings |
| 74 | + host = getDeclarativeHost(t); |
| 75 | + assert_equals(host.delegatesFocus,true); |
| 76 | + assert_equals(host.slotAssignment,"named"); |
| 77 | + assert_true(host.clonable); |
| 78 | + assert_true(host.serializable); |
| 79 | + const initialShadow = host.shadowRoot; |
| 80 | + let newShadow = host.attachShadow({mode: "open", delegatesFocus: false, slotAssignment: "manual", clonable: false, serializable: false}); |
| 81 | + assert_equals(newShadow,initialShadow,'Same shadow should be returned'); |
76 | 82 | assert_equals(shadow.textContent,'','Shadow should be empty');
|
| 83 | + assert_equals(host.delegatesFocus,true); |
| 84 | + assert_equals(host.slotAssignment,"named"); |
| 85 | + assert_true(host.clonable); |
| 86 | + assert_true(host.serializable); |
77 | 87 | },'Calling attachShadow() on declarative shadow root must match all parameters');
|
78 | 88 | </script>
|
0 commit comments