Bug 1730095 - P1: Refactor text Mac marker tests. r=morgan

This change gives a bit more flexibility for isolating issues and seeing which specific marker offset is giving trouble when a test fails.

Depends on D168445

Differential Revision: https://phabricator.services.mozilla.com/D168446
This commit is contained in:
Eitan Isaacson 2023-02-22 04:52:59 +00:00
parent f826326f5f
commit 31c0b1e98c
2 changed files with 114 additions and 72 deletions

View File

@ -66,7 +66,7 @@ addAccessibleTask(
// Test misspelling in text area
addAccessibleTask(
`<textarea id="t">hello worlf</textarea>`,
`<textarea id="t">hello worlf, i love you</textarea>`,
async (browser, accDoc) => {
let textArea = getNativeInterface(accDoc, "t");
let spellDone = waitForEvent(EVENT_TEXT_ATTRIBUTE_CHANGED, "t");
@ -85,7 +85,7 @@ addAccessibleTask(
NSRange(...range)
);
if (attributedText.length != 2) {
if (attributedText.length != 3) {
spellDone = waitForEvent(EVENT_TEXT_ATTRIBUTE_CHANGED, "t");
} else {
break;

View File

@ -109,6 +109,22 @@ function testLines(
);
}
function* markerIterator(macDoc, reverse = false) {
let m = macDoc.getAttributeValue(
reverse ? "AXEndTextMarker" : "AXStartTextMarker"
);
let c = 0;
while (m) {
yield [m, c++];
m = macDoc.getParameterizedAttributeValue(
reverse
? "AXPreviousTextMarkerForTextMarker"
: "AXNextTextMarkerForTextMarker",
m
);
}
}
// Tests consistency in text markers between:
// 1. "Linked list" forward navagation
// 2. Getting markers by index
@ -119,59 +135,21 @@ function testMarkerIntegrity(accDoc, expectedMarkerValues) {
Ci.nsIAccessibleMacInterface
);
let count = 0;
// Iterate forward with "AXNextTextMarkerForTextMarker"
let marker = macDoc.getAttributeValue("AXStartTextMarker");
while (marker) {
let index = macDoc.getParameterizedAttributeValue(
let prevMarker;
let count = 0;
for (let [marker, index] of markerIterator(macDoc)) {
count++;
let markerIndex = macDoc.getParameterizedAttributeValue(
"AXIndexForTextMarker",
marker
);
is(
markerIndex,
index,
count,
`Correct index in "AXNextTextMarkerForTextMarker": ${count}`
`Correct index in "AXNextTextMarkerForTextMarker": ${index}`
);
testWords(
macDoc,
marker,
`At index ${count}`,
...expectedMarkerValues[count].words
);
testLines(
macDoc,
marker,
`At index ${count}`,
...expectedMarkerValues[count].lines
);
testUIElement(
macDoc,
marker,
`At index ${count}`,
...expectedMarkerValues[count].element
);
testParagraph(
macDoc,
marker,
`At index ${count}`,
expectedMarkerValues[count].paragraph
);
testStyleRun(
macDoc,
marker,
`At index ${count}`,
expectedMarkerValues[count].style
);
let prevMarker = marker;
marker = macDoc.getParameterizedAttributeValue(
"AXNextTextMarkerForTextMarker",
marker
);
if (marker) {
if (prevMarker) {
let range = macDoc.getParameterizedAttributeValue(
"AXTextMarkerRangeForUnorderedTextMarkers",
[prevMarker, marker]
@ -182,34 +160,76 @@ function testMarkerIntegrity(accDoc, expectedMarkerValues) {
range
),
1,
"marker moved one character"
`[${index}] marker moved one character`
);
}
prevMarker = marker;
count++;
testWords(
macDoc,
marker,
`At index ${index}`,
...expectedMarkerValues[index].words
);
testLines(
macDoc,
marker,
`At index ${index}`,
...expectedMarkerValues[index].lines
);
testUIElement(
macDoc,
marker,
`At index ${index}`,
...expectedMarkerValues[index].element
);
testParagraph(
macDoc,
marker,
`At index ${index}`,
expectedMarkerValues[index].paragraph
);
testStyleRun(
macDoc,
marker,
`At index ${index}`,
expectedMarkerValues[index].style
);
}
is(expectedMarkerValues.length, count, `Correct marker count: ${count}`);
// Use "AXTextMarkerForIndex" to retrieve all text markers
for (let i = 0; i < count; i++) {
marker = macDoc.getParameterizedAttributeValue("AXTextMarkerForIndex", i);
let marker = macDoc.getParameterizedAttributeValue(
"AXTextMarkerForIndex",
i
);
let index = macDoc.getParameterizedAttributeValue(
"AXIndexForTextMarker",
marker
);
is(index, i, `Correct index in "AXTextMarkerForIndex": ${i}`);
if (i == count - 1) {
ok(
!macDoc.getParameterizedAttributeValue(
"AXNextTextMarkerForTextMarker",
marker
),
"Iterated through all markers"
);
}
}
ok(
!macDoc.getParameterizedAttributeValue(
"AXNextTextMarkerForTextMarker",
marker
),
"Iterated through all markers"
);
count = expectedMarkerValues.length;
// Iterate backward with "AXPreviousTextMarkerForTextMarker"
marker = macDoc.getAttributeValue("AXEndTextMarker");
while (marker) {
for (let [marker] of markerIterator(macDoc, true)) {
if (count <= 0) {
ok(false, "Exceeding marker count");
break;
}
count--;
let index = macDoc.getParameterizedAttributeValue(
"AXIndexForTextMarker",
@ -220,25 +240,17 @@ function testMarkerIntegrity(accDoc, expectedMarkerValues) {
count,
`Correct index in "AXPreviousTextMarkerForTextMarker": ${count}`
);
marker = macDoc.getParameterizedAttributeValue(
"AXPreviousTextMarkerForTextMarker",
marker
);
}
is(count, 0, "Iterated backward through all text markers");
}
addAccessibleTask("mac/doc_textmarker_test.html", async (browser, accDoc) => {
const expectedMarkerValues = await SpecialPowers.spawn(
browser,
[],
async () => {
return content.wrappedJSObject.EXPECTED;
}
);
const expectedValues = await SpecialPowers.spawn(browser, [], async () => {
return content.wrappedJSObject.EXPECTED;
});
testMarkerIntegrity(accDoc, expectedMarkerValues);
testMarkerIntegrity(accDoc, expectedValues);
});
// Test text marker lesser-than operator
@ -317,3 +329,33 @@ addAccessibleTask(
});
}
);
addAccessibleTask(
`<a href="#">link</a> <input id="input" value="hello">`,
async (browser, accDoc) => {
let macDoc = accDoc.nativeInterface.QueryInterface(
Ci.nsIAccessibleMacInterface
);
let input = getNativeInterface(accDoc, "input");
let range = macDoc.getParameterizedAttributeValue(
"AXTextMarkerRangeForUIElement",
input
);
let firstMarkerInInput = macDoc.getParameterizedAttributeValue(
"AXStartTextMarkerForTextMarkerRange",
range
);
let leftWordRange = macDoc.getParameterizedAttributeValue(
"AXLeftWordTextMarkerRangeForTextMarker",
firstMarkerInInput
);
let str = macDoc.getParameterizedAttributeValue(
"AXStringForTextMarkerRange",
leftWordRange
);
is(str, "hello", "Left word at start of input should be right word");
}
);