Skip to content

Commit

Permalink
Only check for matching mode in attachShadow
Browse files Browse the repository at this point in the history
Per the new-new consensus, attachShadow will only verify that
the existing declarative shadow root's `mode` matches the newly
requested `mode`:

whatwg/html#10107 (comment)

Bug: 41483062
Change-Id: Ie3bac4ec297c0b85c40b45495e9c823dd47cb49e
  • Loading branch information
Mason Freed authored and chromium-wpt-export-bot committed Feb 14, 2024
1 parent 2736c7f commit d67e0c4
Showing 1 changed file with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,43 @@
assert_equals(shadow,initialShadow,'Same shadow should be returned');
assert_equals(shadow.textContent,'','Shadow should be empty');
},'Calling attachShadow() on declarative shadow root must match type');
</script>

<div id=open2>
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable>
Open, delegates focus (not the default), clonable (not the default)
named slot assignment (the default)
</template>
</div>
function getDeclarativeHost(t) {
const wrapper = document.createElement('div');
wrapper.setHTMLUnsafe(`<div>
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable serializable>
Open, delegates focus (not the default), clonable (not the default)
serializable (not the default), named slot assignment (the default)
</template>
</div>`);
t.add_cleanup(() => wrapper.remove());
document.body.appendChild(wrapper);
return wrapper.querySelector('div');
}

<script>
test((t) => {
// Changing the type should throw.
let host = getDeclarativeHost(t);
assert_true(!!host.shadowRoot);
assert_throws_dom("NotSupportedError",() => {
open2.attachShadow({mode: "closed", delegatesFocus: true, slotAssignment: "named", clonable: true});
host.attachShadow({mode: "closed"});
},'Mismatched shadow root type should throw');
assert_throws_dom("NotSupportedError",() => {
open2.attachShadow({mode: "open", delegatesFocus: false, slotAssignment: "named", clonable: true});
},'Mismatched shadow root delegatesFocus should throw');
assert_throws_dom("NotSupportedError",() => {
open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "manual", clonable: true});
},'Mismatched shadow root slotAssignment should throw');
assert_throws_dom("NotSupportedError",() => {
open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: false});
},'Mismatched shadow root clonable should throw');
host.attachShadow({mode: "closed", delegatesFocus: true, slotAssignment: "named", clonable: true, serializable: true});
},'Mismatched shadow root type should throw (explicit args)');

const initialShadow = open2.shadowRoot;
const shadow = open2.attachShadow({mode: "open", delegatesFocus: true, slotAssignment: "named", clonable: true}); // Shouldn't throw
assert_equals(shadow,initialShadow,'Same shadow should be returned');
assert_equals(shadow.textContent,'','Shadow should be empty');
// Changing other things should not throw, and should not change the shadow root's settings
const initialShadow = host.shadowRoot;
assert_equals(initialShadow.delegatesFocus,true);
assert_equals(initialShadow.slotAssignment,"named");
assert_true(initialShadow.clonable);
assert_true(initialShadow.serializable);
let newShadow = host.attachShadow({mode: "open", delegatesFocus: false, slotAssignment: "manual", clonable: false, serializable: false});
assert_equals(newShadow,initialShadow,'Same shadow should be returned');
assert_equals(newShadow.textContent,'','Shadow should be empty');
assert_equals(newShadow.delegatesFocus,true);
assert_equals(newShadow.slotAssignment,"named");
assert_true(newShadow.clonable);
assert_true(newShadow.serializable);
},'Calling attachShadow() on declarative shadow root must match all parameters');
</script>

0 comments on commit d67e0c4

Please sign in to comment.