Bug 615189 - tests for menu events, r=fer, a=test

This commit is contained in:
Alexander Surkov 2010-12-03 18:49:20 +08:00
Родитель 4a3b7337a8
Коммит 888b980447
4 изменённых файлов: 336 добавлений и 46 удалений

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

@ -8,6 +8,8 @@ const EVENT_DOCUMENT_LOAD_STOPPED = nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_STOPP
const EVENT_HIDE = nsIAccessibleEvent.EVENT_HIDE;
const EVENT_FOCUS = nsIAccessibleEvent.EVENT_FOCUS;
const EVENT_NAME_CHANGE = nsIAccessibleEvent.EVENT_NAME_CHANGE;
const EVENT_MENU_START = nsIAccessibleEvent.EVENT_MENU_START;
const EVENT_MENU_END = nsIAccessibleEvent.EVENT_MENU_END;
const EVENT_MENUPOPUP_START = nsIAccessibleEvent.EVENT_MENUPOPUP_START;
const EVENT_MENUPOPUP_END = nsIAccessibleEvent.EVENT_MENUPOPUP_END;
const EVENT_REORDER = nsIAccessibleEvent.EVENT_REORDER;
@ -653,11 +655,12 @@ function sequence()
// Event queue invokers
/**
* Invokers defined below take a checker object implementing 'check' method
* which will be called when proper event is handled. Invokers listen default
* event type registered in event queue object until it is passed explicetly.
* Invokers defined below take a checker object (or array of checker objects)
* implementing 'check' method which will be called when proper event is
* handled. Invokers listen default event type registered in event queue object
* until it is passed explicetly.
*
* Note, checker object is optional.
* Note, checker object or array of checker objects is optional.
* Note, you don't need to initialize 'target' and 'type' members of checker
* object. The 'target' member will be initialized by invoker object and you are
* free to use it in 'check' method.
@ -666,9 +669,9 @@ function sequence()
/**
* Click invoker.
*/
function synthClick(aNodeOrID, aChecker, aEventType)
function synthClick(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq, aEventType);
this.invoke = function synthClick_invoke()
{
@ -688,9 +691,9 @@ function synthClick(aNodeOrID, aChecker, aEventType)
/**
* Mouse move invoker.
*/
function synthMouseMove(aNodeOrID, aChecker, aEventType)
function synthMouseMove(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq, aEventType);
this.invoke = function synthMouseMove_invoke()
{
@ -707,9 +710,9 @@ function synthMouseMove(aNodeOrID, aChecker, aEventType)
/**
* General key press invoker.
*/
function synthKey(aNodeOrID, aKey, aArgs, aChecker, aEventType)
function synthKey(aNodeOrID, aKey, aArgs, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq, aEventType);
this.invoke = function synthKey_invoke()
{
@ -728,10 +731,10 @@ function synthKey(aNodeOrID, aKey, aArgs, aChecker, aEventType)
/**
* Tab key invoker.
*/
function synthTab(aNodeOrID, aChecker, aEventType)
function synthTab(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthKey(aNodeOrID, "VK_TAB", { shiftKey: false },
aChecker, aEventType);
aCheckerOrEventSeq, aEventType);
this.getID = function synthTab_getID()
{
@ -742,10 +745,10 @@ function synthTab(aNodeOrID, aChecker, aEventType)
/**
* Shift tab key invoker.
*/
function synthShiftTab(aNodeOrID, aChecker, aEventType)
function synthShiftTab(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthKey(aNodeOrID, "VK_TAB", { shiftKey: true },
aChecker, aEventType);
aCheckerOrEventSeq, aEventType);
this.getID = function synthTabTest_getID()
{
@ -756,9 +759,9 @@ function synthShiftTab(aNodeOrID, aChecker, aEventType)
/**
* Down arrow key invoker.
*/
function synthDownKey(aNodeOrID, aChecker, aEventType)
function synthDownKey(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthKey(aNodeOrID, "VK_DOWN", null, aChecker,
this.__proto__ = new synthKey(aNodeOrID, "VK_DOWN", null, aCheckerOrEventSeq,
aEventType);
this.getID = function synthDownKey_getID()
@ -770,9 +773,9 @@ function synthDownKey(aNodeOrID, aChecker, aEventType)
/**
* Right arrow key invoker.
*/
function synthRightKey(aNodeOrID, aChecker, aEventType)
function synthRightKey(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthKey(aNodeOrID, "VK_RIGHT", null, aChecker,
this.__proto__ = new synthKey(aNodeOrID, "VK_RIGHT", null, aCheckerOrEventSeq,
aEventType);
this.getID = function synthRightKey_getID()
@ -784,9 +787,9 @@ function synthRightKey(aNodeOrID, aChecker, aEventType)
/**
* Home key invoker.
*/
function synthHomeKey(aNodeOrID, aChecker, aEventType)
function synthHomeKey(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthKey(aNodeOrID, "VK_HOME", null, aChecker,
this.__proto__ = new synthKey(aNodeOrID, "VK_HOME", null, aCheckerOrEventSeq,
aEventType);
this.getID = function synthHomeKey_getID()
@ -798,9 +801,9 @@ function synthHomeKey(aNodeOrID, aChecker, aEventType)
/**
* Focus invoker.
*/
function synthFocus(aNodeOrID, aChecker, aEventType)
function synthFocus(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq, aEventType);
this.invoke = function synthFocus_invoke()
{
@ -816,10 +819,10 @@ function synthFocus(aNodeOrID, aChecker, aEventType)
/**
* Focus invoker. Focus the HTML body of content document of iframe.
*/
function synthFocusOnFrame(aNodeOrID, aChecker, aEventType)
function synthFocusOnFrame(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthAction(getNode(aNodeOrID).contentDocument,
aChecker, aEventType);
aCheckerOrEventSeq, aEventType);
this.invoke = function synthFocus_invoke()
{
@ -835,9 +838,9 @@ function synthFocusOnFrame(aNodeOrID, aChecker, aEventType)
/**
* Select all invoker.
*/
function synthSelectAll(aNodeOrID, aChecker, aEventType)
function synthSelectAll(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.__proto__ = new synthAction(aNodeOrID, aChecker, aEventType);
this.__proto__ = new synthAction(aNodeOrID, aCheckerOrEventSeq, aEventType);
this.invoke = function synthSelectAll_invoke()
{
@ -1144,19 +1147,27 @@ function sequenceItem(aProcessor, aEventType, aTarget, aItemID)
/**
* Invoker base class for prepare an action.
*/
function synthAction(aNodeOrID, aChecker, aEventType)
function synthAction(aNodeOrID, aCheckerOrEventSeq, aEventType)
{
this.DOMNode = getNode(aNodeOrID);
if (aChecker)
aChecker.target = this.DOMNode;
this.checker = null;
if (aCheckerOrEventSeq) {
if (aCheckerOrEventSeq instanceof Array) {
this.eventSeq = aCheckerOrEventSeq;
} else {
this.checker = aCheckerOrEventSeq;
this.checker.target = this.DOMNode;
}
}
if (aEventType)
this.eventSeq = [ new invokerChecker(aEventType, this.DOMNode) ];
this.check = function synthAction_check(aEvent)
{
if (aChecker)
aChecker.check(aEvent);
if (this.checker)
this.checker.check(aEvent);
}
this.getID = function synthAction_getID() { return aNodeOrID + " action"; }

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

@ -65,6 +65,7 @@ _TEST_FILES =\
test_focus.xul \
test_focus_name.html \
test_focusdoc.html \
test_menu.xul \
test_mutation.html \
test_scroll.xul \
test_selection.html \

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

@ -10,6 +10,8 @@
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="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript"
src="../common.js"></script>
@ -22,14 +24,32 @@
const kViaDisplayStyle = 0;
const kViaVisibilityStyle = 1;
function showMenu(aMenuID, aHow)
function focusMenu(aMenuBarID, aMenuID)
{
this.eventSeq = [
new invokerChecker(EVENT_MENU_START, getNode(aMenuBarID)),
new invokerChecker(EVENT_FOCUS, getNode(aMenuID)),
];
this.invoke = function focusMenu_invoke()
{
getNode(aMenuID).focus();
}
this.getID = function focusMenu_getID()
{
return "focus menu '" + aMenuID + "'";
}
}
function showMenu(aMenuID, aParentMenuID, aHow)
{
this.menuNode = getNode(aMenuID);
this.eventSeq = [
new invokerChecker(EVENT_SHOW, this.menuNode),
new invokerChecker(EVENT_MENUPOPUP_START, this.menuNode),
new invokerChecker(EVENT_REORDER, document)
new invokerChecker(EVENT_REORDER, getNode(aParentMenuID))
];
this.invoke = function showMenu_invoke()
@ -48,7 +68,7 @@
};
}
function closeMenu(aMenuID, aHow)
function closeMenu(aMenuID, aParentMenuID, aHow)
{
this.menuNode = getNode(aMenuID);
this.menu = null;
@ -56,7 +76,7 @@
this.eventSeq = [
new invokerChecker(EVENT_MENUPOPUP_END, getMenu, this),
new invokerChecker(EVENT_HIDE, getMenu, this),
new invokerChecker(EVENT_REORDER, document),
new invokerChecker(EVENT_REORDER, getNode(aParentMenuID))
];
this.invoke = function closeMenu_invoke()
@ -84,21 +104,61 @@
}
}
function focusInsideMenu(aMenuID, aMenuBarID)
{
this.eventSeq = [
new invokerChecker(EVENT_FOCUS, getNode(aMenuID))
];
this.unexpectedEventSeq = [
new invokerChecker(EVENT_MENU_END, getNode(aMenuBarID))
];
this.invoke = function focusInsideMenu_invoke()
{
getNode(aMenuID).focus();
}
this.getID = function focusInsideMenu_getID()
{
return "focus menu '" + aMenuID + "'";
}
}
function blurMenu(aMenuBarID)
{
var eventSeq = [
new invokerChecker(EVENT_MENU_END, getNode(aMenuBarID)),
new invokerChecker(EVENT_FOCUS, getNode("outsidemenu"))
];
this.__proto__ = new synthClick("outsidemenu", eventSeq);
this.getID = function blurMenu_getID()
{
return "blur menu";
}
}
////////////////////////////////////////////////////////////////////////////
// Do tests
var gQueue = null;
//gA11yEventDumpID = "eventdump";
//gA11yEventDumpToConsole = true;
function doTests()
{
gQueue = new eventQueue();
gQueue.push(new showMenu("menu1", kViaDisplayStyle));
gQueue.push(new closeMenu("menu1", kViaDisplayStyle));
gQueue.push(new showMenu("menu2", kViaVisibilityStyle));
gQueue.push(new closeMenu("menu2", kViaVisibilityStyle));
gQueue.push(new focusMenu("menubar", "menu-file"));
gQueue.push(new showMenu("menupopup-file", "menu-file", kViaDisplayStyle));
gQueue.push(new closeMenu("menupopup-file", "menu-file", kViaDisplayStyle));
gQueue.push(new showMenu("menupopup-edit", "menu-edit", kViaVisibilityStyle));
gQueue.push(new closeMenu("menupopup-edit", "menu-edit", kViaVisibilityStyle));
gQueue.push(new focusInsideMenu("menu-edit", "menubar"));
gQueue.push(new blurMenu("menubar"));
gQueue.invoke(); // Will call SimpleTest.finish();
}
@ -120,20 +180,34 @@
title="Menupopup end event isn't fired for ARIA menus">
Mozilla Bug 614829
</a>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=615189"
title="Clean up FireAccessibleFocusEvent">
Mozilla Bug 615189
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<div id="menu1" role="menu" style="display: none;">
<div role="menuitem">menuitem1.1</div>
<div role="menuitem">menuitem1.2</div>
</div>
<div id="menu2" role="menu" style="visibility: hidden;">
<div role="menuitem">menuitem2.1</div>
<div role="menuitem">menuitem2.2</div>
<div id="menubar" role="menubar">
<div id="menu-file" role="menuitem" tabindex="0">
File
<div id="menupopup-file" role="menu" style="display: none;">
<div id="menuitem-newtab" role="menuitem" tabindex="0">New Tab</div>
<div id="menuitem-newwindow" role="menuitem" tabindex="0">New Window</div>
</div>
</div>
<div id="menu-edit" role="menuitem" tabindex="0">
Edit
<div id="menupopup-edit" role="menu" style="visibility: hidden;">
<div id="menuitem-undo" role="menuitem" tabindex="0">Undo</div>
<div id="menuitem-redo" role="menuitem" tabindex="0">Redo</div>
</div>
</div>
</div>
<div tabindex="0" id="outsidemenu">outsidemenu</div>
<div id="eventdump"></div>

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

@ -0,0 +1,204 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Accessible menu events testing for XUL menu">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<script type="application/javascript"
src="../common.js" />
<script type="application/javascript"
src="../events.js" />
<script type="application/javascript">
function openFileMenu()
{
this.eventSeq = [
new invokerChecker(EVENT_MENU_START, getNode("menubar")),
new invokerChecker(EVENT_MENUPOPUP_START, getNode("menupopup-file"))
// new invokerChecker(EVENT_FOCUS, getNode("menuitem-newtab")) intermitent failure
];
this.invoke = function openFileMenu_invoke()
{
synthesizeKey("F", { altKey: true, shiftKey: true });
}
this.getID = function openFileMenu_getID()
{
return "open file menu by alt+F press";
}
}
function openEditMenu()
{
this.eventSeq = [
new invokerChecker(EVENT_MENUPOPUP_END, getNode("menupopup-file")),
new invokerChecker(EVENT_MENUPOPUP_START, getNode("menupopup-edit"))
// new invokerChecker(EVENT_FOCUS, getNode("menuitem-undo")) intermitent failure
];
this.invoke = function openEditMenu_invoke()
{
synthesizeKey("VK_RIGHT", { });
}
this.getID = function openEditMenu_getID()
{
return "open edit menu by lef arrow press";
}
}
function closeEditMenu()
{
this.eventSeq = [
//new invokerChecker(EVENT_FOCUS, document), intermitent failure
new invokerChecker(EVENT_MENUPOPUP_END, getNode("menupopup-edit")),
new invokerChecker(EVENT_MENU_END, getNode("menubar"))
];
this.invoke = function closeEditMenu_invoke()
{
synthesizeKey("VK_ESCAPE", { });
}
this.getID = function closeEditMenu_getID()
{
return "close edit menu, leave menubar";
}
}
function focusFileMenu()
{
this.eventSeq = [
new invokerChecker(EVENT_MENU_START, getNode("menubar")),
new invokerChecker(EVENT_FOCUS, getNode("menuitem-file"))
];
this.invoke = function focusFileMenu_invoke()
{
synthesizeKey("VK_ALT", { });
}
this.getID = function focusFileMenu_getID()
{
return "activate menubar, focus file menu (atl press)";
}
}
function focusEditMenu()
{
this.eventSeq = [
new invokerChecker(EVENT_FOCUS, getNode("menuitem-edit"))
];
this.invoke = function focusEditMenu_invoke()
{
synthesizeKey("VK_RIGHT", { });
}
this.getID = function focusEditMenu_getID()
{
return "focus edit menu";
}
}
function leaveMenubar()
{
this.eventSeq = [
//new invokerChecker(EVENT_FOCUS, document), intermitent failure
new invokerChecker(EVENT_MENU_END, getNode("menubar"))
];
this.invoke = function leaveMenubar_invoke()
{
synthesizeKey("VK_ESCAPE", { });
}
this.getID = function leaveMenubar_getID()
{
return "leave menubar";
}
}
/**
* Do tests.
*/
//gA11yEventDumpID = "eventdump";
gA11yEventDumpToConsole = true;
var gQueue = null;
function doTests()
{
if (!WIN) {
todo(false, "Enable this test on other platforms.");
SimpleTest.finish();
return;
}
todo(false,
"Fix intermitent failures. Focus may randomly occur before or after menupopup events!");
gQueue = new eventQueue();
gQueue.push(new openFileMenu());
gQueue.push(new openEditMenu());
gQueue.push(new closeEditMenu());
// Alt key is used to active menubar and focus menu item on Windows,
// other platforms requires setting a ui.key.menuAccessKeyFocuses
// preference.
if (WIN) {
gQueue.push(new focusFileMenu());
gQueue.push(new focusEditMenu());
gQueue.push(new leaveMenubar());
}
gQueue.invoke(); // Will call SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTests);
</script>
<hbox flex="1" style="overflow: auto;">
<body xmlns="http://www.w3.org/1999/xhtml">
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=615189"
title="Clean up FireAccessibleFocusEvent">
Mozilla Bug 615189
</a>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
</body>
<vbox flex="1">
<menubar id="menubar">
<menu id="menuitem-file" label="File" accesskey="F">
<menupopup id="menupopup-file">
<menuitem id="menuitem-newtab" label="New Tab"/>
</menupopup>
</menu>
<menu id="menuitem-edit" label="Edit" accesskey="E">
<menupopup id="menupopup-edit">
<menuitem id="menuitem-undo" label="Undo"/>
</menupopup>
</menu>
</menubar>
<vbox id="eventdump" role="log"/>
</vbox>
</hbox>
</window>