summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/mac/browser_navigate.js
blob: 69486676e49daa03f4c660bc9a528b0f5d03f0c5 (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
/* 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";

/**
 * Test navigation of same/different type content
 */
addAccessibleTask(
  `<h1 id="hello">hello</h1>
  world<br>
  <a href="example.com" id="link">I am a link</a>
  <h1 id="goodbye">goodbye</h1>`,
  async (browser, accDoc) => {
    const searchPred = {
      AXSearchKey: "AXSameTypeSearchKey",
      AXImmediateDescendantsOnly: 0,
      AXResultsLimit: 1,
      AXDirection: "AXDirectionNext",
    };

    const hello = getNativeInterface(accDoc, "hello");
    const goodbye = getNativeInterface(accDoc, "goodbye");
    const webArea = accDoc.nativeInterface.QueryInterface(
      Ci.nsIAccessibleMacInterface
    );

    searchPred.AXStartElement = hello;

    let sameItem = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(sameItem.length, 1, "Found one item");
    is(
      "goodbye",
      sameItem[0].getAttributeValue("AXTitle"),
      "Found correct item of same type"
    );

    searchPred.AXDirection = "AXDirectionPrevious";
    searchPred.AXStartElement = goodbye;
    sameItem = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(sameItem.length, 1, "Found one item");
    is(
      "hello",
      sameItem[0].getAttributeValue("AXTitle"),
      "Found correct item of same type"
    );

    searchPred.AXSearchKey = "AXDifferentTypeSearchKey";
    let diffItem = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );
    is(diffItem.length, 1, "Found one item");
    is(
      "I am a link",
      diffItem[0].getAttributeValue("AXValue"),
      "Found correct item of different type"
    );
  }
);

/**
 * Test navigation of heading levels
 */
