Debian Codegraph @

testing/web-platform/mozilla/tests/focus/tab-when-selection-collapsed-at-focusable-element.html

raw
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Testing focus when selection is collapsed at focusable element</title>
6 <script src="/resources/testharness.js"></script>
7 <script src="/resources/testharnessreport.js"></script>
8 <script src="/resources/testdriver.js"></script>
9 <script src="/resources/testdriver-vendor.js"></script>
10 <script src="/resources/testdriver-actions.js"></script>
11 <script>
12 "use strict";
13
14 addEventListener("load", () => {
15 const tab = "\uE004";
16 const shift = "\uE008";
17 const first = document.querySelector("span");
18 const second = document.querySelector("span + span");
19 const third = document.querySelector("span + span + span");
20
21 promise_test(async () => {
22 getSelection().collapse(second.parentNode, 1);
23 document.activeElement?.blur();
24 await new test_driver.Actions()
25 .keyDown(tab)
26 .keyUp(tab)
27 .send();
28 assert_equals(document.activeElement, second);
29 }, "Tab when Selection collapsed at focusable 2nd element should make it focused");
30
31 promise_test(async () => {
32 getSelection().collapse(second.parentNode, 1);
33 document.activeElement?.blur();
34 await new test_driver.Actions()
35 .keyDown(shift)
36 .keyDown(tab)
37 .keyUp(tab)
38 .keyUp(shift)
39 .send();
40 assert_equals(document.activeElement, second);
41 }, "Shift+Tab when Selection collapsed at 2nd focusable element should make it focused");
42
43 promise_test(async () => {
44 getSelection().collapse(third.parentNode, 2);
45 document.activeElement?.blur();
46 await new test_driver.Actions()
47 .keyDown(tab)
48 .keyUp(tab)
49 .send();
50 assert_equals(document.activeElement, third);
51 }, "Tab when Selection collapsed at focusable 3rd element should make it focused");
52
53 promise_test(async () => {
54 getSelection().collapse(first.parentNode, 0);
55 document.activeElement?.blur();
56 await new test_driver.Actions()
57 .keyDown(shift)
58 .keyDown(tab)
59 .keyUp(tab)
60 .keyUp(shift)
61 .send();
62 assert_equals(document.activeElement, first);
63 }, "Shift+Tab when Selection collapsed at 1st focusable element should make it focused");
64 }, {once: true});
65 </script>
66 </head>
67 <body><span id="first" tabindex="0">1</span><span id="second" tabindex="0">2</span><span id="third" tabindex="0">3</span></body>
68 </html>