summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/e10s/browser_caching_relations.js
blob: cc8393083042cb9c7f983e898568cef6998e6297 (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
/* 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";
requestLongerTimeout(2);

/**
 * A test specification that has the following format:
 * [
 *   attr                 relevant aria attribute
 *   hostRelation         corresponding host relation type
 *   dependantRelation    corresponding dependant relation type
 * ]
 */
const attrRelationsSpec = [
  ["aria-labelledby", RELATION_LABELLED_BY, RELATION_LABEL_FOR],
  ["aria-describedby", RELATION_DESCRIBED_BY, RELATION_DESCRIPTION_FOR],
  ["aria-controls", RELATION_CONTROLLER_FOR, RELATION_CONTROLLED_BY],
  ["aria-flowto", RELATION_FLOWS_TO, RELATION_FLOWS_FROM],
  ["aria-details", RELATION_DETAILS, RELATION_DETAILS_FOR],
  ["aria-errormessage", RELATION_ERRORMSG, RELATION_ERRORMSG_FOR],
];

/**
 * Test caching of relations between accessible objects.
 */
addAccessibleTask(
  `
  <div id="dependant1">label</div>
  <div id="dependant2">label2</div>
  <div role="checkbox" id="host"></div>`,
  async function (browser, accDoc) {
    for (let spec of attrRelationsSpec) {
      await testRelated(browser, accDoc, ...spec);
    }
  },
  { iframe: true, remoteIframe: true }
);

/**
 * Test caching of relations with respect to label objects and their "for" attr.
 */
addAccessibleTask(
  `
  <input type="checkbox" id="dependant1">
  <input type="checkbox" id="dependant2">
  <label id="host">label</label>`,
  async function (browser, accDoc) {
    await testRelated(
      browser,
      accDoc,
      "for",
      RELATION_LABEL_FOR,
      RELATION_LABELLED_BY
    );
  },
  { iframe: true, remoteIframe: true }
);

/**
 * Test rel caching for element with existing relation attribute.
 */
addAccessibleTask(
  `<div id="label">label</div><button id="button" aria-labelledby="label">`,
  async function (browser, accDoc) {
    const button = findAccessibleChildByID(accDoc, "button");
    const label = findAccessibleChildByID(accDoc, "label");

    await testCachedRelation(button, RELATION_LABELLED_BY, label);
    await testCachedRelation(label, RELATION_LABEL_FOR, button);
  },
  { iframe: true, remoteIframe: true }
);

/**
 * Test caching of relations with respect to output objects and their "for" attr.
 */
addAccessibleTask(
  `
  <form oninput="host.value=parseInt(dependant1.value)+parseInt(dependant2.value)">
    <input type="number" id="dependant1" value="50"> +
    <input type="number" id="dependant2" value="25"> =
    <output name="host" id="host"></output>
  </form>`,
  async function (browser, accDoc) {
    await testRelated(
      browser,
      accDoc,
      "for",
      RELATION_CONTROLLED_BY,
      RELATION_CONTROLLER_FOR
    );
  },
  { iframe: true, remoteIframe: true }
);

/**
 * Test rel caching for <label> element with existing "for" attribute.
 */
addAccessibleTask(
  `data:text/html,<label id="label" for="input">label</label><input id="input">`,
  async function (browser, accDoc) {
    const input = findAccessibleChildByID(accDoc, "input");
    const label = findAccessibleChildByID(accDoc, "label");
    await testCachedRelation(input, RELATION_LABELLED_BY, label);
    await testCachedRelation(label, RELATION_LABEL_FOR, input);
  },
  { iframe: true, remoteIframe: true }
);

/*
 * Test caching of relations with respect to label objects that are ancestors of
 * their target.
 */
addAccessibleTask(
  `
  <label id="host">
    <input type="checkbox" id="dependant1">
  </label>`,
  async function (browser, accDoc) {
    const input = findAccessibleChildByID(accDoc, "dependant1");
    const label = findAccessibleChildByID(accDoc, "host");

    await testCachedRelation(input, RELATION_LABELLED_BY, label);
    await testCachedRelation(label, RELATION_LABEL_FOR, input);
  },
  { iframe: true, remoteIframe: true }
);

/*
 * Test EMBEDS on root accessible.
 */
addAccessibleTask(
  `hello world`,
  async function (browser, primaryDocAcc, secondaryDocAcc) {
    // The root accessible should EMBED the top level
    // content document. If this test runs in an iframe,
    // the test harness will pass in doc accs for both the
    // iframe (primaryDocAcc) and the top level remote
    // browser (secondaryDocAcc). We should use the second
    // one.
    // If this is not in an iframe, we'll only get
    // a single docAcc (primaryDocAcc) which refers to
    // the top level content doc.
    const topLevelDoc = secondaryDocAcc ? secondaryDocAcc : primaryDocAcc;
    await testRelation(
      getRootAccessible(document),
      RELATION_EMBEDS,
      topLevelDoc
    );
  },
  { chrome: true, iframe: true, remoteIframe: true }
);

/**
 * Test CONTAINING_TAB_PANE
 */
addAccessibleTask(
  `<p id="p">hello world</p>`,
  async function (browser, primaryDocAcc, secondaryDocAcc) {
    // The CONTAINING_TAB_PANE of any acc should be the top level
    // content document. If this test runs in an iframe,
    // the test harness will pass in doc accs for both the
    // iframe (primaryDocAcc) and the top level remote
    // browser (secondaryDocAcc). We should use the second
    // one.
    // If this is not in an iframe, we'll only get
    // a single docAcc (primaryDocAcc) which refers to
    // the top level content doc.
    const topLevelDoc = secondaryDocAcc ? secondaryDocAcc : primaryDocAcc;
    await testCachedRelation(
      findAccessibleChildByID(primaryDocAcc, "p"),
      RELATION_CONTAINING_TAB_PANE,
      topLevelDoc
    );
  },
  {
    chrome: true,
    topLevel: true,
    iframe: true,
    remoteIframe: true,
  }
);

/*
 * Test relation caching on link
 */
addAccessibleTask(
  `
  <a id="link" href="#item">a</a>
  <div id="item">hello</div>
  <div id="item2">world</div>
  <a id="link2" href="#anchor">b</a>
  <a id="namedLink" name="anchor">c</a>`,
  async function (browser, accDoc) {
    const link = findAccessibleChildByID(accDoc, "link");
    const link2 = findAccessibleChildByID(accDoc, "link2");
    const namedLink = findAccessibleChildByID(accDoc, "namedLink");
    const item = findAccessibleChildByID(accDoc, "item");
    const item2 = findAccessibleChildByID(accDoc, "item2");

    await testCachedRelation(link, RELATION_LINKS_TO, item);
    await testCachedRelation(link2, RELATION_LINKS_TO, namedLink);

    await invokeContentTask(browser, [], () => {
      content.document.getElementById("link").href = "";
      content.document.getElementById("namedLink").name = "newName";
    });

    await testCachedRelation(link, RELATION_LINKS_TO, null);
    await testCachedRelation(link2, RELATION_LINKS_TO, null);

    await invokeContentTask(browser, [], () => {
      content.document.getElementById("link").href = "#item2";
    });

    await testCachedRelation(link, RELATION_LINKS_TO, item2);
  },
  {
    chrome: true,
    // IA2 doesn't have a LINKS_TO relation and Windows non-cached
    // RemoteAccessible uses IA2, so we can't run these tests in this case.
    topLevel: true,
    iframe: true,
    remoteIframe: true,
  }
);

/*
 * Test relation caching for NODE_CHILD_OF and NODE_PARENT_OF with aria trees.
 */
addAccessibleTask(
  `
  <div role="tree" id="tree">
    <div role="treeitem" id="treeitem">test</div>
    <div role="treeitem" id="treeitem2">test</div>
  </div>`,
  async function (browser, accDoc) {
    const tree = findAccessibleChildByID(accDoc, "tree");
    const treeItem = findAccessibleChildByID(accDoc, "treeitem");
    const treeItem2 = findAccessibleChildByID(accDoc, "treeitem2");

    await testCachedRelation(tree, RELATION_NODE_PARENT_OF, [
      treeItem,
      treeItem2,
    ]);
    await testCachedRelation(treeItem, RELATION_NODE_CHILD_OF, tree);
  },
  { chrome: true, iframe: true, remoteIframe: true }
);

/*
 * Test relation caching for NODE_CHILD_OF and NODE_PARENT_OF with aria lists.
 */
addAccessibleTask(
  `
  <div id="l1" role="list">
    <div id="l1i1" role="listitem" aria-level="1">a</div>
    <div id="l1i2" role="listitem" aria-level="2">b</div>
    <div id="l1i3" role="listitem" aria-level="1">c</div>
  </div>`,
  async function (browser, accDoc) {
    const list = findAccessibleChildByID(accDoc, "l1");
    const listItem1 = findAccessibleChildByID(accDoc, "l1i1");
    const listItem2 = findAccessibleChildByID(accDoc, "l1i2");
    const listItem3 = findAccessibleChildByID(accDoc, "l1i3");

    await testCachedRelation(list, RELATION_NODE_PARENT_OF, [
      listItem1,
      listItem3,
    ]);
    await testCachedRelation(listItem1, RELATION_NODE_CHILD_OF, list);
    await testCachedRelation(listItem3, RELATION_NODE_CHILD_OF, list);

    await testCachedRelation(listItem1, RELATION_NODE_PARENT_OF, listItem2);
    await testCachedRelation(listItem2, RELATION_NODE_CHILD_OF, listItem1);
  },
  { chrome: true, iframe: true, remoteIframe: true }
);

/*
 * Test NODE_CHILD_OF relation caching for JAWS window emulation special case.
 */
addAccessibleTask(
  ``,
  async function (browser, accDoc) {
    await testCachedRelation(accDoc, RELATION_NODE_CHILD_OF, accDoc.parent);
  },
  { topLevel: true, chrome: true }
);