summaryrefslogtreecommitdiffstats
path: root/accessible/tests/mochitest/events/test_aria_statechange.html
blob: 7796d88ec4be303bcb3b3343a08017ef701eef5b (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<html>

<head>
  <title>ARIA state change event testing</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="../events.js"></script>

  <script type="application/javascript">
    let PromEvents = {};
    Services.scriptloader.loadSubScript(
      "chrome://mochitests/content/a11y/accessible/tests/mochitest/promisified-events.js",
      PromEvents);

    /**
     * Do tests.
     */
    var gQueue = null;

    // gA11yEventDumpID = "eventdump"; // debugging
    // gA11yEventDumpToConsole = true; // debugging

    function expandNode(aID, aIsExpanded) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new expandedStateChecker(aIsExpanded, this.DOMNode),
      ];

      this.invoke = function expandNode_invoke() {
        this.DOMNode.setAttribute("aria-expanded",
                                  (aIsExpanded ? "true" : "false"));
      };

      this.getID = function expandNode_getID() {
        return prettyName(aID) + " aria-expanded changed to '" + aIsExpanded + "'";
      };
    }

    function busyify(aID, aIsBusy) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new stateChangeChecker(STATE_BUSY, kOrdinalState, aIsBusy, this.DOMNode),
      ];

      this.invoke = function busyify_invoke() {
        this.DOMNode.setAttribute("aria-busy", (aIsBusy ? "true" : "false"));
      };

      this.getID = function busyify_getID() {
        return prettyName(aID) + " aria-busy changed to '" + aIsBusy + "'";
      };
    }

    function makeCurrent(aID, aIsCurrent, aValue) {
      this.DOMNode = getNode(aID);

      this.eventSeq = [
        new stateChangeChecker(EXT_STATE_CURRENT, true, aIsCurrent, this.DOMNode),
      ];

      this.invoke = function makeCurrent_invoke() {
        this.DOMNode.setAttribute("aria-current", aValue);
      };

      this.getID = function makeCurrent_getID() {
        return prettyName(aID) + " aria-current changed to " + aValue;
      };
    }

    async function testToggleAttribute(aID, aAttribute, aIncludeMixed) {
      let toggleState = aAttribute == "aria-pressed" ? STATE_PRESSED : STATE_CHECKED;

      // bug 472142. Role changes here if aria-pressed is added,
      // accessible should be recreated?
      let stateChange = PromEvents.waitForStateChange(aID, toggleState, true);
      getNode(aID).setAttribute(aAttribute, "true");
      await stateChange;

      stateChange = PromEvents.waitForStateChange(aID, toggleState, false);
      getNode(aID).setAttribute(aAttribute, "false");
      await stateChange;

      if (aIncludeMixed) {
        stateChange = PromEvents.waitForStateChange(aID, STATE_MIXED, true);
        getNode(aID).setAttribute(aAttribute, "mixed");
        await stateChange;

        stateChange = PromEvents.waitForStateChange(aID, STATE_MIXED, false);
        getNode(aID).setAttribute(aAttribute, "");
        await stateChange;
      }

      stateChange = PromEvents.waitForStateChange(aID, toggleState, true);
      getNode(aID).setAttribute(aAttribute, "true");
      await stateChange;

      if (aIncludeMixed) {
        stateChange = Promise.all([
          PromEvents.waitForStateChange(aID, STATE_MIXED, true),
          PromEvents.waitForStateChange(aID, toggleState, false)]);
        getNode(aID).setAttribute(aAttribute, "mixed");
        await stateChange;

        stateChange = Promise.all([
          PromEvents.waitForStateChange(aID, STATE_MIXED, false),
          PromEvents.waitForStateChange(aID, toggleState, true)]);
        getNode(aID).setAttribute(aAttribute, "true");
        await stateChange;
      }

      // bug 472142. Role changes here too if aria-pressed is removed,
      // accessible should be recreated?
      stateChange = PromEvents.waitForStateChange(aID, toggleState, false);
      getNode(aID).removeAttribute(aAttribute);
      await stateChange;
    }

    async function doTests() {
      gQueue = new eventQueue();

      let queueFinished = new Promise(resolve => {
        gQueue.onFinish = function() {
          resolve();
          return DO_NOT_FINISH_TEST;
        };
      });

      gQueue.push(new expandNode("section", true));
      gQueue.push(new expandNode("section", false));
      gQueue.push(new expandNode("div", true));
      gQueue.push(new expandNode("div", false));

      gQueue.push(new busyify("aria_doc", true));
      gQueue.push(new busyify("aria_doc", false));

      gQueue.push(new makeCurrent("current_page_1", false, "false"));
      gQueue.push(new makeCurrent("current_page_2", true, "page"));
      gQueue.push(new makeCurrent("current_page_2", false, "false"));
      gQueue.push(new makeCurrent("current_page_3", true, "true"));
      gQueue.push(new makeCurrent("current_page_3", false, ""));

      gQueue.invoke();
      await queueFinished;
      // Tests beyond this point use await rather than eventQueue.

      await testToggleAttribute("pressable", "aria-pressed", true);
      await testToggleAttribute("pressable_native", "aria-pressed", true);
      await testToggleAttribute("checkable", "aria-checked", true);
      await testToggleAttribute("checkableBool", "aria-checked", false);

      SimpleTest.finish();
    }

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

<body>

  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=551684"
     title="No statechange event for aria-expanded on native HTML elements, is fired on ARIA widgets">
    Mozilla Bug 551684
  </a><br>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=648133"
     title="fire state change event for aria-busy">
    Mozilla Bug 648133
  </a><br>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=467143"
     title="mixed state change event is fired for focused accessible only">
    Mozilla Bug 467143
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=989958"
     title="Pressed state is not exposed on a button element with aria-pressed attribute">
    Mozilla Bug 989958
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=1136563"
     title="Support ARIA 1.1 switch role">
    Mozilla Bug 1136563
  </a>
  <a target="_blank"
     href="https://bugzilla.mozilla.org/show_bug.cgi?id=1355921"
     title="Elements with a defined, non-false value for aria-current should expose ATK_STATE_ACTIVE">
    Mozilla Bug 1355921
  </a>

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

  <!-- aria-expanded -->
  <div id="section" role="section" aria-expanded="false">expandable section</div>
  <div id="div" aria-expanded="false">expandable native div</div>

  <!-- aria-busy -->
  <div id="aria_doc" role="document" tabindex="0">A document</div>

  <!-- aria-pressed -->
  <div id="pressable" role="button"></div>
  <button id="pressable_native"></button>

  <!-- aria-checked -->
  <div id="checkable" role="checkbox"></div>
  <div id="checkableBool" role="switch"></div>

  <!-- aria-current -->
  <div id="current_page_1" role="link" aria-current="page">1</div>
  <div id="current_page_2" role="link" aria-current="false">2</div>
  <div id="current_page_3" role="link">3</div>
</body>
</html>