summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/shadow-dom/focus/resources
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/shadow-dom/focus/resources
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/shadow-dom/focus/resources')
-rw-r--r--testing/web-platform/tests/shadow-dom/focus/resources/shadow-utils.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/testing/web-platform/tests/shadow-dom/focus/resources/shadow-utils.js b/testing/web-platform/tests/shadow-dom/focus/resources/shadow-utils.js
new file mode 100644
index 0000000000..8033ce0169
--- /dev/null
+++ b/testing/web-platform/tests/shadow-dom/focus/resources/shadow-utils.js
@@ -0,0 +1,80 @@
+// Structure:
+// <div #aboveHost>
+// <div #host>
+// #shadowRoot
+// <div #aboveSlot>
+// <slot #slotAbove>
+// (slotted) <div #slottedAbove>
+// <slot #slotBelow>
+// (slotted) <div #slottedBelow>
+// <div #belowSlot>
+// <div #belowHost>
+function prepareDOM(container, delegatesFocus) {
+
+ const aboveHost = document.createElement("div");
+ aboveHost.innerText = "aboveHost";
+ const host = document.createElement("div");
+ host.id = "host";
+ const slottedBelow = document.createElement("div");
+ slottedBelow.innerText = "slotted below";
+ slottedBelow.slot = "below";
+ const slottedAbove = document.createElement("div");
+ slottedAbove.innerText = "slotted above";
+ slottedAbove.slot = "above";
+
+ const belowHost = document.createElement("div");
+ belowHost.innerText = "belowHost";
+ container.appendChild(aboveHost);
+ container.appendChild(host);
+ container.appendChild(belowHost);
+ host.appendChild(slottedBelow);
+ host.appendChild(slottedAbove);
+ const shadowRoot = host.attachShadow({ mode: "open", delegatesFocus: delegatesFocus});
+ const aboveSlot = document.createElement("div");
+ aboveSlot.innerText = "aboveSlot";
+
+ const slotAbove = document.createElement("slot");
+ slotAbove.name = "above";
+ const slotBelow = document.createElement("slot");
+ slotBelow.name = "below";
+
+ const belowSlot = document.createElement("div");
+ belowSlot.innerText = "belowSlot";
+ shadowRoot.appendChild(aboveSlot);
+ shadowRoot.appendChild(slotAbove);
+ shadowRoot.appendChild(slotBelow);
+ shadowRoot.appendChild(belowSlot);
+
+ return [aboveHost, host, aboveSlot, slotAbove, slottedAbove, slotBelow, slottedBelow, belowSlot, belowHost];
+}
+
+function setTabIndex(elements, value) {
+ for (const el of elements) {
+ el.tabIndex = value;
+ }
+}
+
+function removeTabIndex(elements) {
+ for (const el of elements) {
+ el.removeAttribute("tabindex");
+ }
+}
+
+function resetFocus(root = document) {
+ if (root.activeElement)
+ root.activeElement.blur();
+}
+
+function navigateFocusForward() {
+ // TAB = '\ue004'
+ return test_driver.send_keys(document.body, "\ue004");
+}
+
+async function assertFocusOrder(expectedOrder) {
+ const shadowRoot = document.getElementById("host").shadowRoot;
+ for (const el of expectedOrder) {
+ await navigateFocusForward();
+ const focused = shadowRoot.activeElement ? shadowRoot.activeElement : document.activeElement;
+ assert_equals(focused, el);
+ }
+}