2008-08-31 18:52:40 -07:00
|
|
|
<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"
|
2010-09-01 15:09:56 -07:00
|
|
|
src="common.js"></script>
|
2009-01-24 20:42:21 -08:00
|
|
|
<script type="application/javascript"
|
2010-09-01 15:09:56 -07:00
|
|
|
src="events.js"></script>
|
2008-08-31 18:52:40 -07:00
|
|
|
|
|
|
|
<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();
|
2009-09-23 07:21:47 -07:00
|
|
|
addA11yLoadEvent(doTest);
|
2008-08-31 18:52:40 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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();
|
2010-06-18 11:41:37 -07:00
|
|
|
// Try to work around bug 573085 by using a timeout that's a lot
|
|
|
|
// bigger than our refresh driver period.
|
|
|
|
}, 100, this);
|
2008-08-31 18:52:40 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// 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,
|
2009-05-18 06:48:36 -07:00
|
|
|
"Focus wasn't received for element with ID " + aFocusMgr.mName + ".");
|
2008-08-31 18:52:40 -07:00
|
|
|
|
|
|
|
var states = {}, extraStates = {};
|
2008-11-03 19:37:46 -08:00
|
|
|
aFocusMgr.mAcc.getState(states, extraStates);
|
2008-09-18 02:29:18 -07:00
|
|
|
// 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 + ".");
|
2008-08-31 18:52:40 -07:00
|
|
|
|
|
|
|
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>
|