summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/windows/uia/browser_relationProps.js
blob: ff4059f99ecbd1dabf6c6f8d2ac6670d2ee22031 (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
/* 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";

function testUiaRelationArray(id, prop, targets) {
  return isUiaElementArray(
    `findUiaByDomId(doc, "${id}").Current${prop}`,
    targets,
    `${id} has correct ${prop} targets`
  );
}

/**
 * Test the ControllerFor property.
 */
addUiaTask(
  `
<input id="controls" aria-controls="t1 t2">
<input id="error" aria-errormessage="t3 t4" aria-invalid="true">
<input id="controlsError" aria-controls="t1 t2" aria-errormessage="t3 t4" aria-invalid="true">
<div id="t1">t1</div>
<div id="t2">t2</div>
<div id="t3">t3</div>
<div id="t4">t4</div>
<button id="none">none</button>
  `,
  async function testControllerFor() {
    await definePyVar("doc", `getDocUia()`);
    await testUiaRelationArray("controls", "ControllerFor", ["t1", "t2"]);
    // The IA2 -> UIA proxy doesn't support IA2_RELATION_ERROR.
    if (gIsUiaEnabled) {
      await testUiaRelationArray("error", "ControllerFor", ["t3", "t4"]);
      await testUiaRelationArray("controlsError", "ControllerFor", [
        "t1",
        "t2",
        "t3",
        "t4",
      ]);
    }
    await testUiaRelationArray("none", "ControllerFor", []);
  }
);

/**
 * Test the DescribedBy property.
 */
addUiaTask(
  `
<input id="describedby" aria-describedby="t1 t2">
<input id="details" aria-details="t3 t4">
<input id="describedbyDetails" aria-describedby="t1 t2" aria-details="t3 t4" aria-invalid="true">
<div id="t1">t1</div>
<div id="t2">t2</div>
<div id="t3">t3</div>
<div id="t4">t4</div>
<button id="none">none</button>
  `,
  async function testDescribedBy() {
    await definePyVar("doc", `getDocUia()`);
    await testUiaRelationArray("describedby", "DescribedBy", ["t1", "t2"]);
    // The IA2 -> UIA proxy doesn't support IA2_RELATION_DETAILS.
    if (gIsUiaEnabled) {
      await testUiaRelationArray("details", "DescribedBy", ["t3", "t4"]);
      await testUiaRelationArray("describedbyDetails", "DescribedBy", [
        "t1",
        "t2",
        "t3",
        "t4",
      ]);
    }
    await testUiaRelationArray("none", "DescribedBy", []);
  }
);

/**
 * Test the FlowsFrom and FlowsTo properties.
 */
addUiaTask(
  `
<div id="t1" aria-flowto="t2">t1</div>
<div id="t2">t2</div>
<button id="none">none</button>
  `,
  async function testFlows() {
    await definePyVar("doc", `getDocUia()`);
    await testUiaRelationArray("t1", "FlowsTo", ["t2"]);
    await testUiaRelationArray("t2", "FlowsFrom", ["t1"]);
    await testUiaRelationArray("none", "FlowsFrom", []);
    await testUiaRelationArray("none", "FlowsTo", []);
  }
);

/**
 * Test the LabeledBy property.
 */
addUiaTask(
  `
<label id="label">label</label>
<input id="input" aria-labelledby="label">
<label id="wrappingLabel">
  <input id="wrappedInput" value="wrappedInput">
  <p id="wrappingLabelP">wrappingLabel</p>
</label>
<button id="button" aria-labelledby="label">content</button>
<button id="noLabel">noLabel</button>
  `,
  async function testLabeledBy() {
    await definePyVar("doc", `getDocUia()`);
    // input's LabeledBy should be label's text leaf.
    let result = await runPython(`
      input = findUiaByDomId(doc, "input")
      label = findUiaByDomId(doc, "label")
      labelLeaf = uiaClient.RawViewWalker.GetFirstChildElement(label)
      return uiaClient.CompareElements(input.CurrentLabeledBy, labelLeaf)
    `);
    ok(result, "input has correct LabeledBy");
    // wrappedInput's LabeledBy should be wrappingLabelP's text leaf.
    result = await runPython(`
      wrappedInput = findUiaByDomId(doc, "wrappedInput")
      wrappingLabelP = findUiaByDomId(doc, "wrappingLabelP")
      wrappingLabelLeaf = uiaClient.RawViewWalker.GetFirstChildElement(wrappingLabelP)
      return uiaClient.CompareElements(wrappedInput.CurrentLabeledBy, wrappingLabelLeaf)
    `);
    ok(result, "wrappedInput has correct LabeledBy");
    // button has aria-labelledby, but UIA prohibits LabeledBy on buttons.
    ok(
      !(await runPython(
        `bool(findUiaByDomId(doc, "button").CurrentLabeledBy)`
      )),
      "button has no LabeledBy"
    );
    ok(
      !(await runPython(
        `bool(findUiaByDomId(doc, "noLabel").CurrentLabeledBy)`
      )),
      "noLabel has no LabeledBy"
    );
  },
  // The IA2 -> UIA proxy doesn't expose LabeledBy properly.
  { uiaEnabled: true, uiaDisabled: false }
);