summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/windows/uia/browser_generalProps.js
blob: 244c9e4b1b6abeae94db51b7670d37d2557e3716 (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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/* 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";

/* eslint-disable camelcase */
// From https://learn.microsoft.com/en-us/windows/win32/winauto/landmark-type-identifiers
const UIA_CustomLandmarkTypeId = 80000;
const UIA_MainLandmarkTypeId = 80002;
/* eslint-enable camelcase */

/**
 * Test the Name property.
 */
addUiaTask(
  `
<button id="button">before</button>
<div id="div">div</div>
  `,
  async function testName(browser) {
    await definePyVar("doc", `getDocUia()`);
    await assignPyVarToUiaWithId("button");
    is(
      await runPython(`button.CurrentName`),
      "before",
      "button has correct name"
    );
    await assignPyVarToUiaWithId("div");
    is(await runPython(`div.CurrentName`), "", "div has no name");

    info("Setting aria-label on button");
    await setUpWaitForUiaPropEvent("Name", "button");
    await invokeSetAttribute(browser, "button", "aria-label", "after");
    await waitForUiaEvent();
    ok(true, "Got Name prop change event on button");
    is(
      await runPython(`button.CurrentName`),
      "after",
      "button has correct name"
    );
  }
);

/**
 * Test the FullDescription property.
 */
addUiaTask(
  `
<button id="button" aria-description="before">button</button>
<div id="div">div</div>
  `,
  async function testFullDescription(browser) {
    await definePyVar("doc", `getDocUia()`);
    await assignPyVarToUiaWithId("button");
    is(
      await runPython(`button.CurrentFullDescription`),
      "before",
      "button has correct FullDescription"
    );
    await assignPyVarToUiaWithId("div");
    is(
      await runPython(`div.CurrentFullDescription`),
      "",
      "div has no FullDescription"
    );

    info("Setting aria-description on button");
    await setUpWaitForUiaPropEvent("FullDescription", "button");
    await invokeSetAttribute(browser, "button", "aria-description", "after");
    await waitForUiaEvent();
    ok(true, "Got FullDescription prop change event on button");
    is(
      await runPython(`button.CurrentFullDescription`),
      "after",
      "button has correct FullDescription"
    );
  },
  // The IA2 -> UIA proxy doesn't support FullDescription.
  { uiaEnabled: true, uiaDisabled: false }
);

/**
 * Test the IsEnabled property.
 */
addUiaTask(
  `
<button id="button">button</button>
<p id="p">p</p>
  `,
  async function testIsEnabled(browser) {
    await definePyVar("doc", `getDocUia()`);
    await assignPyVarToUiaWithId("button");
    ok(await runPython(`button.CurrentIsEnabled`), "button has IsEnabled true");
    // The IA2 -> UIA proxy doesn't fire IsEnabled prop change events.
    if (gIsUiaEnabled) {
      info("Setting disabled on button");
      await setUpWaitForUiaPropEvent("IsEnabled", "button");
      await invokeSetAttribute(browser, "button", "disabled", true);
      await waitForUiaEvent();
      ok(true, "Got IsEnabled prop change event on button");
      ok(
        !(await runPython(`button.CurrentIsEnabled`)),
        "button has IsEnabled false"
      );
    }

    await assignPyVarToUiaWithId("p");
    ok(await runPython(`p.CurrentIsEnabled`), "p has IsEnabled true");
  }
);

async function testGroupPos(id, level, pos, size) {
  await assignPyVarToUiaWithId(id);
  is(await runPython(`${id}.CurrentLevel`), level, `${id} Level correct`);
  is(
    await runPython(`${id}.CurrentPositionInSet`),
    pos,
    `${id} PositionInSet correct`
  );
  is(
    await runPython(`${id}.CurrentSizeOfSet`),
    size,
    `${id} SizeOfSet correct`
  );
}

/**
 * Test the Level, PositionInSet and SizeOfSet properties.
 */
addUiaTask(
  `
<ul>
  <li id="li1">li1<ul id="ul1">
    <li id="li2a">li2a</li>
    <li id="li2b" hidden>li2b</li>
    <li id="li2c">li2c</li>
  </ul></li>
</ul>
<h2 id="h2">h2</h2>
<button id="button">button</button>
  `,
  async function testGroupPosProps(browser) {
    await definePyVar("doc", `getDocUia()`);
    await testGroupPos("li1", 1, 1, 1);
    await testGroupPos("li2a", 2, 1, 2);
    await testGroupPos("li2c", 2, 2, 2);
    info("Showing li2b");
    // There aren't events in any API for a change to group position properties
    // because this would be too spammy and isn't particularly useful given
    // how frequently these can change.
    let shown = waitForEvent(EVENT_SHOW, "li2b");
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("li2b").hidden = false;
    });
    await shown;
    await testGroupPos("li2a", 2, 1, 3);
    await testGroupPos("li2b", 2, 2, 3);
    await testGroupPos("li2c", 2, 3, 3);

    // The IA2 -> UIA proxy doesn't map heading level to the Level property.
    if (gIsUiaEnabled) {
      await testGroupPos("h2", 2, 0, 0);
    }
    await testGroupPos("button", 0, 0, 0);
  }
);

