Bug 455840 - change test_nsIAccessible_focus.html mochitest to use eventQueue, r=marcoz, a=test-only

--HG--
rename : accessible/tests/mochitest/test_nsIAccessible_focus.html => accessible/tests/mochitest/test_takeFocus.html
This commit is contained in:
Alexander Surkov 2011-03-14 19:28:33 +08:00
Родитель c2eb678181
Коммит f6f588d0be
3 изменённых файлов: 83 добавлений и 145 удалений

Просмотреть файл

@ -100,12 +100,12 @@ _TEST_FILES =\
test_keys.html \
$(warning test_nsIAccessible_comboboxes.xul temporarily disabled) \
test_nsIAccessible_selects.html \
test_nsIAccessible_focus.html \
test_nsIAccessibleDocument.html \
test_nsIAccessibleImage.html \
test_nsIAccessNode_utils.html \
test_nsOuterDocAccessible.html \
test_role_nsHyperTextAcc.html \
test_takeFocus.html \
test_text_caret.html \
test_textboxes.html \
test_textboxes.xul \

Просмотреть файл

@ -1,144 +0,0 @@
<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="common.js"></script>
<script type="application/javascript"
src="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();
// Try to work around bug 573085 by using a timeout that's a lot
// bigger than our refresh driver period.
}, 100, 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>

Просмотреть файл

@ -0,0 +1,82 @@
<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="common.js"></script>
<script type="application/javascript"
src="states.js"></script>
<script type="application/javascript"
src="events.js"></script>
<script type="application/javascript">
////////////////////////////////////////////////////////////////////////////
// Test
var gQueue = null;
function takeFocusInvoker(aID)
{
this.accessible = getAccessible(aID);
this.eventSeq = [ new invokerChecker(EVENT_FOCUS, this.accessible) ];
this.invoke = function takeFocusInvoker_invoke()
{
this.accessible.takeFocus();
}
this.finalCheck = function takeFocusInvoker()
{
testStates(this.accessible, STATE_FOCUSED);
}
this.getID = function takeFocusInvoker_getID()
{
return "takeFocus for " + prettyName(aID);
}
}
function doTest()
{
gQueue = new eventQueue();
gQueue.push(new takeFocusInvoker("aria-link"));
gQueue.push(new takeFocusInvoker("aria-link2"));
gQueue.push(new takeFocusInvoker("link"));
gQueue.invoke(); // Will call SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</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>