summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/declarative/script-access.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/shadow-dom/declarative/script-access.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/shadow-dom/declarative/script-access.html')
-rw-r--r--testing/web-platform/tests/shadow-dom/declarative/script-access.html119
1 files changed, 119 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shadow-dom/declarative/script-access.html b/testing/web-platform/tests/shadow-dom/declarative/script-access.html
new file mode 100644
index 0000000000..7e1340d477
--- /dev/null
+++ b/testing/web-platform/tests/shadow-dom/declarative/script-access.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<title>Declarative Shadow DOM</title>
+<link rel='author' href='mailto:masonf@chromium.org'>
+<link rel='help' href='https://github.com/whatwg/dom/issues/831'>
+<script src='/resources/testharness.js'></script>
+<script src='/resources/testharnessreport.js'></script>
+
+<body>
+<script>
+let templatesSeen = 0;
+
+function myObserver(mutationsList, observer) {
+ document.querySelectorAll('.host').forEach(n => {
+ templatesSeen++;
+ n.className = 'done';
+ switch (n.id) {
+ case 'openhost':
+ case 'closedhost':
+ assert_equals(n.querySelector('template'),null,'No template ever for streaming declarative Shadow DOM');
+ assert_equals(n.innerHTML, "", 'Declarative shadow host innerHTML should be empty - all content is inside shadow');
+ break;
+ case 'noroot':
+ const template = n.querySelector('template');
+ assert_true(!!template,'Regular template should still be present');
+ // Make sure adding 'shadowrootmode' attribute doesn't trigger a shadow root,
+ // even if added before parsing completes.
+ template.setAttribute('shadowrootmode','open');
+ assert_not_equals(template.content, null, 'Regular template should have content, even after adding shadowrootmode attribute');
+ assert_not_equals(template.innerHTML, "", 'Regular template should have innerHTML, even after adding shadowrootmode attribute');
+ break;
+ default:
+ assert_unreached('Unrecognized template');
+ }
+ });
+}
+const observer = new MutationObserver(myObserver);
+observer.observe(document.body, { childList: true, subtree: true });
+assert_equals(templatesSeen, 0, 'No mutations yet');
+</script>
+
+<div id=openhost class=host><template shadowrootmode=open>
+ <slot></slot>
+ <!-- Ensure observer runs at this point (https://github.com/web-platform-tests/wpt/issues/35393) -->
+ <script> // some content, which shouldn't be necessary </script>
+</template></div>
+
+<div id=closedhost class=host><template shadowrootmode=closed>
+ <slot></slot>
+ <!-- Ensure observer runs at this point (https://github.com/web-platform-tests/wpt/issues/35393) -->
+ <script> // some content, which shouldn't be necessary </script>
+</template></div>
+
+<div id=noroot class=host><template>
+ <slot></slot>
+ <!-- Ensure observer runs at this point (https://github.com/web-platform-tests/wpt/issues/35393) -->
+ <script> // some content, which shouldn't be necessary </script>
+</template></div>
+
+<script>
+test(t => {
+ t.add_cleanup(function() { observer.disconnect(); });
+
+ assert_equals(templatesSeen, 3);
+
+ // Open shadow root
+ let host = document.querySelector('#openhost');
+ assert_equals(host.querySelector('template'), null, 'No template nodes');
+ assert_true(!!host.shadowRoot, 'Shadow root should exist');
+
+ // Closed shadow root
+ host = document.querySelector('#closedhost');
+ assert_equals(host.querySelector('template'), null, 'No template nodes');
+ assert_true(!host.shadowRoot, 'Closed shadow root (can\'t detect)');
+
+ // No shadow root
+ host = document.querySelector('#noroot');
+ assert_true(!!host.querySelector('template'), 'Template node still present for invalid shadowrootmode value');
+ assert_true(!host.shadowRoot, 'No shadow root');
+},'Streaming Declarative Shadow DOM: template .content() should be null');
+</script>
+
+
+<script>
+let synchronous_events_received = new Set();
+function synchronousHandler(e) {
+ synchronous_events_received.add(e.type);
+}
+const sync_events = ["DOMAttrModified","DOMAttributeNameChanged","DOMCharacterDataModified",
+ "DOMElementNameChanged","DOMNodeInserted","DOMNodeInsertedIntoDocument","DOMNodeRemoved",
+ "DOMNodeRemovedFromDocument","DOMSubtreeModified"];
+function addSyncObserver(evt) {
+ window.addEventListener(evt, synchronousHandler, true);
+}
+function removeSyncObserver(evt) {
+ window.removeEventListener(evt, synchronousHandler, true);
+}
+sync_events.forEach(e => addSyncObserver(e));
+</script>
+
+<div id=synchost1>
+ <template shadowrootmode=open>
+ <div class=foo>content</div>
+ <slot></slot>
+ </template>
+</div>
+
+<div id=synchost2>
+ <template shadowrootmode=closed>
+ <div class=foo>content</div>
+ <slot></slot>
+ </template>
+</div>
+
+<script>
+test(t => {
+ t.add_cleanup(function() { sync_events.forEach(e => removeSyncObserver(e)) });
+ assert_true(!synchronous_events_received.size,`Synchronous mutation events fired: ${Array.from(synchronous_events_received)}`);
+},'Synchronous mutation events should not be fired during streaming declarative shadow DOM parsing');
+</script>