Files
openlayers/master/examples/Menu_a11y.html
Éric Lemoine 5d14b9e2d4 Updated
2013-02-20 10:38:25 +01:00

558 lines
18 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>doh.robot Menu Keyboard Tests</title>
<style>
@import "../../../util/doh/robot/robot.css";
</style>
<!-- required: dojo.js -->
<script type="text/javascript" src="../../../dojo/dojo.js"></script>
<!-- functions to help test -->
<script type="text/javascript" src="../helpers.js"></script>
<script type="text/javascript">
dojo.require("dijit.robotx");
dojo.ready(function(){
doh.robot.initRobot('../test_Menu.html');
doh.register("dijit.MenuBar general keyboard tests",[
{
name: "start focus on the link, outside of menubar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// Start at the link
doh.robot.sequence(function(){
dijit.focus(dojo.byId("link"));
}, 500, 500);
doh.robot.sequence(d.getTestCallback(function(){
doh.t(dojo.global.dijit.focus.curNode, "something has focus");
doh.is("random link", dojo.global.dijit.focus.curNode.innerHTML, "check that focus is on the link");
}), 1000);
return d;
}
},
{
name: "tab to the menubar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// tab to the MenuBar... then focus should automatically shift to "File" menu,
doh.robot.keyPress(dojo.keys.TAB, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("File", dojo.trim(dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent),
"check that focus is on File menu");
}), 1000);
return d;
}
},
{
name: "arrow to the edit menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); // TODO: use left arrow in RTL mode
doh.robot.sequence(d.getTestCallback(function(){
doh.is("Edit", dojo.trim(dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent),
"check that focus is on Edit MenuItem");
}), 1000);
return d;
}
},
{
name: "shift-tab back",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.TAB, 500, {shift:true});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("random link", dojo.trim(dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent),
"check that focus is back on the link");
}), 1000);
return d;
}
},
{
name: "open file menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// Start at the link
doh.robot.sequence(function(){
dijit.focus(dojo.byId("link"));
}, 500, 500);
// tab to the MenuBar... then focus should automatically shift to "File" menu
doh.robot.keyPress(dojo.keys.TAB, 500, {});
// and then down arrow to menu... focus should go to "New"
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.t((dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent).indexOf("New") >= 0,
"check that focus is on New menu item of the File menu (indirectly checks that menu is visible)");
}), 1000);
return d;
}
},
{
name: "click 'new' using enter key",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
var clicked = false;
dijit.byId("new").onClick = function(){ clicked = true; };
doh.robot.keyPress(dojo.keys.ENTER, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.t(clicked, "new was clicked");
doh.t(isHidden("fileMenu"), "File menu disappeared");
doh.f(dojo.hasClass("file", "dijitMenuItemSelected"),
"File MenuBarItem should no longer have selected effect, actual class is: " + dojo.byId("edit").className);
}), 1000);
return d;
}
},
{
name: "open submenu",
timeout: 8000,
runTest: function(){
var d = new doh.Deferred();
// Start at the link
doh.robot.sequence(function(){
dijit.focus(dojo.byId("link"));
}, 500, 500);
// tab to the MenuBar... then focus should automatically shift to "File" menu item
doh.robot.keyPress(dojo.keys.TAB, 500, {});
// and then move to "View" menu item
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
// open the menu
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
// go down to "Zoom" menu item
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {});
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {});
// open the submenu (landing on first item)
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.t( (dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent).indexOf("50%") >= 0,
"check that focus is on '50%'");
doh.robot.keyPress(dojo.keys.ENTER, 0, {}, true); // close popup menus
}), 1000, 500);
return d;
}
}
]);
// Using left-arrow to back up (#10437)
doh.register("dijit.MenuBar left arrow tests",[
{
name: "start focus on the link, outside of menubar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// Start at the link
doh.robot.sequence(function(){
dijit.focus(dojo.byId("link"));
}, 500, 500);
doh.robot.sequence(d.getTestCallback(function(){
doh.t(dojo.global.dijit.focus.curNode, "something has focus");
doh.is("random link", dojo.global.dijit.focus.curNode.innerHTML, "check that focus is on the link");
}), 1000);
return d;
}
},
{
name: "tab to the menubar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// tab to the MenuBar... then focus should automatically shift to "File" menu,
doh.robot.keyPress(dojo.keys.TAB, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("File", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on File MenuItem");
}), 1000);
return d;
}
},
{
name: "arrow to the view menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); // TODO: use left arrow in RTL mode
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); // TODO: use left arrow in RTL mode
doh.robot.sequence(d.getTestCallback(function(){
doh.is("View", dojo.trim(dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent),
"check that focus is on View MenuItem");
}), 1000);
return d;
}
},
{
name: "down to the zoom menuitem",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // focuses "Normal", first menu item
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // focuses "Outline", second menu item
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // focuses "Zoom", third menu item
doh.robot.sequence(d.getTestCallback(function(){
doh.is("Zoom", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on Zoom MenuItem");
}), 1000);
return d;
}
},
{
name: "open the zoom menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("50%", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on Zoom MenuItem");
}), 1000);
return d;
}
},
{
name: "close Zoom menu, back to View menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("Zoom", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on Zoom MenuItem");
doh.is(0, dojo.query("#zoomMenu .dijitMenuItemSelected").length,
"dijitMenuItemSelected removed from Zoom Menu")
}), 1000);
return d;
}
},
{
name: "close View menu, back to MenuBar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// This should move focus to "Edit" in the MenuBar, which then opens
// the drop down and focuses on the first item (Cut)
doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("Cut", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on first MenuItem in Edit Menu");
doh.is(0, dojo.query("#viewMenu .dijitMenuItemSelected").length,
"dijitMenuItemSelected removed from View Menu")
}), 1000);
return d;
}
}
]);
doh.register("dijit.MenuBar nested click focus test",[
{
name: "start focus on the link, outside of menubar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// Start at the link
doh.robot.sequence(function(){
dojo.byId("link").focus();
}, 500);
doh.robot.sequence(d.getTestCallback(function(){
doh.t(dojo.global.dijit.focus.curNode, "something has focus");
doh.is("random link", dojo.global.dijit.focus.curNode.innerHTML, "check that focus is on the link");
}), 1000);
return d;
}
},
{
name: "tab to the menubar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// tab to the MenuBar... then focus should automatically shift to "File" menu,
doh.robot.keyPress(dojo.keys.TAB, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("File", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on File MenuItem");
}), 1000);
return d;
}
},
{
name: "arrow to the view menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); // TODO: use left arrow in RTL mode
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); // TODO: use left arrow in RTL mode
doh.robot.sequence(d.getTestCallback(function(){
doh.is("View", dojo.trim(dojo.global.dijit.focus.curNode.innerText || dojo.global.dijit.focus.curNode.textContent),
"check that focus is on View MenuItem");
}), 1000);
return d;
}
},
{
name: "down to the zoom menuitem",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // focuses "Normal", first menu item
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // focuses "Outline", second menu item
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // focuses "Zoom", third menu item
doh.robot.sequence(d.getTestCallback(function(){
doh.is("Zoom", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on Zoom MenuItem");
}), 1000);
return d;
}
},
{
name: "open the zoom menu",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("50%", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on Zoom MenuItem");
}), 1000);
return d;
}
},
{
name: "click to close Zoom menu, focus back to MenuBar",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// This should move focus to "Edit" in the MenuBar, which then opens
// the drop down and focuses on the first item (Cut)
doh.robot.keyPress(dojo.keys.ENTER, 500, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is("View", dijit.getEnclosingWidget(dojo.global.dijit.focus.curNode).label,
"check that focus is on first View item in MenuBar");
}), 1000);
return d;
}
}
]);
// Run test about opening context menu via keyboard, except on safari/mac where that isn't
// possible (#9927)
if(!dojo.isMac || !dojo.isWebKit){
doh.register("Context menu keyboard tests", [{
name: "open global context menu (keyboard)",
timeout: 5000,
runTest: function(){
var d = new doh.Deferred();
// Put focus on the link; this is just a random place on the screen to have focus
doh.robot.sequence(function(){
dijit.focus(dojo.byId("link"));
}, 500, 500);
// open via keyboard
if(dojo.isMac){
doh.robot.keyPress(dojo.keys.SPACE, 500, {
ctrl: true
});
}else{
doh.robot.keyPress(dojo.keys.F10, 500, {
shift: true
});
}
doh.robot.sequence(d.getTestCallback(function(){
var menu = dijit.byId("windowContextMenu");
doh.t(isVisible(menu), "menu is now shown");
var menuCoords = dojo.position(menu.domNode),
linkCoords = dojo.position("link");
doh.t(menuCoords.x < 100, "x < 100", "actual x: " + menuCoords.x);
doh.t(menuCoords.y < 50, "y < 50", "actual y: " + menuCoords.y);
doh.t(menuCoords.x >= 0, "x >= 0", "actual x: " + menuCoords.x);
doh.t(menuCoords.y >= 0, "y >= 0", "actual y: " + menuCoords.y);
doh.robot.keyPress(dojo.keys.ESCAPE, 0, {}, true); // close context menu
}), 1000);
return d;
}
}]);
}
doh.register("Cancellation (ESCAPE) tests", [
{
name: "MenuBar selection and cancellation",
timeout: 20000,
runTest: function(){
var d = new doh.Deferred();
// Start at the link
doh.robot.sequence(function(){
dijit.focus(dojo.byId("link"));
}, 500, 500);
// tab to the MenuBar... then focus should automatically shift to "File" menu,
doh.robot.keyPress(dojo.keys.TAB, 500, {});
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // open File menu
doh.robot.sequence(d.getTestErrback(function(){
doh.t(isVisible("fileMenu"), "File menu should be visible");
}), 1000);
doh.robot.keyPress(dojo.keys.ESCAPE, 500, {}); // close File menu
doh.robot.sequence(d.getTestErrback(function(){
doh.t(isHidden("fileMenu"), "File menu is hidden after cancel");
doh.t(dojo.hasClass("file", "dijitMenuItemSelected"),
"File MenuBarItem should have selected class, actual class is: " + dojo.byId("file").className);
}), 1000);
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500, {}); // move to Edit menu
doh.robot.sequence(d.getTestErrback(function(){
doh.f(dojo.hasClass("file", "dijitMenuItemSelected"),
"File MenuBarItem should not have selected class, actual class is: " + dojo.byId("file").className);
doh.t(isHidden("editMenu"), "Edit menu is hidden after cancel and select");
doh.t(dojo.hasClass("edit", "dijitMenuItemSelected"),
"Edit MenuBarItem should have selected class, actual class is: " + dojo.byId("edit").className);
}), 1000);
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // open Edit menu
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 1000, {}); // move to copy more slowly
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // move to paste option
doh.robot.keyPress(dojo.keys.ENTER, 500, {}); // click paste, closing edit menu
doh.robot.sequence(d.getTestErrback(function(){
doh.t(isHidden("editMenu"), "edit menu disappeared");
dijit.focus(dojo.byId("link"));
}), 1000, 500);
// tab to the MenuBar... then focus should automatically shift to "File" menu,
doh.robot.keyPress(dojo.keys.TAB, 500, {}); // move to File
doh.robot.sequence(d.getTestErrback(function(){
doh.t(isHidden("fileMenu"), "File menu should be hidden");
}), 1000);
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500, {}); // open File menu
doh.robot.sequence(d.getTestErrback(function(){
doh.t(isVisible("fileMenu"), "File menu should be visible");
}), 1000);
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 75, {}); // #9846
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 75, {}); // move to View menu
doh.robot.keyPress(dojo.keys.LEFT_ARROW, 75, {}); // move to Edit menu
doh.robot.sequence(d.getTestErrback(function(){
doh.t(isVisible("editMenu"), "Edit menu should be visible and File menu hidden");
doh.t(isHidden("fileMenu"), "File menu should be hidden and Edit menu visible");
}), 1000);
doh.robot.keyPress(dojo.keys.ESCAPE, 500, {}); // close Edit menu
doh.robot.sequence(d.getTestCallback(function(){
doh.t(isHidden("editMenu"), "edit menu disappeared");
}), 1000);
return d;
}
}
]);
doh.run();
});
</script>
</head>
</html>