gecko/accessible/tests/mochitest/test_nsIAccessible_focus.html

143 lines
4.0 KiB
HTML
Raw Normal View History

<html>
<head>
<title>nsIAccessible::takeFocus testing</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/common.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/a11y/accessible/events.js"></script>
<script type="application/javascript">
////////////////////////////////////////////////////////////////////////////
// Test
function doTest()
{
// focus ARIA link
var ID = "aria-link";
var linkAcc = getAccessible(ID);
gFocusManager.listenElement(linkAcc, ID, doTest2);
linkAcc.takeFocus();
}
function doTest2()
{
// focus first child of ARIA link
var ID = "aria-link2";
var linkAcc = getAccessible(ID);
gFocusManager.listenElement(linkAcc, ID, doTest3);
linkAcc.firstChild.takeFocus();
}
function doTest3()
{
// focus html:a
var ID = "link";
var linkAcc = getAccessible(ID);
gFocusManager.listenElement(linkAcc, ID, finishTest);
linkAcc.takeFocus();
}
function finishTest()
{
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
////////////////////////////////////////////////////////////////////////////
// Helpers
var gFocusManager =
{
// Public
listenElement: function listenElement(aAccOrID, aPrettyName, aCallback)
{
registerA11yEventListener(nsIAccessibleEvent.EVENT_FOCUS, this);
var elmObj = {};
this.mAcc = getAccessible(aAccOrID, null, elmObj);
this.mElm = elmObj.value;
this.mName = aPrettyName ? aPrettyName : aAccOrID;
this.mCallback = aCallback;
window.setTimeout(
function(aFocusMgr)
{
aFocusMgr.checkWasFocusHandled();
}, 0, this);
},
// Private
handleEvent: function handleEvent(aAccEvent)
{
var node = aAccEvent.DOMNode;
if (node == this.mElm)
this.mIsFocusHandled = true;
},
checkWasFocusHandled: function checkWasFocusHandled()
{
window.setTimeout(
function(aFocusMgr)
{
unregisterA11yEventListener(nsIAccessibleEvent.EVENT_FOCUS, this);
ok(aFocusMgr.mIsFocusHandled,
"Focus wasn't received for element with ID " + aFocusMgr.mName + ".");
var states = {}, extraStates = {};
aFocusMgr.mAcc.getState(states, extraStates);
// XXX see bug 455840. Only fails on aria-link, the other two are OK.
// When fixing this bug, remove the if statement and else block and "todo" statement.
if (states.value & nsIAccessibleStates.STATE_FOCUSED)
ok(states.value & nsIAccessibleStates.STATE_FOCUSED,
"No focused state for element with ID " + aFocusMgr.mName + ".");
else
todo(states.value & nsIAccessibleStates.STATE_FOCUSED,
"No focused state for element with ID " + aFocusMgr.mName + ".");
aFocusMgr.mCallback();
}, 0, this);
},
mAcc: null,
mElm: null,
mName: "",
mIsFocusHandled: false
};
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=452710"
title="nsIAccessible::takeFocus testing">
Mozilla Bug 452710
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<span id="aria-link" role="link" tabindex="0">link</span>
<span id="aria-link2" role="link" tabindex="0">link</span>
<a id="link" href="">link</span>
</body>
</html>