summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_focus_scrollable_fieldset.html
blob: 444d078cb1bef3d0b07df7e71fdbf76ce1d38718 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!doctype html>
<title>Test for bug 1351248</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<style>
  fieldset {
    overflow: auto;
    height: 1em;
    width: 1em;
  }
</style>
<input type="text" id="start">

<fieldset>
  <input type="text">
  <input type="text">
  <input type="text">
  <input type="text">
  <input type="text">
  <input type="text">
</fieldset>

<input type="text" id="end">
<script>
  SimpleTest.waitForExplicitFinish();
  SimpleTest.waitForFocus(async function() {
    // Enable Full Keyboard Access emulation on Mac.
    if (navigator.platform.indexOf("Mac") === 0) {
      await SpecialPowers.pushPrefEnv({"set": [["accessibility.tabfocus", 7]]});
    }

    const start = document.getElementById("start");

    start.focus();

    const end = document.getElementById("end");

    is(document.activeElement, start, "Focus moved sanely");

    let lastActiveElement = start;
    let stack = [start];

    do {
      synthesizeKey("KEY_Tab");
      isnot(document.activeElement, lastActiveElement, "Focus should've moved once per tab keypress");
      lastActiveElement = document.activeElement;
      stack.push(lastActiveElement);
    } while (document.activeElement != end)

    is(stack.length, document.querySelectorAll("input").length + 1, "Fieldset should be focusable");

    do {
      let previous = stack.pop();
      is(document.activeElement, previous, "Focus should've moved backwards as expected");
      synthesizeKey("KEY_Tab", {shiftKey: true});
    } while (stack.length);

    SimpleTest.finish();
  });
</script>