addAccessibleTask(
  `
  <h1 id="a">a</h1>
  <h2 id="b">b</h2>
  <h3 id="c">c</h3>
  <h4 id="d">d</h4>
  <h5 id="e">e</h5>
  <h6 id="f">f</h5>
  <h1 id="g">g</h1>
  <h2 id="h">h</h2>
  <h3 id="i">i</h3>
  <h4 id="j">j</h4>
  <h5 id="k">k</h5>
  <h6 id="l">l</h5>
  this is some regular text that should be ignored
  `,
  async (browser, accDoc) => {
    const searchPred = {
      AXSearchKey: "AXHeadingLevel1SearchKey",
      AXImmediateDescendantsOnly: 0,
      AXResultsLimit: -1,
      AXDirection: "AXDirectionNext",
    };

    const webArea = accDoc.nativeInterface.QueryInterface(
      Ci.nsIAccessibleMacInterface
    );

    let h1Count = webArea.getParameterizedAttributeValue(
      "AXUIElementCountForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(2, h1Count, "Found two h1 items");

    let h1s = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    const a = getNativeInterface(accDoc, "a");
    const g = getNativeInterface(accDoc, "g");

    is(
      a.getAttributeValue("AXValue"),
      h1s[0].getAttributeValue("AXValue"),
      "Found correct h1 heading"
    );

    is(
      g.getAttributeValue("AXValue"),
      h1s[1].getAttributeValue("AXValue"),
      "Found correct h1 heading"
    );

    searchPred.AXSearchKey = "AXHeadingLevel2SearchKey";

    let h2Count = webArea.getParameterizedAttributeValue(
      "AXUIElementCountForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(2, h2Count, "Found two h2 items");

    let h2s = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    const b = getNativeInterface(accDoc, "b");
    const h = getNativeInterface(accDoc, "h");

    is(
      b.getAttributeValue("AXValue"),
      h2s[0].getAttributeValue("AXValue"),
      "Found correct h2 heading"
    );

    is(
      h.getAttributeValue("AXValue"),
      h2s[1].getAttributeValue("AXValue"),
      "Found correct h2 heading"
    );

    searchPred.AXSearchKey = "AXHeadingLevel3SearchKey";

    let h3Count = webArea.getParameterizedAttributeValue(
      "AXUIElementCountForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(2, h3Count, "Found two h3 items");

    let h3s = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    const c = getNativeInterface(accDoc, "c");
    const i = getNativeInterface(accDoc, "i");

    is(
      c.getAttributeValue("AXValue"),
      h3s[0].getAttributeValue("AXValue"),
      "Found correct h3 heading"
    );

    is(
      i.getAttributeValue("AXValue"),
      h3s[1].getAttributeValue("AXValue"),
      "Found correct h3 heading"
    );

    searchPred.AXSearchKey = "AXHeadingLevel4SearchKey";

    let h4Count = webArea.getParameterizedAttributeValue(
      "AXUIElementCountForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(2, h4Count, "Found two h4 items");

    let h4s = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    const d = getNativeInterface(accDoc, "d");
    const j = getNativeInterface(accDoc, "j");

    is(
      d.getAttributeValue("AXValue"),
      h4s[0].getAttributeValue("AXValue"),
      "Found correct h4 heading"
    );

    is(
      j.getAttributeValue("AXValue"),
      h4s[1].getAttributeValue("AXValue"),
      "Found correct h4 heading"
    );

    searchPred.AXSearchKey = "AXHeadingLevel5SearchKey";

    let h5Count = webArea.getParameterizedAttributeValue(
      "AXUIElementCountForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(2, h5Count, "Found two h5 items");

    let h5s = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    const e = getNativeInterface(accDoc, "e");
    const k = getNativeInterface(accDoc, "k");

    is(
      e.getAttributeValue("AXValue"),
      h5s[0].getAttributeValue("AXValue"),
      "Found correct h5 heading"
    );

    is(
      k.getAttributeValue("AXValue"),
      h5s[1].getAttributeValue("AXValue"),
      "Found correct h5 heading"
    );

    searchPred.AXSearchKey = "AXHeadingLevel6SearchKey";

    let h6Count = webArea.getParameterizedAttributeValue(
      "AXUIElementCountForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(2, h6Count, "Found two h6 items");

    let h6s = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    const f = getNativeInterface(accDoc, "f");
    const l = getNativeInterface(accDoc, "l");

    is(
      f.getAttributeValue("AXValue"),
      h6s[0].getAttributeValue("AXValue"),
      "Found correct h6 heading"
    );

    is(
      l.getAttributeValue("AXValue"),
      h6s[1].getAttributeValue("AXValue"),
      "Found correct h6 heading"
    );
  }
);

/*
 * Test rotor with blockquotes
 */
addAccessibleTask(
  `
  <blockquote id="first">hello I am a blockquote</blockquote>
  <blockquote id="second">
    I am also a blockquote of the same level
    <br>
    <blockquote id="third">but I have a different level</blockquote>
  </blockquote>
  `,
  (browser, accDoc) => {
    let searchPred = {
      AXSearchKey: "AXBlockquoteSearchKey",
      AXImmediateDescendantsOnly: 0,
      AXResultsLimit: -1,
      AXDirection: "AXDirectionNext",
    };

    const webArea = accDoc.nativeInterface.QueryInterface(
      Ci.nsIAccessibleMacInterface
    );
    is(
      webArea.getAttributeValue("AXRole"),
      "AXWebArea",
      "Got web area accessible"
    );

    let bquotes = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(bquotes.length, 3, "Found three blockquotes");

    const first = getNativeInterface(accDoc, "first");
    const second = getNativeInterface(accDoc, "second");
    const third = getNativeInterface(accDoc, "third");
    console.log("values :");
    console.log(first.getAttributeValue("AXValue"));
    is(
      first.getAttributeValue("AXValue"),
      bquotes[0].getAttributeValue("AXValue"),
      "Found correct first blockquote"
    );

    is(
      second.getAttributeValue("AXValue"),
      bquotes[1].getAttributeValue("AXValue"),
      "Found correct second blockquote"
    );

    is(
      third.getAttributeValue("AXValue"),
      bquotes[2].getAttributeValue("AXValue"),
      "Found correct third blockquote"
    );
  }
);

/*
 * Test rotor with graphics
 */
addAccessibleTask(
  `
  <img id="img1" alt="image one" src="http://example.com/a11y/accessible/tests/mochitest/moz.png"><br>
  <a href="http://example.com">
    <img id="img2" alt="image two" src="http://example.com/a11y/accessible/tests/mochitest/moz.png">
  </a>
  <img src="" id="img3">
  `,
  (browser, accDoc) => {
    let searchPred = {
      AXSearchKey: "AXGraphicSearchKey",
      AXImmediateDescendantsOnly: 0,
      AXResultsLimit: -1,
      AXDirection: "AXDirectionNext",
    };

    const webArea = accDoc.nativeInterface.QueryInterface(
      Ci.nsIAccessibleMacInterface
    );
    is(
      webArea.getAttributeValue("AXRole"),
      "AXWebArea",
      "Got web area accessible"
    );

    let images = webArea.getParameterizedAttributeValue(
      "AXUIElementsForSearchPredicate",
      NSDictionary(searchPred)
    );

    is(images.length, 3, "Found three images");

    const img1 = getNativeInterface(accDoc, "img1");
    const img2 = getNativeInterface(accDoc, "img2");
    const img3 = getNativeInterface(accDoc, "img3");

    is(
      img1.getAttributeValue("AXDescription"),
      images[0].getAttributeValue("AXDescription"),
      "Found correct image"
    );

    is(
      img2.getAttributeValue("AXDescription"),
      images[1].getAttributeValue("AXDescription"),
      "Found correct image"
    );

    is(
      img3.getAttributeValue("AXDescription"),
      images[2].getAttributeValue("AXDescription"),
      "Found correct image"
    );
  }
);