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 13, 2024
1 parent 2380ac0 commit 722d4a1
Showing 1 changed file with 30 additions and 20 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 div = document.createElement('div');
div.setHTMLUnsafe(`
<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>
`);
t.add_cleanup(() => div.remove());
document.body.appendChild(div);
return div;
}

<script>
test((t) => {
// Changing the type should throw.
let host = getDeclarativeHost(t);
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');
// Changing other things should not throw, and should not change the shadow root's settings
host = getDeclarativeHost(t);
assert_equals(host.delegatesFocus,true);
assert_equals(host.slotAssignment,"named");
assert_true(host.clonable);
assert_true(host.serializable);
const initialShadow = host.shadowRoot;
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(shadow.textContent,'','Shadow should be empty');
assert_equals(host.delegatesFocus,true);
assert_equals(host.slotAssignment,"named");
assert_true(host.clonable);
assert_true(host.serializable);
},'Calling attachShadow() on declarative shadow root must match all parameters');
</script>

0 comments on commit 722d4a1

Please sign in to comment.