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,325598615
Change-Id: Ie3bac4ec297c0b85c40b45495e9c823dd47cb49e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5283935
Commit-Queue: Mason Freed <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Commit-Queue: Di Zhang <[email protected]>
Reviewed-by: Di Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1262014}
  • Loading branch information
mfreed7 authored and chromium-wpt-export-bot committed Feb 17, 2024
1 parent a415844 commit a092215
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions shadow-dom/declarative/declarative-shadow-dom-repeats.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,48 @@
test((t) => {
assert_throws_dom("NotSupportedError",() => {
open1.attachShadow({mode: "closed"});
},'Mismatched shadow root type should throw');
},'Mismatched shadow root mode should throw');
const initialShadow = open1.shadowRoot;
const shadow = open1.attachShadow({mode: "open"}); // Shouldn't throw
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');
},'Calling attachShadow() on declarative shadow root must match mode');
</script>

<div id=open2>
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable>
<template shadowrootmode=open shadowrootdelegatesfocus shadowrootclonable serializable>
Open, delegates focus (not the default), clonable (not the default)
named slot assignment (the default)
serializable (not the default), named slot assignment (the default)
</template>
</div>

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

// Changing other things should not throw, and should not change the shadow root's settings
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');

assert_equals(initialShadow.delegatesFocus,true);
assert_equals(initialShadow.slotAssignment,"named");
assert_true(initialShadow.clonable);
assert_true(initialShadow.serializable);
let newShadow = open2.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);
assert_throws_dom("NotSupportedError",() => {
open2.attachShadow({mode: "open"});
},'Invoking attachShadow() on a non-declarative shadow root should throw');

},'Calling attachShadow() on declarative shadow root must match all parameters');
</script>

0 comments on commit a092215

Please sign in to comment.