diff --git a/accessible/tests/mochitest/common.js b/accessible/tests/mochitest/common.js index 01ea3b0a036..78f87815944 100644 --- a/accessible/tests/mochitest/common.js +++ b/accessible/tests/mochitest/common.js @@ -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 //////////////////////////////////////////////////////////////////////////////// diff --git a/accessible/tests/mochitest/jsat/Makefile.in b/accessible/tests/mochitest/jsat/Makefile.in index 8747591f3f2..6e5a9b84a43 100644 --- a/accessible/tests/mochitest/jsat/Makefile.in +++ b/accessible/tests/mochitest/jsat/Makefile.in @@ -12,6 +12,8 @@ relativesrcdir = @relativesrcdir@ include $(DEPTH)/config/autoconf.mk MOCHITEST_A11Y_FILES =\ +jsatcommon.js \ +test_alive.html \ test_utterance_order.html \ $(NULL) diff --git a/accessible/tests/mochitest/jsat/jsatcommon.js b/accessible/tests/mochitest/jsat/jsatcommon.js new file mode 100644 index 00000000000..1842c1b5314 --- /dev/null +++ b/accessible/tests/mochitest/jsat/jsatcommon.js @@ -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); + } +}; diff --git a/accessible/tests/mochitest/jsat/test_alive.html b/accessible/tests/mochitest/jsat/test_alive.html new file mode 100644 index 00000000000..2b4b751971d --- /dev/null +++ b/accessible/tests/mochitest/jsat/test_alive.html @@ -0,0 +1,81 @@ + + +
+