/**
 * Test the FrameworkId property.
 */
addUiaTask(
  `<button id="button">button</button>`,
  async function testFrameworkId() {
    await definePyVar("doc", `getDocUia()`);
    is(
      await runPython(`doc.CurrentFrameworkId`),
      "Gecko",
      "doc FrameworkId is correct"
    );
    await assignPyVarToUiaWithId("button");
    is(
      await runPython(`button.CurrentFrameworkId`),
      "Gecko",
      "button FrameworkId is correct"
    );
  }
);

/**
 * Test the ClassName property.
 */
addUiaTask(
  `
<p id="p">p</p>
<button id="button" class="c1">button</button>
  `,
  async function testClassName(browser, docAcc) {
    await definePyVar("doc", `getDocUia()`);
    await assignPyVarToUiaWithId("p");
    ok(!(await runPython(`p.CurrentClassName`)), "p has no ClassName");

    await assignPyVarToUiaWithId("button");
    is(
      await runPython(`button.CurrentClassName`),
      "c1",
      "button has correct ClassName"
    );
    info("Changing button class");
    await invokeSetAttribute(browser, "button", "class", "c2 c3");
    // Gecko doesn't fire an event for class changes, as this isn't useful for
    // clients.
    const button = findAccessibleChildByID(docAcc, "button");
    await untilCacheIs(
      () => button.attributes.getStringProperty("class"),
      "c2 c3",
      "button class updated"
    );
    is(
      await runPython(`button.CurrentClassName`),
      "c2 c3",
      "button has correct ClassName"
    );
  },
  // The IA2 -> UIA proxy doesn't support ClassName.
  { uiaEnabled: true, uiaDisabled: false }
);

/**
 * Test the AriaRole property.
 */
addUiaTask(
  `
<div id="button" role="button">button</div>
<div id="main" role="main">main</div>
<div id="unknown" role="unknown">unknown</div>
<button id="computedButton">computedButton</button>
<h1 id="computedHeading">computedHeading</h1>
<main id="computedMain">computedMain</main>
<div id="generic">generic</div>
  `,
  async function testAriaRole() {
    await definePyVar("doc", `getDocUia()`);
    is(
      await runPython(`findUiaByDomId(doc, "button").CurrentAriaRole`),
      "button",
      "button has correct AriaRole"
    );
    is(
      await runPython(`findUiaByDomId(doc, "main").CurrentAriaRole`),
      "main",
      "main has correct AriaRole"
    );
    is(
      await runPython(`findUiaByDomId(doc, "unknown").CurrentAriaRole`),
      "unknown",
      "unknown has correct AriaRole"
    );
    // The IA2 -> UIA proxy doesn't compute ARIA roles.
    if (gIsUiaEnabled) {
      is(
        await runPython(
          `findUiaByDomId(doc, "computedButton").CurrentAriaRole`
        ),
        "button",
        "computedButton has correct AriaRole"
      );
      is(
        await runPython(`findUiaByDomId(doc, "computedMain").CurrentAriaRole`),
        "main",
        "computedMain has correct AriaRole"
      );
      is(
        await runPython(
          `findUiaByDomId(doc, "computedHeading").CurrentAriaRole`
        ),
        "heading",
        "computedHeading has correct AriaRole"
      );
      is(
        await runPython(`findUiaByDomId(doc, "generic").CurrentAriaRole`),
        "generic",
        "generic has correct AriaRole"
      );
    }
  }
);

/**
 * Test the LocalizedControlType property. We don't support this ourselves, but
 * the system provides it based on ControlType and AriaRole.
 */
