mirror of
https://github.com/servo/servo.git
synced 2025-07-12 09:53:40 +01:00
109 lines
4.5 KiB
HTML
109 lines
4.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>CSS Test (Selectors): Keyboard use triggers :focus-visible</title>
|
|
<link rel="author" title="Alice Boxhall" href="aboxhall@chromium.org" />
|
|
<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo" />
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/resources/testdriver.js"></script>
|
|
<script src="/resources/testdriver-vendor.js"></script>
|
|
<style>
|
|
[data-hadkeydown] :focus-visible {
|
|
outline: darkgreen dotted 1px; /* fallback for Edge */
|
|
outline: darkgreen auto 5px;
|
|
}
|
|
|
|
[data-hadmousedown] :focus-visible {
|
|
outline: red dotted 1px; /* fallback for Edge */
|
|
outline: red auto 5px;
|
|
}
|
|
|
|
[data-hadkeydown] :focus:not(:focus-visible) {
|
|
outline: 0;
|
|
background-color: tomato;
|
|
}
|
|
|
|
[data-hadmousedown] :focus:not(:focus-visible) {
|
|
outline: 0;
|
|
background-color: darkseagreen;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
This test checks that using the keyboard in a way that does not move focus still causes <code>:focus-visible</code> matching to trigger.
|
|
<ol id="instructions">
|
|
<li>If the user-agent does not claim to support the <code>:focus-visible</code> pseudo-class then SKIP this test.</li>
|
|
<li>Use the mouse to focus the element below that says "Click me first."</li>
|
|
<li>If the element has a red outline, then the test result is FAILURE.</li>
|
|
<li>Press the SHIFT key.</li>
|
|
<li>If the element now has a red background, then the test result is FAILURE.</li>
|
|
<li>Use the mouse to click the element below that says "Click me second."</li>
|
|
<li>If the element has a green background, the test result is SUCCESS.</li>
|
|
</ol>
|
|
|
|
<div id="one" tabindex="0">Click me first.</div>
|
|
<div id="two" tabindex="0">Click me second.</div>
|
|
<script>
|
|
document.body.addEventListener("keydown", (e) => {
|
|
delete document.body.dataset.hadmousedown;
|
|
document.body.dataset.hadkeydown = "";
|
|
}, true);
|
|
|
|
document.body.addEventListener("mousedown", (e) => {
|
|
delete document.body.dataset.hadkeydown;
|
|
document.body.dataset.hadmousedown = "";
|
|
}, true);
|
|
|
|
async_test(async function(t) {
|
|
let tested_modality_change = false;
|
|
let tested_modality_unchanged_by_mouse_click = false;
|
|
let tested_mouse_focus_after_modality_change = false;
|
|
|
|
// TODO(crbug.com/828858): Remove this check once bug is resolved.
|
|
test_driver.send_keys(document.body, "\uE050").then(t.step_func(() => {
|
|
const handle_initial_focus = t.step_func(() => {
|
|
one.addEventListener("keyup", t.step_func(test_modality_change));
|
|
one.removeEventListener("focus", handle_initial_focus);
|
|
|
|
test_driver.send_keys(one, "\uE050");
|
|
});
|
|
|
|
const test_modality_change = t.step_func(() => {
|
|
assert_equals(getComputedStyle(one).outlineColor, "rgb(59, 153, 252)");
|
|
tested_modality_change = true;
|
|
one.removeEventListener("keyup", test_modality_change);
|
|
one.addEventListener("click", test_modality_unchanged_by_mouse_click);
|
|
test_driver.click(one);
|
|
});
|
|
|
|
const test_modality_unchanged_by_mouse_click = t.step_func(() => {
|
|
assert_true(tested_modality_change);
|
|
assert_equals(getComputedStyle(one).outlineColor, "rgb(59, 153, 252)");
|
|
tested_modality_unchanged_by_mouse_click = true;
|
|
one.removeEventListener("click", test_modality_unchanged_by_mouse_click);
|
|
two.addEventListener("focus", test_mouse_focus_after_modality_change);
|
|
test_driver.click(two);
|
|
});
|
|
|
|
const test_mouse_focus_after_modality_change = t.step_func(() => {
|
|
assert_true(tested_modality_unchanged_by_mouse_click);
|
|
assert_false("hadkeydown" in document.body.dataset);
|
|
assert_equals(getComputedStyle(two).outlineColor, "rgb(59, 153, 252)");
|
|
tested_mouse_focus_after_modality_change = true;
|
|
t.done();
|
|
});
|
|
|
|
one.addEventListener("focus", handle_initial_focus);
|
|
test_driver.click(one);
|
|
})).catch(t.step_func((e) => {
|
|
// TODO(crbug.com/828858): Remove this check once bug is resolved.
|
|
assert_true(false, "send_keys not implemented yet");
|
|
t.done();
|
|
}));
|
|
}, "Using keyboard while element is focused should trigger :focus-visible; using mouse without moving focus should not cancel it; moving focus using mouse should cancel it.");
|
|
</script>
|
|
</body>
|
|
</html>
|