summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_focusable_statechange.html
blob: 8c841490bb3511d5116bc137892382b2bc65aa52 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<html>

<head>
  <title>Test removal of focused accessible</title>

  <link rel="stylesheet" type="text/css"
        href="chrome://mochikit/content/tests/SimpleTest/test.css" />

  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>

  <script type="application/javascript"
          src="../common.js"></script>
  <script type="application/javascript"
          src="../role.js"></script>
  <script type="application/javascript"
          src="../states.js"></script>
  <script type="application/javascript"
          src="../promisified-events.js"></script>

  <script type="application/javascript">
    function focusableStateChange(id, enabled) {
      return [EVENT_STATE_CHANGE, e => {
         e.QueryInterface(nsIAccessibleStateChangeEvent);
         return getAccessible(id) == e.accessible &&
          e.state == STATE_FOCUSABLE && (enabled == undefined || e.isEnabled == enabled);
      }];
     }

    async function doTests() {
      info("disable buttons.");
      // Expect focusable change with 'disabled',
      // and don't expect it with 'aria-disabled'.
      let p = waitForEvents({
        expected: [focusableStateChange("button2", false)],
        unexpected: [focusableStateChange("button1")]
      });
      getNode("button1").setAttribute("aria-disabled", "true");
      getNode("button2").disabled = true;
      await p;

      info("re-enable button");
      // Expect focusable change with 'disabled',
      // and don't expect it with 'aria-disabled'.
      p = waitForEvents({
        expected: [focusableStateChange("button2", true)],
        unexpected: [focusableStateChange("button1")]
      });
      getNode("button1").setAttribute("aria-disabled", "false");
      getNode("button2").disabled = false;
      await p;

      info("add tabindex");
      // Expect focusable change on non-input,
      // and don't expect event on an already focusable input.
      p = waitForEvents({
        expected: [focusableStateChange("div", true)],
        unexpected: [focusableStateChange("button2")]
      });
      getNode("button2").tabIndex = "0";
      getNode("div").tabIndex = "0";
      await p;

      info("remove tabindex");
      // Expect focusable change when removing tabindex.
      p = waitForEvent(...focusableStateChange("div", false));
      getNode("div").removeAttribute("tabindex");
      await p;

      p = waitForEvent(...focusableStateChange("link", false));
      getNode("link").removeAttribute("href");
      await p;

      SimpleTest.finish();
    }

    SimpleTest.waitForExplicitFinish();
    addA11yLoadEvent(doTests);
  </script>
</head>

<body>

  <p id="display"></p>
  <div id="content" style="display: none"></div>
  <pre id="test">
  </pre>

  <button id="button1"></button>
  <button id="button2"></button>

  <div id="div">Hello</div>

  <a id="link" href="#">A link</a>

</body>
</html>