summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/text/browser_textleafpoint.js
blob: 894e9821424bfee2adafb2c7ac63e219b8641ce2 (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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/* 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/text.js */

addAccessibleTask(
  `
  <p id="p" style="white-space: pre-line;">A bug
h<a href="#">id i</a>n
the <strong>big</strong> rug.</p>
`,
  function (browser, docAcc) {
    const container = findAccessibleChildByID(docAcc, "p");
    const firstPoint = createTextLeafPoint(container, 0);
    const lastPoint = createTextLeafPoint(container, kTextEndOffset);

    let charSequence = [
      ...textBoundaryGenerator(firstPoint, BOUNDARY_CHAR, DIRECTION_NEXT),
    ];

    testPointEqual(
      firstPoint,
      charSequence[0],
      "Point constructed via container and offset 0 is first character point."
    );
    testPointEqual(
      lastPoint,
      charSequence[charSequence.length - 1],
      "Point constructed via container and kTextEndOffset is last character point."
    );

    const expectedCharSequence = [
      ["A bug\nh", 0],
      ["A bug\nh", 1],
      ["A bug\nh", 2],
      ["A bug\nh", 3],
      ["A bug\nh", 4],
      ["A bug\nh", 5],
      ["A bug\nh", 6],
      ["id i", 0],
      ["id i", 1],
      ["id i", 2],
      ["id i", 3],
      ["n\nthe ", 0],
      ["n\nthe ", 1],
      ["n\nthe ", 2],
      ["n\nthe ", 3],
      ["n\nthe ", 4],
      ["n\nthe ", 5],
      ["big", 0],
      ["big", 1],
      ["big", 2],
      [" rug.", 0],
      [" rug.", 1],
      [" rug.", 2],
      [" rug.", 3],
      [" rug.", 4],
      [" rug.", 5],
    ];

    testBoundarySequence(
      firstPoint,
      BOUNDARY_CHAR,
      DIRECTION_NEXT,
      expectedCharSequence,
      "Forward BOUNDARY_CHAR sequence is correct"
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_CHAR,
      DIRECTION_PREVIOUS,
      [...expectedCharSequence].reverse(),
      "Backward BOUNDARY_CHAR sequence is correct"
    );

    const expectedWordStartSequence = [
      ["A bug\nh", 0],
      ["A bug\nh", 2],
      ["A bug\nh", 6],
      ["id i", 3],
      ["n\nthe ", 2],
      ["big", 0],
      [" rug.", 1],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_WORD_START,
      DIRECTION_NEXT,
      // Add last point in doc
      [...expectedWordStartSequence, readablePoint(lastPoint)],
      "Forward BOUNDARY_WORD_START sequence is correct"
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_WORD_START,
      DIRECTION_PREVIOUS,
      [...expectedWordStartSequence].reverse(),
      "Backward BOUNDARY_WORD_START sequence is correct"
    );

    const expectedWordEndSequence = [
      ["A bug\nh", 1],
      ["A bug\nh", 5],
      ["id i", 2],
      ["n\nthe ", 1],
      ["n\nthe ", 5],
      [" rug.", 0],
      [" rug.", 5],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_WORD_END,
      DIRECTION_NEXT,
      expectedWordEndSequence,
      "Forward BOUNDARY_WORD_END sequence is correct"
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_WORD_END,
      DIRECTION_PREVIOUS,
      [readablePoint(firstPoint), ...expectedWordEndSequence].reverse(),
      "Backward BOUNDARY_WORD_END sequence is correct"
    );

    const expectedLineStartSequence = [
      ["A bug\nh", 0],
      ["A bug\nh", 6],
      ["n\nthe ", 2],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_LINE_START,
      DIRECTION_NEXT,
      // Add last point in doc
      [...expectedLineStartSequence, readablePoint(lastPoint)],
      "Forward BOUNDARY_LINE_START sequence is correct"
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_LINE_START,
      DIRECTION_PREVIOUS,
      [...expectedLineStartSequence].reverse(),
      "Backward BOUNDARY_LINE_START sequence is correct"
    );

    const expectedLineEndSequence = [
      ["A bug\nh", 5],
      ["n\nthe ", 1],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_LINE_END,
      DIRECTION_NEXT,
      // Add last point in doc
      [...expectedLineEndSequence, readablePoint(lastPoint)],
      "Forward BOUNDARY_LINE_END sequence is correct",
      { todo: true }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_LINE_END,
      DIRECTION_PREVIOUS,
      [readablePoint(firstPoint), ...expectedLineEndSequence].reverse(),
      "Backward BOUNDARY_LINE_END sequence is correct"
    );
  },
  { chrome: true, topLevel: true, iframe: false, remoteIframe: false }
);

addAccessibleTask(
  `<p id="p">
    Rob ca<input id="i1" value="n m">op up.
  </p>`,
  function (browser, docAcc) {
    const container = findAccessibleChildByID(docAcc, "p");
    const firstPoint = createTextLeafPoint(container, 0);
    const lastPoint = createTextLeafPoint(container, kTextEndOffset);

    testBoundarySequence(
      firstPoint,
      BOUNDARY_CHAR,
      DIRECTION_NEXT,
      [
        ["Rob ca", 0],
        ["Rob ca", 1],
        ["Rob ca", 2],
        ["Rob ca", 3],
        ["Rob ca", 4],
        ["Rob ca", 5],
        ["n m", 0],
        ["n m", 1],
        ["n m", 2],
        ["n m", 3],
      ],
      "Forward BOUNDARY_CHAR sequence when stopping in editable is correct",
      { flags: BOUNDARY_FLAG_STOP_IN_EDITABLE }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_CHAR,
      DIRECTION_PREVIOUS,
      [
        ["op up. ", 7],
        ["op up. ", 6],
        ["op up. ", 5],
        ["op up. ", 4],
        ["op up. ", 3],
        ["op up. ", 2],
        ["op up. ", 1],
        ["op up. ", 0],
        ["n m", 2],
        ["n m", 1],
        ["n m", 0],
      ],
      "Backward BOUNDARY_CHAR sequence when stopping in editable is correct",
      { flags: BOUNDARY_FLAG_STOP_IN_EDITABLE }
    );

    testBoundarySequence(
      firstPoint,
      BOUNDARY_WORD_START,
      DIRECTION_NEXT,
      [
        ["Rob ca", 0],
        ["Rob ca", 4],
        ["n m", 2],
      ],
      "Forward BOUNDARY_WORD_START sequence when stopping in editable is correct",
      {
        flags: BOUNDARY_FLAG_STOP_IN_EDITABLE,
        todo: true, //  Shouldn't consider end of input a word start
      }
    );
  },
  { chrome: true, topLevel: true, iframe: false, remoteIframe: false }
);

addAccessibleTask(
  `
  <p id="p" style="white-space: pre-line;">A bug
on a <span style="display: block;">rug</span></p>
  <p id="p2">
    Numbers:
  </p>
  <ul>
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
  </ul>`,
  function (browser, docAcc) {
    const firstPoint = createTextLeafPoint(docAcc, 0);
    const lastPoint = createTextLeafPoint(docAcc, kTextEndOffset);

    const expectedParagraphStart = [
      ["A bug\non a ", 0],
      ["A bug\non a ", 6],
      ["rug", 0],
      ["Numbers: ", 0],
      ["• ", 0],
      ["• ", 0],
      ["• ", 0],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_PARAGRAPH,
      DIRECTION_NEXT,
      [...expectedParagraphStart, readablePoint(lastPoint)],
      "Forward BOUNDARY_PARAGRAPH sequence is correct"
    );

    const paragraphStart = createTextLeafPoint(
      findAccessibleChildByID(docAcc, "p2").firstChild,
      0
    );
    const wordEnd = paragraphStart.findBoundary(
      BOUNDARY_WORD_END,
      DIRECTION_NEXT,
      BOUNDARY_FLAG_INCLUDE_ORIGIN
    );
    testPointEqual(
      wordEnd,
      paragraphStart,
      "The word end from the previous block is the first point in this block"
    );
  },
  { chrome: true, topLevel: true, iframe: false, remoteIframe: false }
);

// Test for skipping list item bullets.
addAccessibleTask(
  `<ul>
    <li>One</li>
    <li>Two</li>
    <li style="white-space: pre-line;">Three
Four</li>
  </ul>`,
  function (browser, docAcc) {
    const firstPoint = createTextLeafPoint(docAcc, 0);
    const lastPoint = createTextLeafPoint(docAcc, kTextEndOffset);

    const firstNonMarkerPoint = firstPoint.findBoundary(
      BOUNDARY_CHAR,
      DIRECTION_NEXT,
      BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER | BOUNDARY_FLAG_INCLUDE_ORIGIN
    );
    Assert.deepEqual(
      readablePoint(firstNonMarkerPoint),
      ["One", 0],
      "First non-marker point is correct"
    );

    const expectedParagraphStart = [
      ["One", 0],
      ["Two", 0],
      ["Three\nFour", 0],
      ["Three\nFour", 6],
    ];

    testBoundarySequence(
      firstPoint,
      BOUNDARY_PARAGRAPH,
      DIRECTION_NEXT,
      [...expectedParagraphStart, readablePoint(lastPoint)],
      "Forward BOUNDARY_PARAGRAPH skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_PARAGRAPH,
      DIRECTION_PREVIOUS,
      [...expectedParagraphStart].reverse(),
      "Backward BOUNDARY_PARAGRAPH skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    const expectedCharSequence = [
      ["One", 0],
      ["One", 1],
      ["One", 2],
      ["Two", 0],
      ["Two", 1],
      ["Two", 2],
      ["Three\nFour", 0],
      ["Three\nFour", 1],
      ["Three\nFour", 2],
      ["Three\nFour", 3],
      ["Three\nFour", 4],
      ["Three\nFour", 5],
      ["Three\nFour", 6],
      ["Three\nFour", 7],
      ["Three\nFour", 8],
      ["Three\nFour", 9],
      ["Three\nFour", 10],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_CHAR,
      DIRECTION_NEXT,
      expectedCharSequence,
      "Forward BOUNDARY_CHAR skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_CHAR,
      DIRECTION_PREVIOUS,
      [...expectedCharSequence].reverse(),
      "Backward BOUNDARY_CHAR skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    const expectedWordStartSequence = [
      ["One", 0],
      ["Two", 0],
      ["Three\nFour", 0],
      ["Three\nFour", 6],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_WORD_START,
      DIRECTION_NEXT,
      [...expectedWordStartSequence, readablePoint(lastPoint)],
      "Forward BOUNDARY_WORD_START skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_WORD_START,
      DIRECTION_PREVIOUS,
      [...expectedWordStartSequence].reverse(),
      "Backward BOUNDARY_WORD_START skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    const expectedWordEndSequence = [
      ["Two", 0],
      ["Three\nFour", 0],
      ["Three\nFour", 5],
      ["Three\nFour", 10],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_WORD_END,
      DIRECTION_NEXT,
      expectedWordEndSequence,
      "Forward BOUNDARY_WORD_END skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_WORD_END,
      DIRECTION_PREVIOUS,
      [
        readablePoint(firstNonMarkerPoint),
        ...expectedWordEndSequence,
      ].reverse(),
      "Backward BOUNDARY_WORD_END skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    const expectedLineStartSequence = [
      ["One", 0],
      ["Two", 0],
      ["Three\nFour", 0],
      ["Three\nFour", 6],
    ];
    testBoundarySequence(
      firstPoint,
      BOUNDARY_LINE_START,
      DIRECTION_NEXT,
      // Add last point in doc
      [...expectedLineStartSequence, readablePoint(lastPoint)],
      "Forward BOUNDARY_LINE_START skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );

    testBoundarySequence(
      lastPoint,
      BOUNDARY_LINE_START,
      DIRECTION_PREVIOUS,
      // Add last point in doc
      [...expectedLineStartSequence].reverse(),
      "Backward BOUNDARY_LINE_START skipping list item markers sequence is correct",
      { flags: BOUNDARY_FLAG_SKIP_LIST_ITEM_MARKER }
    );
  },
  { chrome: true, topLevel: true, iframe: false, remoteIframe: false }
);

/**
 * Test the paragraph boundary on tables.
 */
addAccessibleTask(
  `
<table id="table">
  <tr><th>a</th><td>b</td></tr>
  <tr><td>c</td><td>d</td></tr>
</table>
  `,
  async function (browser, docAcc) {
    const firstPoint = createTextLeafPoint(docAcc, 0);
    const lastPoint = createTextLeafPoint(docAcc, kTextEndOffset);
    testBoundarySequence(
      firstPoint,
      BOUNDARY_PARAGRAPH,
      DIRECTION_NEXT,
      [["a", 0], ["b", 0], ["c", 0], ["d", 0], readablePoint(lastPoint)],
      "Forward BOUNDARY_PARAGRAPH sequence is correct"
    );
  },
  { chrome: true, topLevel: true, iframe: false, remoteIframe: false }
);