addUiaTask(
  `
<button id="button">button</button>
<h1 id="h1">h1</h1>
<main id="main">main</main>
  `,
  async function testLocalizedControlType() {
    await definePyVar("doc", `getDocUia()`);
    is(
      await runPython(
        `findUiaByDomId(doc, "button").CurrentLocalizedControlType`
      ),
      "button",
      "button has correct LocalizedControlType"
    );
    // The IA2 -> UIA proxy doesn't compute ARIA roles, so it can't compute the
    // correct LocalizedControlType for these either.
    if (gIsUiaEnabled) {
      is(
        await runPython(
          `findUiaByDomId(doc, "h1").CurrentLocalizedControlType`
        ),
        "heading",
        "h1 has correct LocalizedControlType"
      );
      is(
        await runPython(
          `findUiaByDomId(doc, "main").CurrentLocalizedControlType`
        ),
        "main",
        "main has correct LocalizedControlType"
      );
    }
  }
);

/**
 * Test the LandmarkType property.
 */
addUiaTask(
  `
<div id="main" role="main">main</div>
<main id="htmlMain">htmlMain</main>
<div id="banner" role="banner">banner</div>
<header id="header">header</header>
<div id="region" role="region" aria-label="region">region</div>
<div id="unnamedRegion" role="region">unnamedRegion</div>
<main id="mainBanner" role="banner">mainBanner</main>
<div id="none">none</div>
  `,
  async function testLandmarkType() {
    await definePyVar("doc", `getDocUia()`);
    is(
      await runPython(`findUiaByDomId(doc, "main").CurrentLandmarkType`),
      UIA_MainLandmarkTypeId,
      "main has correct LandmarkType"
    );
    is(
      await runPython(`findUiaByDomId(doc, "htmlMain").CurrentLandmarkType`),
      UIA_MainLandmarkTypeId,
      "htmlMain has correct LandmarkType"
    );
    is(
      await runPython(`findUiaByDomId(doc, "banner").CurrentLandmarkType`),
      UIA_CustomLandmarkTypeId,
      "banner has correct LandmarkType"
    );
    is(
      await runPython(`findUiaByDomId(doc, "header").CurrentLandmarkType`),
      UIA_CustomLandmarkTypeId,
      "header has correct LandmarkType"
    );
    is(
      await runPython(`findUiaByDomId(doc, "region").CurrentLandmarkType`),
      UIA_CustomLandmarkTypeId,
      "region has correct LandmarkType"
    );
    is(
      await runPython(
        `findUiaByDomId(doc, "unnamedRegion").CurrentLandmarkType`
      ),
      0,
      "unnamedRegion has correct LandmarkType"
    );
    // ARIA role takes precedence.
    is(
      await runPython(`findUiaByDomId(doc, "mainBanner").CurrentLandmarkType`),
      UIA_CustomLandmarkTypeId,
      "mainBanner has correct LandmarkType"
    );
    is(
      await runPython(`findUiaByDomId(doc, "none").CurrentLandmarkType`),
      0,
      "none has correct LandmarkType"
    );
  }
);

/**
 * Test the LocalizedLandmarkType property.
 */
addUiaTask(
  `
<div id="main" role="main">main</div>
<div id="contentinfo" role="contentinfo">contentinfo</div>
<div id="region" role="region" aria-label="region">region</div>
<div id="unnamedRegion" role="region">unnamedRegion</div>
<main id="mainBanner" role="banner">mainBanner</main>
<div id="none">none</div>
  `,
  async function testLocalizedLandmarkType() {
    await definePyVar("doc", `getDocUia()`);
    // Provided by the system.
    is(
      await runPython(
        `findUiaByDomId(doc, "main").CurrentLocalizedLandmarkType`
      ),
      "main",
      "main has correct LocalizedLandmarkType"
    );
    // The IA2 -> UIA proxy doesn't follow the Core AAM spec for this role.
    if (gIsUiaEnabled) {
      // Provided by us.
      is(
        await runPython(
          `findUiaByDomId(doc, "contentinfo").CurrentLocalizedLandmarkType`
        ),
        "content information",
        "contentinfo has correct LocalizedLandmarkType"
      );
    }
    is(
      await runPython(
        `findUiaByDomId(doc, "region").CurrentLocalizedLandmarkType`
      ),
      "region",
      "region has correct LocalizedLandmarkType"
    );
    // Invalid landmark.
    is(
      await runPython(
        `findUiaByDomId(doc, "unnamedRegion").CurrentLocalizedLandmarkType`
      ),
      "",
      "unnamedRegion has correct LocalizedLandmarkType"
    );
    // ARIA role takes precedence.
    is(
      await runPython(
        `findUiaByDomId(doc, "mainBanner").CurrentLocalizedLandmarkType`
      ),
      "banner",
      "mainBanner has correct LocalizedLandmarkType"
    );
    is(
      await runPython(
        `findUiaByDomId(doc, "none").CurrentLocalizedLandmarkType`
      ),
      "",
      "none has correct LocalizedLandmarkType"
    );
  }
);