|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +"use strict"; |
| 6 | + |
| 7 | +/* import-globals-from ../../mochitest/text.js */ |
| 8 | +loadScripts({ name: "text.js", dir: MOCHITESTS_DIR }); |
| 9 | + |
| 10 | +const isCacheEnabled = Services.prefs.getBoolPref( |
| 11 | + "accessibility.cache.enabled", |
| 12 | + false |
| 13 | +); |
| 14 | + |
| 15 | +/** |
| 16 | + * Test line and word offsets for various cases for both local and remote |
| 17 | + * Accessibles. There is more extensive coverage in ../../mochitest/text. These |
| 18 | + * tests don't need to duplicate all of that, since much of the underlying code |
| 19 | + * is unified. They should ensure that the cache works as expected and that |
| 20 | + * there is consistency between local and remote. |
| 21 | + */ |
| 22 | +addAccessibleTask( |
| 23 | + ` |
| 24 | +<p id="br">ab cd<br>ef gh</p> |
| 25 | +<pre id="pre">ab cd |
| 26 | +ef gh</pre> |
| 27 | +<p id="linksStartEnd"><a href="https://example.com/">a</a>b<a href="https://example.com/">c</a></p> |
| 28 | +<p id="linksBreaking">a<a href="https://example.com/">b<br>c</a>d</p> |
| 29 | + `, |
| 30 | + async function(browser, docAcc) { |
| 31 | + for (const id of ["br", "pre"]) { |
| 32 | + const acc = findAccessibleChildByID(docAcc, id); |
| 33 | + if (!isCacheEnabled && AppConstants.platform == "win") { |
| 34 | + todo( |
| 35 | + false, |
| 36 | + "Cache disabled, so RemoteAccessible doesn't support CharacterCount on Windows" |
| 37 | + ); |
| 38 | + } else { |
| 39 | + testCharacterCount([acc], 11); |
| 40 | + } |
| 41 | + testTextAtOffset(acc, BOUNDARY_LINE_START, [ |
| 42 | + [0, 5, "ab cd\n", 0, 6], |
| 43 | + [6, 11, "ef gh", 6, 11], |
| 44 | + ]); |
| 45 | + testTextAtOffset(acc, BOUNDARY_WORD_START, [ |
| 46 | + [0, 2, "ab ", 0, 3], |
| 47 | + [3, 5, "cd\n", 3, 6], |
| 48 | + [6, 8, "ef ", 6, 9], |
| 49 | + [9, 11, "gh", 9, 11], |
| 50 | + ]); |
| 51 | + } |
| 52 | + const linksStartEnd = findAccessibleChildByID(docAcc, "linksStartEnd"); |
| 53 | + testTextAtOffset(linksStartEnd, BOUNDARY_LINE_START, [ |
| 54 | + [0, 3, `${kEmbedChar}b${kEmbedChar}`, 0, 3], |
| 55 | + ]); |
| 56 | + testTextAtOffset(linksStartEnd, BOUNDARY_WORD_START, [ |
| 57 | + [0, 3, `${kEmbedChar}b${kEmbedChar}`, 0, 3], |
| 58 | + ]); |
| 59 | + const linksBreaking = findAccessibleChildByID(docAcc, "linksBreaking"); |
| 60 | + testTextAtOffset(linksBreaking, BOUNDARY_LINE_START, [ |
| 61 | + [0, 0, `a${kEmbedChar}`, 0, 2], |
| 62 | + [1, 1, `a${kEmbedChar}d`, 0, 3], |
| 63 | + [2, 3, `${kEmbedChar}d`, 1, 3], |
| 64 | + ]); |
| 65 | + if (isCacheEnabled) { |
| 66 | + testTextAtOffset(linksBreaking, BOUNDARY_WORD_START, [ |
| 67 | + [0, 0, `a${kEmbedChar}`, 0, 2], |
| 68 | + [1, 1, `a${kEmbedChar}d`, 0, 3], |
| 69 | + [2, 3, `${kEmbedChar}d`, 1, 3], |
| 70 | + ]); |
| 71 | + } else { |
| 72 | + todo( |
| 73 | + false, |
| 74 | + "TextLeafPoint disabled, so word boundaries are incorrect for linksBreaking" |
| 75 | + ); |
| 76 | + } |
| 77 | + }, |
| 78 | + { chrome: true, topLevel: true, iframe: true, remoteIframe: true } |
| 79 | +); |
0 commit comments