Skip to content

Truly independent web browser

LibWeb: Import top layer user action coverage

Andreas Kling4a21f02c93b2
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/active-toplayer-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/active-toplayer-001.txt
new file mode 100644
index 00000000000..c4096a7bf54
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/active-toplayer-001.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Fail
+Fail Clicking inside a modal dialog should not propagate :active beyond the dialog.
+Fail Clicking inside a popover should not propagate :active beyond the popover.
+Fail With nested top layer elements, :active should stop at the innermost top layer boundary.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-toplayer-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-toplayer-001.txt
new file mode 100644
index 00000000000..6cc5820a0cc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-toplayer-001.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Fail
+Fail Focusing inside a modal dialog should not propagate :focus-within beyond the dialog.
+Fail Focusing inside a popover should not propagate :focus-within beyond the popover.
+Fail With nested top layer elements, :focus-within should stop at the innermost top layer boundary.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/hover-toplayer-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/hover-toplayer-001.txt
new file mode 100644
index 00000000000..2c0801588f5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/hover-toplayer-001.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Fail
+Fail Hovering inside a modal dialog should not propagate :hover beyond the dialog.
+Fail Hovering inside a popover should not propagate :hover beyond the popover.
+Fail With nested top layer elements, :hover should stop at the innermost top layer boundary.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/toplayer-transition-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/toplayer-transition-001.txt
new file mode 100644
index 00000000000..3a419ca6971
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/toplayer-transition-001.txt
@@ -0,0 +1,7 @@
+Harness status: OK
+
+Found 2 tests
+
+2 Fail
+Fail :focus-within should be adjusted on ancestors when popover enters/exits top layer.
+Fail :hover should be adjusted on ancestors when popover enters/exits top layer.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/user-action-pseudo-top-layer.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/user-action-pseudo-top-layer.txt
new file mode 100644
index 00000000000..66b831ba387
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/user-action-pseudo-top-layer.txt
@@ -0,0 +1,11 @@
+Harness status: OK
+
+Found 4 tests
+
+1 Pass
+2 Fail
+1 Optional Feature Unsupported
+Fail User action pseudo-classes on dialog (modal)
+Pass User action pseudo-classes on dialog (non-modal)
+Fail User action pseudo-classes on popover (popover)
+Optional Feature Unsupported User action pseudo-classes on customizable-select (open)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/active-toplayer-001.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/active-toplayer-001.html
new file mode 100644
index 00000000000..ebffbbf3902
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/active-toplayer-001.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Selectors: :active should not propagate past top layer elements</title>
+<link rel="help" href="https://drafts.csswg.org/selectors/#the-active-pseudo">
+<link rel="help" href="https://drafts.csswg.org/css-position-4/#top-layer">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/testdriver.js"></script>
+<script src="../../resources/testdriver-actions.js"></script>
+<script src="../../resources/testdriver-vendor.js"></script>
+<style>
+ dialog::backdrop {
+ background: transparent;
+ }
+</style>
+
+<div id="outer">
+ <dialog id="dialog">
+ <div id="inner">click target</div>
+ </dialog>
+</div>
+
+<div id="popoverOuter">
+ <div id="popover" popover>
+ <div id="popoverInner">click target</div>
+ </div>
+</div>
+
+<div id="nestOuter">
+ <dialog id="nestDialog">
+ <div id="nestPopover" popover>
+ <div id="nestInner">click target</div>
+ </div>
+ </dialog>
+</div>
+
+<script>
+function captureActiveState(elements, target) {
+ return new Promise(resolve => {
+ target.addEventListener('mousedown', () => {
+ const result = {};
+ for (const [name, el] of Object.entries(elements)) {
+ result[name] = el.matches(':active');
+ }
+ resolve(result);
+ }, {once: true});
+ });
+}
+
+promise_test(async t => {
+ const dialog = document.getElementById('dialog');
+ dialog.showModal();
+ t.add_cleanup(() => dialog.close());
+
+ const inner = document.getElementById('inner');
+ const outer = document.getElementById('outer');
+
+ const statePromise = captureActiveState({
+ inner, dialog, outer, body: document.body
+ }, inner);
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: inner})
+ .pointerDown()
+ .pointerUp()
+ .send();
+
+ const state = await statePromise;
+ assert_true(state.inner, 'inner element should match :active');
+ assert_true(state.dialog, 'dialog (top layer) should match :active');
+ assert_false(state.outer, 'ancestor outside top layer should not match :active');
+ assert_false(state.body, 'body should not match :active');
+}, 'Clicking inside a modal dialog should not propagate :active beyond the dialog.');
+
+promise_test(async t => {
+ const popover = document.getElementById('popover');
+ popover.showPopover();
+ t.add_cleanup(() => popover.hidePopover());
+
+ const popoverInner = document.getElementById('popoverInner');
+ const popoverOuter = document.getElementById('popoverOuter');
+
+ const statePromise = captureActiveState({
+ popoverInner, popover, popoverOuter, body: document.body
+ }, popoverInner);
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: popoverInner})
+ .pointerDown()
+ .pointerUp()
+ .send();
+
+ const state = await statePromise;
+ assert_true(state.popoverInner, 'inner element should match :active');
+ assert_true(state.popover, 'popover (top layer) should match :active');
+ assert_false(state.popoverOuter, 'ancestor outside top layer should not match :active');
+ assert_false(state.body, 'body should not match :active');
+}, 'Clicking inside a popover should not propagate :active beyond the popover.');
+
+promise_test(async t => {
+ const nestDialog = document.getElementById('nestDialog');
+ nestDialog.showModal();
+ t.add_cleanup(() => nestDialog.close());
+
+ const nestPopover = document.getElementById('nestPopover');
+ nestPopover.showPopover();
+ t.add_cleanup(() => nestPopover.hidePopover());
+
+ const nestInner = document.getElementById('nestInner');
+ const nestOuter = document.getElementById('nestOuter');
+
+ const statePromise = captureActiveState({
+ nestInner, nestPopover, nestDialog, nestOuter, body: document.body
+ }, nestInner);
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: nestInner})
+ .pointerDown()
+ .pointerUp()
+ .send();
+
+ const state = await statePromise;
+ assert_true(state.nestInner, 'inner element should match :active');
+ assert_true(state.nestPopover, 'popover (innermost top layer) should match :active');
+ assert_false(state.nestDialog, 'dialog (outer top layer) should not match :active');
+ assert_false(state.nestOuter, 'ancestor outside both top layers should not match :active');
+}, 'With nested top layer elements, :active should stop at the innermost top layer boundary.');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-within-toplayer-001.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-within-toplayer-001.html
new file mode 100644
index 00000000000..edfe5623f87
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/focus-within-toplayer-001.html
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Selectors: :focus-within should not propagate past top layer elements</title>
+<link rel="help" href="https://drafts.csswg.org/selectors/#the-focus-within-pseudo">
+<link rel="help" href="https://drafts.csswg.org/css-position-4/#top-layer">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<style>
+ dialog::backdrop {
+ background: transparent;
+ }
+</style>
+
+<div id="outer">
+ <dialog id="dialog">
+ <input id="dialogInput">
+ </dialog>
+</div>
+
+<div id="popoverOuter">
+ <div id="popover" popover>
+ <input id="popoverInput">
+ </div>
+</div>
+
+<div id="nestOuter">
+ <dialog id="nestDialog">
+ <div id="nestPopover" popover>
+ <input id="nestInput">
+ </div>
+ </dialog>
+</div>
+
+<script>
+test(t => {
+ const dialog = document.getElementById('dialog');
+ dialog.showModal();
+ t.add_cleanup(() => dialog.close());
+
+ const dialogInput = document.getElementById('dialogInput');
+ const outer = document.getElementById('outer');
+
+ dialogInput.focus();
+ assert_true(dialogInput.matches(':focus'), 'input should be focused');
+ assert_true(dialog.matches(':focus-within'), 'dialog (top layer) should match :focus-within');
+ assert_false(outer.matches(':focus-within'), 'ancestor outside top layer should not match :focus-within');
+ assert_false(document.body.matches(':focus-within'), 'body should not match :focus-within');
+}, 'Focusing inside a modal dialog should not propagate :focus-within beyond the dialog.');
+
+test(t => {
+ const popover = document.getElementById('popover');
+ popover.showPopover();
+ t.add_cleanup(() => popover.hidePopover());
+
+ const popoverInput = document.getElementById('popoverInput');
+ const popoverOuter = document.getElementById('popoverOuter');
+
+ popoverInput.focus();
+ assert_true(popoverInput.matches(':focus'), 'input should be focused');
+ assert_true(popover.matches(':focus-within'), 'popover (top layer) should match :focus-within');
+ assert_false(popoverOuter.matches(':focus-within'), 'ancestor outside top layer should not match :focus-within');
+ assert_false(document.body.matches(':focus-within'), 'body should not match :focus-within');
+}, 'Focusing inside a popover should not propagate :focus-within beyond the popover.');
+
+test(t => {
+ const nestDialog = document.getElementById('nestDialog');
+ nestDialog.showModal();
+ t.add_cleanup(() => nestDialog.close());
+
+ const nestPopover = document.getElementById('nestPopover');
+ nestPopover.showPopover();
+ t.add_cleanup(() => nestPopover.hidePopover());
+
+ const nestInput = document.getElementById('nestInput');
+ const nestOuter = document.getElementById('nestOuter');
+
+ nestInput.focus();
+ assert_true(nestInput.matches(':focus'), 'input should be focused');
+ assert_true(nestPopover.matches(':focus-within'), 'popover (innermost top layer) should match :focus-within');
+ assert_false(nestDialog.matches(':focus-within'), 'dialog (outer top layer) should not match :focus-within');
+ assert_false(nestOuter.matches(':focus-within'), 'ancestor outside both top layers should not match :focus-within');
+}, 'With nested top layer elements, :focus-within should stop at the innermost top layer boundary.');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/hover-toplayer-001.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/hover-toplayer-001.html
new file mode 100644
index 00000000000..4cf44ab2761
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/hover-toplayer-001.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Selectors: :hover should not propagate past top layer elements</title>
+<link rel="help" href="https://drafts.csswg.org/selectors/#the-hover-pseudo">
+<link rel="help" href="https://drafts.csswg.org/css-position-4/#top-layer">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/testdriver.js"></script>
+<script src="../../resources/testdriver-actions.js"></script>
+<script src="../../resources/testdriver-vendor.js"></script>
+<style>
+ dialog::backdrop {
+ background: transparent;
+ }
+</style>
+
+<div id="outer">
+ <dialog id="dialog">
+ <div id="inner">hover target</div>
+ </dialog>
+</div>
+
+<div id="popoverOuter">
+ <div id="popover" popover>
+ <div id="popoverInner">hover target</div>
+ </div>
+</div>
+
+<div id="nestOuter">
+ <dialog id="nestDialog">
+ <div id="nestPopover" popover>
+ <div id="nestInner">hover target</div>
+ </div>
+ </dialog>
+</div>
+
+<script>
+promise_test(async t => {
+ const dialog = document.getElementById('dialog');
+ dialog.showModal();
+ t.add_cleanup(() => dialog.close());
+
+ const inner = document.getElementById('inner');
+ const outer = document.getElementById('outer');
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: inner})
+ .send();
+ await new Promise(requestAnimationFrame);
+
+ assert_true(inner.matches(':hover'), 'inner element should match :hover');
+ assert_true(dialog.matches(':hover'), 'dialog (top layer) should match :hover');
+ assert_false(outer.matches(':hover'), 'ancestor outside top layer should not match :hover');
+ assert_false(document.body.matches(':hover'), 'body should not match :hover');
+}, 'Hovering inside a modal dialog should not propagate :hover beyond the dialog.');
+
+promise_test(async t => {
+ const popover = document.getElementById('popover');
+ popover.showPopover();
+ t.add_cleanup(() => popover.hidePopover());
+
+ const popoverInner = document.getElementById('popoverInner');
+ const popoverOuter = document.getElementById('popoverOuter');
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: popoverInner})
+ .send();
+ await new Promise(requestAnimationFrame);
+
+ assert_true(popoverInner.matches(':hover'), 'inner element should match :hover');
+ assert_true(popover.matches(':hover'), 'popover (top layer) should match :hover');
+ assert_false(popoverOuter.matches(':hover'), 'ancestor outside top layer should not match :hover');
+ assert_false(document.body.matches(':hover'), 'body should not match :hover');
+}, 'Hovering inside a popover should not propagate :hover beyond the popover.');
+
+promise_test(async t => {
+ const nestDialog = document.getElementById('nestDialog');
+ nestDialog.showModal();
+ t.add_cleanup(() => nestDialog.close());
+
+ const nestPopover = document.getElementById('nestPopover');
+ nestPopover.showPopover();
+ t.add_cleanup(() => nestPopover.hidePopover());
+
+ const nestInner = document.getElementById('nestInner');
+ const nestOuter = document.getElementById('nestOuter');
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: nestInner})
+ .send();
+ await new Promise(requestAnimationFrame);
+
+ assert_true(nestInner.matches(':hover'), 'inner element should match :hover');
+ assert_true(nestPopover.matches(':hover'), 'popover (innermost top layer) should match :hover');
+ assert_false(nestDialog.matches(':hover'), 'dialog (outer top layer) should not match :hover');
+ assert_false(nestOuter.matches(':hover'), 'ancestor outside both top layers should not match :hover');
+}, 'With nested top layer elements, :hover should stop at the innermost top layer boundary.');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/toplayer-transition-001.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/toplayer-transition-001.html
new file mode 100644
index 00000000000..861ecf479b1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/toplayer-transition-001.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Selectors: top layer transitions should adjust pseudo-classes on ancestors</title>
+<link rel="help" href="https://drafts.csswg.org/selectors/#the-hover-pseudo">
+<link rel="help" href="https://drafts.csswg.org/selectors/#the-focus-within-pseudo">
+<link rel="help" href="https://drafts.csswg.org/css-position-4/#top-layer">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/testdriver.js"></script>
+<script src="../../resources/testdriver-actions.js"></script>
+<script src="../../resources/testdriver-vendor.js"></script>
+<style>
+ [popover] { display: block; }
+</style>
+
+<div id="container">
+ <div id="popover" popover="manual">
+ <input id="input">
+ <div id="hoverTarget">hover here</div>
+ </div>
+</div>
+
+<script>
+promise_test(async t => {
+ t.add_cleanup(() => { if (popover.matches(':popover-open')) popover.hidePopover(); });
+
+ input.focus();
+ assert_true(input.matches(':focus'), 'input should be focused');
+ assert_true(container.matches(':focus-within'), 'container should match :focus-within before showPopover');
+
+ popover.showPopover();
+ assert_true(input.matches(':focus'), 'input should still be focused after showPopover');
+ assert_true(popover.matches(':focus-within'), 'popover should match :focus-within after showPopover');
+ assert_false(container.matches(':focus-within'), 'container should not match :focus-within after showPopover');
+ assert_false(document.body.matches(':focus-within'), 'body should not match :focus-within after showPopover');
+
+ popover.hidePopover();
+ await new Promise(requestAnimationFrame);
+ assert_true(input.matches(':focus'), 'input should still be focused after hidePopover');
+ assert_true(container.matches(':focus-within'), 'container should match :focus-within after hidePopover');
+ assert_true(document.body.matches(':focus-within'), 'body should match :focus-within after hidePopover');
+}, ':focus-within should be adjusted on ancestors when popover enters/exits top layer.');
+
+promise_test(async t => {
+ t.add_cleanup(() => { if (popover.matches(':popover-open')) popover.hidePopover(); });
+
+ await new test_driver.Actions()
+ .pointerMove(1, 1, {origin: hoverTarget})
+ .send();
+ await new Promise(requestAnimationFrame);
+
+ assert_true(hoverTarget.matches(':hover'), 'hoverTarget should match :hover');
+ assert_true(container.matches(':hover'), 'container should match :hover before showPopover');
+
+ popover.showPopover();
+ assert_true(hoverTarget.matches(':hover'), 'hoverTarget should still match :hover after showPopover');
+ assert_true(popover.matches(':hover'), 'popover should match :hover after showPopover');
+ assert_false(container.matches(':hover'), 'container should not match :hover after showPopover');
+ assert_false(document.body.matches(':hover'), 'body should not match :hover after showPopover');
+
+ popover.hidePopover();
+ await new Promise(requestAnimationFrame);
+ assert_true(hoverTarget.matches(':hover'), 'hoverTarget should still match :hover after hidePopover');
+ assert_true(container.matches(':hover'), 'container should match :hover after hidePopover');
+ assert_true(document.body.matches(':hover'), 'body should match :hover after hidePopover');
+}, ':hover should be adjusted on ancestors when popover enters/exits top layer.');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/selectors/user-action-pseudo-top-layer.html b/Tests/LibWeb/Text/input/wpt-import/css/selectors/user-action-pseudo-top-layer.html
new file mode 100644
index 00000000000..f869bd8b89a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/selectors/user-action-pseudo-top-layer.html
@@ -0,0 +1,178 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<link rel="help" href="https://www.w3.org/TR/selectors-4/#useraction-pseudos">
+<meta name="author" href="mailto:[email protected]">
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/testdriver.js"></script>
+<script src="../../resources/testdriver-actions.js"></script>
+<script src="../../resources/testdriver-vendor.js"></script>
+<script src="../../html/semantics/interestfor/resources/invoker-utils.js"></script>
+
+<style>
+/* Make elements large enough to click and separate them to prevent overlap */
+#container * {
+ min-width: 50px;
+ min-height: 50px;
+}
+/* Ensure top layer elements do not overlap with body or container when clicked */
+dialog,
+[popover] {
+ top: 100px;
+ left: 100px;
+ margin: 0;
+}
+select,
+::picker(select) {
+ appearance: base-select;
+}
+</style>
+
+<div id="container"></div>
+
+<script>
+function createTestElement(type, state) {
+ const container = document.getElementById('container');
+
+ let topLayerElement = undefined;
+ let selectElement = undefined;
+ let button;
+
+ if (type === 'popover') {
+ topLayerElement = document.createElement('div');
+ topLayerElement.setAttribute('popover', 'auto');
+ button = document.createElement('button');
+ button.textContent = 'Button';
+ topLayerElement.appendChild(button);
+ container.appendChild(topLayerElement);
+ topLayerElement.showPopover();
+ } else if (type === 'customizable-select') {
+ selectElement = document.createElement('select');
+ button = document.createElement('option');
+ button.textContent = 'Option';
+ selectElement.appendChild(button);
+ container.appendChild(selectElement);
+ // topLayerElement remains undefined because the top layer element
+ // is the select picker pseudo-element which we cannot query directly.
+ } else {
+ topLayerElement = document.createElement('dialog');
+ button = document.createElement('button');
+ button.textContent = 'Button';
+ topLayerElement.appendChild(button);
+ container.appendChild(topLayerElement);
+ if (state === 'modal') {
+ topLayerElement.showModal();
+ } else {
+ topLayerElement.show();
+ }
+ }
+
+ return { container, topLayerElement, selectElement, button };
+}
+
+function cleanUp() {
+ document.getElementById('container').innerHTML = '';
+ // Reset mouse position to avoid state leaking between tests
+ return new test_driver.Actions().pointerMove(0, 0).send();
+}
+
+const tests = [
+ { type: 'dialog', state: 'modal', topLayer: true },
+ { type: 'dialog', state: 'non-modal', topLayer: false },
+ { type: 'popover', state: 'popover', topLayer: true },
+ { type: 'customizable-select', state: 'open', topLayer: true },
+];
+
+tests.forEach(({ type, state, topLayer }) => {
+ promise_test(async (t) => {
+ t.add_cleanup(cleanUp);
+ const { container, topLayerElement, selectElement, button } = createTestElement(type, state);
+
+ if (type === 'customizable-select') {
+ const style = getComputedStyle(selectElement);
+ assert_implements_optional(style.appearance === 'base-select',
+ "appearance: base-select is not supported on this browser");
+
+ await test_driver.bless('open picker');
+ selectElement.showPicker();
+ await waitForRender();
+ assert_true(selectElement.matches(':open'), 'select should be open');
+ }
+
+ await waitForRender();
+
+ // Focus test
+ button.focus();
+ assert_true(button.matches(':focus-within'), 'button has :focus-within');
+ if (topLayerElement) {
+ assert_true(topLayerElement.matches(':focus-within'), `${type} should match :focus-within`);
+ }
+
+ if (topLayer) {
+ assert_false(
+ container.matches(':focus-within'),
+ 'container should not have :focus-within for top layer elements',
+ );
+ assert_false(
+ document.body.matches(':focus-within'),
+ 'body should not have :focus-within for top layer elements',
+ );
+ } else {
+ assert_true(
+ container.matches(':focus-within'),
+ 'container should have :focus-within for non-top layer elements',
+ );
+ assert_true(
+ document.body.matches(':focus-within'),
+ 'body should have :focus-within for non-top layer elements',
+ );
+ }
+ button.blur();
+
+ // Hover test
+ await hoverOver(button);
+
+ assert_true(button.matches(':hover'), 'button has :hover');
+ if (topLayerElement) {
+ assert_true(topLayerElement.matches(':hover'), `${type} should match :hover`);
+ }
+
+ if (topLayer) {
+ assert_false(container.matches(':hover'), 'container should not have :hover for top layer elements');
+ assert_false(document.body.matches(':hover'), 'body should not have :hover for top layer elements');
+ } else {
+ assert_true(container.matches(':hover'), 'container should have :hover for non-top layer elements');
+ assert_true(document.body.matches(':hover'), 'body should have :hover for non-top layer elements');
+ }
+
+ // Active test requires monitoring inside event listener because pointerDown might auto-pointerUp
+ let buttonMatchedActive = false;
+ let topLayerMatchedActive = false;
+ let containerMatchedActive = false;
+ let bodyMatchedActive = false;
+ button.addEventListener('mousedown', () => {
+ buttonMatchedActive = button.matches(':active');
+ if (topLayerElement) {
+ topLayerMatchedActive = topLayerElement.matches(':active');
+ }
+ containerMatchedActive = container.matches(':active');
+ bodyMatchedActive = document.body.matches(':active');
+ });
+
+ await clickOn(button);
+
+ assert_true(buttonMatchedActive, 'button has :active');
+ if (topLayerElement) {
+ assert_true(topLayerMatchedActive, `${type} should match :active`);
+ }
+
+ if (topLayer) {
+ assert_false(containerMatchedActive, 'container should not have :active for top layer elements');
+ assert_false(bodyMatchedActive, 'body should not have :active for top layer elements');
+ } else {
+ assert_true(containerMatchedActive, 'container should have :active for non-top layer elements');
+ assert_true(bodyMatchedActive, 'body should have :active for non-top layer elements');
+ }
+ }, `User action pseudo-classes on ${type} (${state})`);
+});
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/interestfor/resources/invoker-utils.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interestfor/resources/invoker-utils.js
new file mode 100644
index 00000000000..2a5e7498f2c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/interestfor/resources/invoker-utils.js
@@ -0,0 +1,137 @@
+function waitForRender() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+}
+async function clickOn(element) {
+ await waitForRender();
+ let rect = element.getBoundingClientRect();
+ let actions = new test_driver.Actions();
+ // FIXME: Switch to pointerMove(0, 0, {origin: element}) once
+ // https://github.com/web-platform-tests/wpt/issues/41257 is fixed.
+ await actions
+ .pointerMove(Math.round(rect.x + rect.width / 2), Math.round(rect.y + rect.height / 2), {})
+ .pointerDown({button: actions.ButtonType.LEFT})
+ .pointerUp({button: actions.ButtonType.LEFT})
+ .send();
+ await waitForRender();
+}
+async function focusOn(element) {
+ element.focus();
+ await waitForRender();
+ assert_equals(document.activeElement,element,'focus should be on element');
+}
+async function hoverOver(element) {
+ await waitForRender();
+ let rect = element.getBoundingClientRect();
+ let actions = new test_driver.Actions();
+ // FIXME: Switch to pointerMove(0, 0, {origin: element}) once
+ // https://github.com/web-platform-tests/wpt/issues/41257 is fixed.
+ await actions
+ .pointerMove(Math.round(rect.x + rect.width / 2), Math.round(rect.y + rect.height / 2), {})
+ .send();
+ await waitForRender();
+}
+async function longPress(element) {
+ await waitForRender();
+ let rect = element.getBoundingClientRect();
+ // FIXME: Switch to pointerMove(0, 0, {origin: element}) once
+ // https://github.com/web-platform-tests/wpt/issues/41257 is fixed.
+ const x = Math.round(rect.x + rect.width / 2);
+ const y = Math.round(rect.y + rect.height / 2);
+ await new test_driver.Actions()
+ .addPointer("touchPointer", "touch")
+ .pointerMove(x, y, {sourceName: "touchPointer"})
+ .pointerDown({sourceName: "touchPointer"})
+ // This needs to be long enough to trigger long-press on all platforms:
+ .pause(1000, "pointer", {sourceName: "touchPointer"})
+ .pointerUp({sourceName: "touchPointer"})
+ .send();
+ await waitForRender();
+}
+function mouseOverAndRecord(t,element) {
+ let timingInfo = {element, started: performance.now()};
+ return (new test_driver.Actions())
+ .pointerMove(0, 0, {origin: element})
+ .send()
+ .then(() => timingInfo);
+}
+function focusAndRecord(t,element) {
+ let timingInfo = {element, started: performance.now()};
+ element.focus();
+ return timingInfo;
+}
+async function hoverOrFocus(invokerMethod,element) {
+ if (invokerMethod === 'hover') {
+ await hoverOver(element);
+ } else {
+ assert_equals(invokerMethod,'focus');
+ element.focus();
+ await waitForRender();
+ }
+}
+async function mouseOverOrFocusAndRecord(t,invokerMethod,element) {
+ if (invokerMethod === 'hover') {
+ return await mouseOverAndRecord(t,element);
+ } else {
+ assert_equals(invokerMethod,'focus');
+ return focusAndRecord(t,element);
+ }
+}
+// Note that this may err on the side of being too large (reporting a number
+// that is larger than the actual time since the mouseover happened), due to how
+// `timingInfo.started` is initialized, on first mouse move. However, this
+// function is intended to be used as a detector for the test harness taking too
+// long for some tests, so it's ok to be conservative.
+function msSinceMouseOver(timingInfo) {
+ return performance.now() - timingInfo.started;
+}
+async function waitForHoverTime(hoverWaitTimeMs) {
+ await new Promise(resolve => step_timeout(resolve,hoverWaitTimeMs));
+ await waitForRender();
+};
+
+async function createPopoverAndInvokerForHoverTests(test, showdelayMs, hideDelayMs) {
+ const unrelated = document.createElement('div');
+ unrelated.tabIndex = 0;
+ document.body.appendChild(unrelated);
+ unrelated.textContent = 'Unrelated';
+ unrelated.setAttribute('style','position:fixed; top:0;');
+ // Ensure we never hover over or focus on an active interestfor element.
+ unrelated.focus();
+ await hoverOver(unrelated);
+ const popover = document.createElement('div');
+ popover.popover = 'auto';
+ popover.setAttribute('style','inset:auto; top: 100px;');
+ popover.textContent = 'Popover';
+ document.body.appendChild(popover);
+ let invoker = document.createElement('button');
+ invoker.interestForElement = popover;
+ invoker.setAttribute('style',`
+ interest-delay-start: ${showdelayMs}ms;
+ interest-delay-end: ${hideDelayMs}ms;
+ position:fixed;
+ top:200px;
+ width:fit-content;
+ height:fit-content;
+ `);
+ invoker.innerText = 'Invoker';
+ document.body.appendChild(invoker);
+ const actualShowDelay = Number(getComputedStyle(invoker).interestDelayStart.slice(0,-1))*1000;
+ assert_equals(actualShowDelay,showdelayMs,'interest-delay-start is incorrect');
+ const actualHideDelay = Number(getComputedStyle(invoker).interestDelayEnd.slice(0,-1))*1000;
+ assert_equals(actualHideDelay,hideDelayMs,'interest-delay-end is incorrect');
+ test.add_cleanup(() => {
+ popover.remove();
+ invoker.remove();
+ unrelated.remove();
+ });
+ assert_false(popover.matches(':popover-open'),'The popover should start out closed');
+ return {popover, invoker, unrelated};
+}
+async function sendLoseInterestHotkey() {
+ const kEscape = '\uE00C';
+ await new test_driver.Actions()
+ .keyDown(kEscape)
+ .keyUp(kEscape)
+ .send();
+ await waitForRender();
+}