2007-07-23 10:08:10 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
2011-06-24 09:39:13 -07:00
|
|
|
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
|
2007-07-23 10:08:10 -07:00
|
|
|
|
|
|
|
<window title="Menulist Key Navigation Tests"
|
2010-03-02 06:21:23 -08:00
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
2007-07-23 10:08:10 -07:00
|
|
|
|
2011-06-24 09:39:13 -07:00
|
|
|
<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>
|
2007-07-23 10:08:10 -07:00
|
|
|
|
2009-02-17 07:51:11 -08:00
|
|
|
<button id="button1" label="One"/>
|
2007-07-23 10:08:10 -07:00
|
|
|
<menulist id="list">
|
2010-03-02 06:21:23 -08:00
|
|
|
<menupopup id="popup" onpopupshowing="return gShowPopup;">
|
2007-07-23 10:08:10 -07:00
|
|
|
<menuitem id="i1" label="One"/>
|
|
|
|
<menuitem id="i2" label="Two"/>
|
|
|
|
<menuitem id="i2b" disabled="true" label="Two and a Half"/>
|
|
|
|
<menuitem id="i3" label="Three"/>
|
|
|
|
<menuitem id="i4" label="Four"/>
|
|
|
|
</menupopup>
|
|
|
|
</menulist>
|
2009-02-17 07:51:11 -08:00
|
|
|
<button id="button2" label="Two"/>
|
2007-07-23 10:08:10 -07:00
|
|
|
|
|
|
|
<script class="testbody" type="application/javascript">
|
|
|
|
<![CDATA[
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2010-03-02 06:21:23 -08:00
|
|
|
var gShowPopup = false;
|
2011-04-13 10:53:24 -07:00
|
|
|
var gModifiers = 0;
|
2010-03-02 06:21:23 -08:00
|
|
|
|
2007-07-23 11:19:49 -07:00
|
|
|
var iswin = (navigator.platform.indexOf("Win") == 0);
|
|
|
|
|
2007-07-23 10:08:10 -07:00
|
|
|
function runTests()
|
|
|
|
{
|
|
|
|
var list = $("list");
|
|
|
|
list.focus();
|
|
|
|
// on Mac, up and cursor keys open the menu, but on other platforms, the
|
|
|
|
// cursor keys navigate between items without opening the menu
|
|
|
|
if (navigator.platform.indexOf("Mac") == -1) {
|
|
|
|
keyCheck(list, "VK_DOWN", 2, "cursor down");
|
2007-07-23 11:19:49 -07:00
|
|
|
keyCheck(list, "VK_DOWN", iswin ? "2b" : 3, "cursor down skip disabled");
|
2007-07-23 10:08:10 -07:00
|
|
|
keyCheck(list, "VK_UP", 2, "cursor up skip disabled");
|
|
|
|
keyCheck(list, "VK_UP", 1, "cursor up");
|
|
|
|
keyCheck(list, "VK_UP", 4, "cursor up wrap");
|
|
|
|
keyCheck(list, "VK_DOWN", 1, "cursor down wrap");
|
|
|
|
}
|
|
|
|
|
2009-05-04 13:16:05 -07:00
|
|
|
// check that attempting to open the menulist does not change the selection
|
|
|
|
synthesizeKey("VK_DOWN", { altKey: navigator.platform.indexOf("Mac") == -1 });
|
|
|
|
is(list.selectedItem, $("i1"), "open menulist down selectedItem");
|
|
|
|
synthesizeKey("VK_UP", { altKey: navigator.platform.indexOf("Mac") == -1 });
|
|
|
|
is(list.selectedItem, $("i1"), "open menulist up selectedItem");
|
|
|
|
|
2007-07-23 10:08:10 -07:00
|
|
|
synthesizeKey("G", { });
|
|
|
|
is(list.selectedItem, $("i1"), "letter pressed not found selectedItem");
|
|
|
|
|
|
|
|
keyCheck(list, "T", 2, "letter pressed");
|
|
|
|
keyCheck(list, "T", 2, "letter pressed");
|
|
|
|
setTimeout(pressedAgain, 1200);
|
|
|
|
}
|
|
|
|
|
|
|
|
function pressedAgain()
|
|
|
|
{
|
|
|
|
var list = $("list");
|
2007-07-23 11:19:49 -07:00
|
|
|
keyCheck(list, "T", iswin ? "2b" : 3, "letter pressed again");
|
2007-07-23 10:08:10 -07:00
|
|
|
keyCheck(list, "W", 2, "second letter pressed");
|
|
|
|
setTimeout(differentPressed, 1200);
|
|
|
|
}
|
|
|
|
|
|
|
|
function differentPressed()
|
|
|
|
{
|
2010-03-02 06:21:23 -08:00
|
|
|
var list = $("list");
|
|
|
|
keyCheck(list, "O", 1, "different letter pressed");
|
2009-02-17 07:51:11 -08:00
|
|
|
|
2009-10-22 12:06:08 -07:00
|
|
|
if (navigator.platform.indexOf("Mac") == -1) {
|
|
|
|
$("button1").focus();
|
2010-03-02 06:21:23 -08:00
|
|
|
synthesizeKeyExpectEvent("VK_TAB", { }, list, "focus", "focus to menulist");
|
2009-10-22 12:06:08 -07:00
|
|
|
synthesizeKeyExpectEvent("VK_TAB", { }, $("button2"), "focus", "focus to button");
|
|
|
|
is(document.activeElement, $("button2"), "tab from menulist focused button");
|
|
|
|
}
|
2009-02-17 07:51:11 -08:00
|
|
|
|
2010-03-02 06:21:23 -08:00
|
|
|
// now make sure that using a key scrolls the menu correctly
|
|
|
|
gShowPopup = true;
|
|
|
|
|
2010-05-13 06:42:57 -07:00
|
|
|
for (let i = 0; i < 65; i++) {
|
2010-03-02 06:21:23 -08:00
|
|
|
list.appendItem("Item" + i, "item" + i);
|
|
|
|
}
|
2010-05-13 06:42:57 -07:00
|
|
|
list.open = true;
|
|
|
|
is(list.getBoundingClientRect().width, list.firstChild.getBoundingClientRect().width,
|
|
|
|
"menu and popup width match");
|
|
|
|
ok(list.getBoundingClientRect().width > list.getItemAtIndex(0).getBoundingClientRect().width + 2,
|
|
|
|
"menuitem width accounts for scrollbar");
|
|
|
|
list.open = false;
|
|
|
|
|
2010-03-02 06:21:23 -08:00
|
|
|
list.menupopup.maxHeight = 100;
|
|
|
|
list.open = true;
|
|
|
|
|
|
|
|
var rowdiff = list.getItemAtIndex(1).getBoundingClientRect().top -
|
|
|
|
list.getItemAtIndex(0).getBoundingClientRect().top;
|
|
|
|
|
|
|
|
var item = list.getItemAtIndex(10);
|
|
|
|
var originalPosition = item.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
list.menuBoxObject.activeChild = item;
|
|
|
|
ok(item.getBoundingClientRect().top < originalPosition,
|
|
|
|
"position of item 1: " + item.getBoundingClientRect().top + " -> " + originalPosition);
|
|
|
|
|
|
|
|
originalPosition = item.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
synthesizeKey("VK_DOWN", { });
|
|
|
|
is(item.getBoundingClientRect().top, originalPosition - rowdiff, "position of item 10");
|
|
|
|
|
|
|
|
list.open = false;
|
|
|
|
|
2011-04-13 10:53:24 -07:00
|
|
|
checkEnter();
|
2007-07-23 10:08:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function keyCheck(list, key, index, testname)
|
|
|
|
{
|
|
|
|
var item = $("i" + index);
|
|
|
|
synthesizeKeyExpectEvent(key, { }, item, "command", testname);
|
|
|
|
is(list.selectedItem, item, testname + " selectedItem");
|
|
|
|
}
|
|
|
|
|
2011-04-13 10:53:24 -07:00
|
|
|
function checkModifiers(event)
|
|
|
|
{
|
|
|
|
var expectedModifiers = (gModifiers == 1);
|
|
|
|
is(event.shiftKey, expectedModifiers, "shift key pressed");
|
|
|
|
is(event.ctrlKey, expectedModifiers, "ctrl key pressed");
|
|
|
|
is(event.altKey, expectedModifiers, "alt key pressed");
|
|
|
|
is(event.metaKey, expectedModifiers, "meta key pressed");
|
|
|
|
gModifiers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkEnter()
|
|
|
|
{
|
|
|
|
var list = $("list");
|
|
|
|
list.addEventListener("popuphidden", checkEnterWithModifiers, false);
|
|
|
|
list.addEventListener("command", checkModifiers, false);
|
|
|
|
list.open = true;
|
|
|
|
synthesizeKey("VK_ENTER", { });
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkEnterWithModifiers()
|
|
|
|
{
|
|
|
|
is(gModifiers, 1, "modifiers checked when not set");
|
|
|
|
|
|
|
|
var list = $("list");
|
|
|
|
ok(!list.open, "list closed on enter press");
|
|
|
|
list.removeEventListener("popuphidden", checkEnterWithModifiers, false);
|
|
|
|
|
|
|
|
list.addEventListener("popuphidden", done, false);
|
|
|
|
list.open = true;
|
|
|
|
|
|
|
|
synthesizeKey("VK_ENTER", { shiftKey: true, ctrlKey: true, altKey: true, metaKey: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
function done()
|
|
|
|
{
|
|
|
|
is(gModifiers, 2, "modifiers checked when set");
|
|
|
|
|
|
|
|
var list = $("list");
|
|
|
|
ok(!list.open, "list closed on enter press with modifiers");
|
|
|
|
list.removeEventListener("popuphidden", done, false);
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
2010-03-02 06:21:23 -08:00
|
|
|
SimpleTest.waitForFocus(runTests);
|
|
|
|
|
2007-07-23 10:08:10 -07:00
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<p id="display">
|
|
|
|
</p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</window>
|