Bug 811307 - [PATCH 2/2] [AccessFu] Add mochitest for enabling. Tear-down bits by MarcoZ. r=eeejay r=marcoz

This commit is contained in:
Yura Zenevich 2013-04-23 10:39:15 -07:00
Родитель 51ea552b94
Коммит 7399dfba4c
4 изменённых файлов: 191 добавлений и 0 удалений

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

@ -661,6 +661,23 @@ function shortenString(aString, aMaxLength)
aString.substring(aString.length - trimOffset, aString.length);
}
////////////////////////////////////////////////////////////////////////////////
// General Utils
////////////////////////////////////////////////////////////////////////////////
/**
* Return main chrome window (crosses chrome boundary)
*/
function getMainChromeWindow(aWindow)
{
return aWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
}
////////////////////////////////////////////////////////////////////////////////
// Private
////////////////////////////////////////////////////////////////////////////////

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

@ -12,6 +12,8 @@ relativesrcdir = @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MOCHITEST_A11Y_FILES =\
jsatcommon.js \
test_alive.html \
test_utterance_order.html \
$(NULL)

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

@ -0,0 +1,91 @@
// A common module to run tests on the AccessFu module
/**
* A global variable holding an array of test functions.
*/
var gTestFuncs = [];
/**
* A global Iterator for the array of test functions.
*/
var gIterator;
Components.utils.import('resource://gre/modules/Services.jsm');
Components.utils.import("resource://gre/modules/accessibility/Utils.jsm");
Components.utils.import("resource://gre/modules/accessibility/EventManager.jsm");
var AccessFuTest = {
addFunc: function AccessFuTest_addFunc(aFunc) {
if (aFunc) {
gTestFuncs.push(aFunc);
}
},
_waitForExplicitFinish: false,
waitForExplicitFinish: function AccessFuTest_waitForExplicitFinish() {
this._waitForExplicitFinish = true;
},
finish: function AccessFuTest_finish() {
// Disable the console service logging.
Logger.test = false;
AccessFu.doneCallback = function doneCallback() {
// This is being called once AccessFu has been shut down.
// Detach AccessFu from everything it attached itself to.
AccessFu.detach();
// and finish the test run.
SimpleTest.finish();
};
// Tear down accessibility and make AccessFu stop.
SpecialPowers.setIntPref("accessibility.accessfu.activate", 0);
},
nextTest: function AccessFuTest_nextTest() {
var testFunc;
try {
// Get the next test function from the iterator. If none left,
// StopIteration exception is thrown.
testFunc = gIterator.next()[1];
} catch (ex) {
// StopIteration exception.
this.finish();
return;
}
testFunc();
},
runTests: function AccessFuTest_runTests() {
if (gTestFuncs.length === 0) {
ok(false, "No tests specified!");
simpleTest.finish();
return;
}
// Create an Iterator for gTestFuncs array.
gIterator = Iterator(gTestFuncs);
// Start AccessFu and put it in stand-by.
Components.utils.import("resource://gre/modules/accessibility/AccessFu.jsm");
AccessFu.attach(getMainChromeWindow(window));
AccessFu.readyCallback = function readyCallback() {
// Enable logging to the console service.
Logger.test = true;
// This is being called once accessibility has been turned on.
if (AccessFuTest._waitForExplicitFinish) {
// Run all test functions asynchronously.
AccessFuTest.nextTest();
} else {
// Run all test functions synchronously.
[testFunc() for (testFunc of gTestFuncs)];
AccessFuTest.finish();
}
};
// Invoke the whole thing.
SpecialPowers.setIntPref("accessibility.accessfu.activate", 1);
}
};

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

@ -0,0 +1,81 @@
<html>
<head>
<title>AccessFu test for enabling</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<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="./jsatcommon.js"></script>
<script type="application/javascript">
function confirmAccessFuStart() {
ok(AccessFu._enabled, "AccessFu was started and enabled.");
AccessFuTest.nextTest();
}
function makeEventManagerListener(waitForMessage, callback) {
return {
observe: function observe(aMessage) {
// Ignore unexpected messages.
if (!(aMessage instanceof Components.interfaces.nsIConsoleMessage)) {
return;
}
if (aMessage.message.indexOf(waitForMessage) < 0) {
return;
}
Services.console.unregisterListener(this);
callback();
}
};
}
function testEventManagerStartStop() {
// Firs listen for initial 'EventManager.start' and disable AccessFu.
var initialStartListener = makeEventManagerListener("EventManager.start",
function () {
ok(EventManager._started, "EventManager was started.");
Services.console.registerListener(stopListener);
AccessFu._disable();
});
// Listen for 'EventManager.stop' and enable AccessFu again.
var stopListener = makeEventManagerListener("EventManager.stop",
function () {
isnot(EventManager._started, true, "EventManager was stopped.");
Services.console.registerListener(finalStartListener);
AccessFu._enable();
});
// Make sure EventManager is started again.
var finalStartListener = makeEventManagerListener("EventManager.start",
function () {
ok(EventManager._started, "EventManager was started again.");
AccessFuTest.finish();
});
Services.console.registerListener(initialStartListener);
}
function doTest() {
AccessFuTest.addFunc(confirmAccessFuStart);
AccessFuTest.addFunc(testEventManagerStartStop);
AccessFuTest.waitForExplicitFinish();
AccessFuTest.runTests(); // Will call SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=811307"
title="[AccessFu] Add mochitest for enabling">
Mozilla Bug 811307
</a>
</body>
</html>