Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE html>
<html>
<head>
<title>nsIHyper>TextAccessible in dynamic tests</title>
<link rel="stylesheet" type="text/css"
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../promisified-events.js"></script>
<script type="application/javascript">
// gA11yEventDumpToConsole = true; // debug stuff
const kLinksCount = 128;
async function doTest() {
// addLinks
const p1Node = getNode("p1");
let reordered = waitForEvent(EVENT_REORDER, p1Node);
for (let jdx = 0; jdx < kLinksCount; jdx++) {
const a = document.createElement("a");
a.setAttribute("href", "mozilla.org");
a.textContent = "mozilla";
p1Node.appendChild(a);
const span = document.createElement("span");
span.textContent = " text ";
p1Node.appendChild(span);
}
await reordered;
// getLinkAt and getLinkIndex.
const p1Acc = getAccessible(p1Node, [nsIAccessibleHyperText]);
for (let idx = 0; idx < kLinksCount; idx++) {
const link = p1Acc.getLinkAt(idx);
ok(link, "No link at index " + idx + " for 'p1'");
const linkIdx = p1Acc.getLinkIndex(link);
is(linkIdx, idx, "Wrong link index for 'p1'!");
}
// updateText
const p2Node = getNode("p2");
const p2Acc = getAccessible(p2Node, nsIAccessibleHyperText);
const textAcc = p2Acc.firstChild;
const textNode = textAcc.DOMNode;
const textLen = textNode.data.length;
is(p2Acc.getLinkIndexAtOffset(textLen), 0, "Wrong intial text offsets!");
let inserted = waitForEvent(EVENT_TEXT_INSERTED, p2Node);
textNode.appendData(" my");
await inserted;
is(
p2Acc.getLinkIndexAtOffset(textLen),
-1,
"Text offsets weren't updated!"
);
// removeChild
const div1Node = getNode("div1");
const div1Acc = getAccessible(div1Node, nsIAccessibleText);
const div2Node = getNode("div2");
// Call first to getText so offsets are cached
is(div1Acc.getText(0, -1), "hello my good friend",
"Wrong text before child removal");
reordered = waitForEvent(EVENT_REORDER, div1Node);
div1Node.removeChild(div2Node);
await reordered;
is(div1Acc.getText(0, -1), "hello friend",
"Wrong text after child removal");
is(div1Acc.characterCount, "hello friend".length,
"Wrong text after child removal");
// removeFirstChild
const c4Node = getNode("c4");
const c4Acc = getAccessible(c4Node, [nsIAccessibleHyperText]);
is(c4Acc.linkCount, 2, "Wrong embedded objects count before removal");
reordered = waitForEvent(EVENT_REORDER, c4Node);
c4Node.removeChild(c4Node.firstElementChild);
await reordered;
// check list index before link count
is(c4Acc.getLinkIndex(c4Acc.firstChild), 0, "Wrong child index");
is(c4Acc.linkCount, 1, "Wrong embedded objects count after removal");
// removeLastChild
const c5Node = getNode("c5");
const c5Acc = getAccessible(c5Node, [nsIAccessibleHyperText]);
is(c5Acc.linkCount, 1, "Wrong embedded objects count before removal");
reordered = waitForEvent(EVENT_REORDER, c5Node);
c5Node.removeChild(c5Node.lastElementChild);
await reordered;
is(c5Acc.linkCount, 0, "Wrong embedded objects count after removal");
let lastLink = null;
try {
lastLink = c5Acc.getLinkAt(0);
} catch (e) { }
ok(!lastLink, "No embedded object is expected");
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank"
title="Cache links within hypertext accessible"
Mozilla Bug 572394
</a>
<a target="_blank"
title="Text offsets don't get updated when text of first child text accessible is changed"
Mozilla Bug 625009
</a>
<a target="_blank"
title="Crash in nsHyperTextAccessible::GetText()"
Mozilla Bug 630841
</a><br>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<p id="p1"></p>
<p id="p2"><b>hello</b><a>friend</a></p>
<div id="div1">hello<span id="div2"> my<span id="div3"> good</span></span> friend</span></div>
<form id="c4">
<label for="c4_input">label</label>
<input id="c4_input">
</form>
<div id="c5">TextLeaf<input id="c5_input"></div>
</body>
</html>