summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/mac/browser_aria_haspopup.js
blob: 57f1e50f65f5e516a805f7ba01fbe2ccf4bc6fd0 (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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from ../../mochitest/role.js */
/* import-globals-from ../../mochitest/states.js */
loadScripts(
  { name: "role.js", dir: MOCHITESTS_DIR },
  { name: "states.js", dir: MOCHITESTS_DIR }
);

/**
 * Test aria-haspopup
 */
addAccessibleTask(
  `
  <button aria-haspopup="false" id="false">action</button>

  <button aria-haspopup="menu" id="menu">action</button>

  <button aria-haspopup="listbox" id="listbox">action</button>

  <button aria-haspopup="tree" id="tree">action</button>

  <button aria-haspopup="grid" id="grid">action</button>

  <button aria-haspopup="dialog" id="dialog">action</button>

  `,
  async (browser, accDoc) => {
    // FALSE
    let falseID = getNativeInterface(accDoc, "false");
    is(
      falseID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup val for button with false"
    );
    is(
      falseID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue val for button with false"
    );
    let attrChanged = waitForEvent(EVENT_STATE_CHANGE, "false");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("false")
        .setAttribute("aria-haspopup", "true");
    });
    await attrChanged;

    is(
      falseID.getAttributeValue("AXPopupValue"),
      "true",
      "Correct AXPopupValue after change for false"
    );
    is(
      falseID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup val for button with true"
    );

    let stateChanged = waitForEvent(EVENT_STATE_CHANGE, "false");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("false").removeAttribute("aria-haspopup");
    });
    await stateChanged;

    is(
      falseID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue after remove for false"
    );
    is(
      falseID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup val for button after remove"
    );

    // MENU
    let menuID = getNativeInterface(accDoc, "menu");
    is(
      menuID.getAttributeValue("AXPopupValue"),
      "menu",
      "Correct AXPopupValue val for button with menu"
    );
    is(
      menuID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup val for button with menu"
    );

    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("menu")
        .setAttribute("aria-haspopup", "true");
    });

    await untilCacheIs(
      () => menuID.getAttributeValue("AXPopupValue"),
      "true",
      "Correct AXPopupValue after change for menu"
    );
    is(
      menuID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup val for button with menu"
    );

    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "menu");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("menu").removeAttribute("aria-haspopup");
    });
    await stateChanged;

    await untilCacheIs(
      () => menuID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue after remove for menu"
    );
    is(
      menuID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup val for button after remove"
    );

    // LISTBOX
    let listboxID = getNativeInterface(accDoc, "listbox");
    is(
      listboxID.getAttributeValue("AXPopupValue"),
      "listbox",
      "Correct AXPopupValue for button with listbox"
    );
    is(
      listboxID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with listbox"
    );

    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("listbox")
        .setAttribute("aria-haspopup", "true");
    });

    await untilCacheIs(
      () => listboxID.getAttributeValue("AXPopupValue"),
      "true",
      "Correct AXPopupValue after change for listbox"
    );
    is(
      listboxID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with listbox"
    );

    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "listbox");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("listbox")
        .removeAttribute("aria-haspopup");
    });
    await stateChanged;

    is(
      listboxID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue after remove for listbox"
    );
    is(
      listboxID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup for button with listbox"
    );

    // TREE
    let treeID = getNativeInterface(accDoc, "tree");
    is(
      treeID.getAttributeValue("AXPopupValue"),
      "tree",
      "Correct AXPopupValue for button with tree"
    );
    is(
      treeID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with tree"
    );

    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("tree")
        .setAttribute("aria-haspopup", "true");
    });

    await untilCacheIs(
      () => treeID.getAttributeValue("AXPopupValue"),
      "true",
      "Correct AXPopupValue after change for tree"
    );
    is(
      treeID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with tree"
    );

    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "tree");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("tree").removeAttribute("aria-haspopup");
    });
    await stateChanged;

    is(
      treeID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue after remove for tree"
    );
    is(
      treeID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup for button with tree after remove"
    );

    // GRID
    let gridID = getNativeInterface(accDoc, "grid");
    is(
      gridID.getAttributeValue("AXPopupValue"),
      "grid",
      "Correct AXPopupValue for button with grid"
    );
    is(
      gridID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with grid"
    );

    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("grid")
        .setAttribute("aria-haspopup", "true");
    });

    await untilCacheIs(
      () => gridID.getAttributeValue("AXPopupValue"),
      "true",
      "Correct AXPopupValue after change for grid"
    );
    is(
      gridID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with grid"
    );

    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "grid");
    await SpecialPowers.spawn(browser, [], () => {
      content.document.getElementById("grid").removeAttribute("aria-haspopup");
    });
    await stateChanged;

    is(
      gridID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue after remove for grid"
    );
    is(
      gridID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup for button with grid after remove"
    );

    // DIALOG
    let dialogID = getNativeInterface(accDoc, "dialog");
    is(
      dialogID.getAttributeValue("AXPopupValue"),
      "dialog",
      "Correct AXPopupValue for button with dialog"
    );
    is(
      dialogID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with dialog"
    );

    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("dialog")
        .setAttribute("aria-haspopup", "true");
    });

    await untilCacheIs(
      () => dialogID.getAttributeValue("AXPopupValue"),
      "true",
      "Correct AXPopupValue after change for dialog"
    );
    is(
      dialogID.getAttributeValue("AXHasPopup"),
      1,
      "Correct AXHasPopup for button with dialog"
    );

    stateChanged = waitForEvent(EVENT_STATE_CHANGE, "dialog");
    await SpecialPowers.spawn(browser, [], () => {
      content.document
        .getElementById("dialog")
        .removeAttribute("aria-haspopup");
    });
    await stateChanged;

    is(
      dialogID.getAttributeValue("AXPopupValue"),
      null,
      "Correct AXPopupValue after remove for dialog"
    );
    is(
      dialogID.getAttributeValue("AXHasPopup"),
      0,
      "Correct AXHasPopup for button with dialog after remove"
    );
  }
);