From 8f80f72f4c0269aa98d926e9c6e1da4a26b22e35 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Fri, 27 Jan 2012 19:22:19 +0900 Subject: [PATCH] Bug 719754 - rewrite events/test_docload.xul, r=marcoz --- accessible/tests/mochitest/Makefile.in | 1 + accessible/tests/mochitest/browser.js | 96 ++++++ accessible/tests/mochitest/events.js | 22 +- accessible/tests/mochitest/events/Makefile.in | 3 +- .../tests/mochitest/events/docload_wnd.xul | 275 ------------------ .../tests/mochitest/events/test_docload.xul | 166 ++++++++++- .../mochitest/events/test_focus_browserui.xul | 51 +--- accessible/tests/mochitest/states.js | 2 + 8 files changed, 287 insertions(+), 329 deletions(-) create mode 100644 accessible/tests/mochitest/browser.js delete mode 100644 accessible/tests/mochitest/events/docload_wnd.xul diff --git a/accessible/tests/mochitest/Makefile.in b/accessible/tests/mochitest/Makefile.in index b2d14cdd1442..e90e1e108f3b 100644 --- a/accessible/tests/mochitest/Makefile.in +++ b/accessible/tests/mochitest/Makefile.in @@ -75,6 +75,7 @@ _TEST_FILES =\ actions.js \ attributes.js \ autocomplete.js \ + browser.js \ common.js \ events.js \ grid.js \ diff --git a/accessible/tests/mochitest/browser.js b/accessible/tests/mochitest/browser.js new file mode 100644 index 000000000000..71c42b6a5687 --- /dev/null +++ b/accessible/tests/mochitest/browser.js @@ -0,0 +1,96 @@ +/** + * Load the browser with the given url and then invokes the given function. + */ +function openBrowserWindow(aFunc, aURL) +{ + gBrowserContext.testFunc = aFunc; + gBrowserContext.startURL = aURL; + + addLoadEvent(openBrowserWindowIntl); +} + +/** + * Close the browser window. + */ +function closeBrowserWindow() +{ + gBrowserContext.browserWnd.close(); +} + +/** + * Return the browser window object. + */ +function browserWindow() +{ + return gBrowserContext.browserWnd; +} + +/** + * Return tab browser object. + */ +function tabBrowser() +{ + return browserWindow().gBrowser; +} + +/** + * Return browser element of the current tab. + */ +function currentBrowser() +{ + return tabBrowser().selectedBrowser; +} + +/** + * Return DOM document of the current tab. + */ +function currentTabDocument() +{ + return currentBrowser().contentDocument; +} + +/** + * Return input element of address bar. + */ +function urlbarInput() +{ + return browserWindow().document.getElementById("urlbar").inputField; +} + +/** + * Return reload button. + */ +function reloadButton() +{ + return browserWindow().document.getElementById("urlbar-reload-button"); +} + +//////////////////////////////////////////////////////////////////////////////// +// private section + +Components.utils.import("resource://gre/modules/Services.jsm"); + +var gBrowserContext = +{ + browserWnd: null, + testFunc: null, + startURL: "" +}; + +function openBrowserWindowIntl() +{ + gBrowserContext.browserWnd = + window.openDialog(Services.prefs.getCharPref("browser.chromeURL"), + "_blank", "chrome,all,dialog=no", + gBrowserContext.startURL); + + addA11yLoadEvent(startBrowserTests, browserWindow()); +} + +function startBrowserTests() +{ + if (gBrowserContext.startURL) // wait for load + addA11yLoadEvent(gBrowserContext.testFunc, currentBrowser().contentWindow); + else + gBrowserContext.testFunc(); +} diff --git a/accessible/tests/mochitest/events.js b/accessible/tests/mochitest/events.js index 06b41759c7d8..7186b111f0bd 100644 --- a/accessible/tests/mochitest/events.js +++ b/accessible/tests/mochitest/events.js @@ -174,7 +174,7 @@ const DO_NOT_FINISH_TEST = 1; * // phase getter: function() {}, * // * // * Callback, called to match handled event. * - * // match : function() {}, + * // match : function(aEvent) {}, * // * // * Callback, called when event is handled * // check: function(aEvent) {}, @@ -1340,10 +1340,10 @@ function caretMoveChecker(aCaretOffset, aTargetOrFunc, aTargetFuncArg) * State change checker. */ function stateChangeChecker(aState, aIsExtraState, aIsEnabled, - aTargetOrFunc, aTargetFuncArg) + aTargetOrFunc, aTargetFuncArg, aIsAsync) { this.__proto__ = new invokerChecker(EVENT_STATE_CHANGE, aTargetOrFunc, - aTargetFuncArg); + aTargetFuncArg, aIsAsync); this.check = function stateChangeChecker_check(aEvent) { @@ -1370,6 +1370,22 @@ function stateChangeChecker(aState, aIsExtraState, aIsEnabled, var unxpdExtraState = aIsEnabled ? 0 : (aIsExtraState ? aState : 0); testStates(event.accessible, state, extraState, unxpdState, unxpdExtraState); } + + this.match = function stateChangeChecker_match(aEvent) + { + if (aEvent instanceof nsIAccessibleStateChangeEvent) { + var scEvent = aEvent.QueryInterface(nsIAccessibleStateChangeEvent); + return aEvent.accessible = this.target && scEvent.state == aState; + } + return false; + } +} + +function asyncStateChangeChecker(aState, aIsExtraState, aIsEnabled, + aTargetOrFunc, aTargetFuncArg) +{ + this.__proto__ = new stateChangeChecker(aState, aIsExtraState, aIsEnabled, + aTargetOrFunc, aTargetFuncArg, true); } /** diff --git a/accessible/tests/mochitest/events/Makefile.in b/accessible/tests/mochitest/events/Makefile.in index a7d6d6b39e99..4057726a4081 100644 --- a/accessible/tests/mochitest/events/Makefile.in +++ b/accessible/tests/mochitest/events/Makefile.in @@ -45,7 +45,7 @@ relativesrcdir = accessible/events include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk -# test_docload.xul, docload_wnd.xul, test_scroll.xul disabled for misusing (bug 715857) +# test_scroll.xul disabled for misusing (bug 715857) _TEST_FILES =\ docload_wnd.html \ @@ -61,6 +61,7 @@ _TEST_FILES =\ test_coalescence.html \ test_contextmenu.html \ test_docload.html \ + test_docload.xul \ test_dragndrop.html \ test_flush.html \ test_focus_aria_activedescendant.html \ diff --git a/accessible/tests/mochitest/events/docload_wnd.xul b/accessible/tests/mochitest/events/docload_wnd.xul deleted file mode 100644 index b64820c40791..000000000000 --- a/accessible/tests/mochitest/events/docload_wnd.xul +++ /dev/null @@ -1,275 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - -