blob: f0938a4dbd8b0daa44c4bd8a6a136575a149fb7a [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
description("This tests keyboard events with KeyLocationCode argument.");
var lastKeyboardEvent;
var VK_SHIFT = 16;
var VK_CONTROL = 17;
var VK_MENU = 18;
function recordKeyEvent(ev) {
ev = ev || event;
ev.keyCode = (ev.which || ev.keyCode);
if (window.eventSender) {
lastKeyboardEvent = ev;
} else {
debug('Type=' + ev.type + ',' +
'keyCode=' + ev.keyCode + ',' +
'ctrlKey=' + ev.ctrlKey + ',' +
'shiftKey=' + ev.shiftKey + ',' +
'altKey=' + ev.altKey + ',' +
'metaKey=' + ev.metaKey + ',' +
'location=' + ev.location);
}
}
function testKeyEventWithLocation(evString, expectedKeyCode, expectedLocation) {
eventSender.keyDown(evString, []);
shouldBe("lastKeyboardEvent.type", '"keydown"');
shouldEvaluateTo("lastKeyboardEvent.keyCode", expectedKeyCode);
shouldEvaluateTo("lastKeyboardEvent.location", expectedLocation);
}
var textarea = document.createElement("textarea");
textarea.addEventListener("keydown", recordKeyEvent, false);
document.body.insertBefore(textarea, document.body.firstChild);
textarea.focus();
if (window.eventSender) {
// location=0 indicates that we send events as standard keys.
testKeyEventWithLocation("ShiftLeft", VK_SHIFT, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
testKeyEventWithLocation("ControlLeft", VK_CONTROL, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
testKeyEventWithLocation("AltLeft", VK_MENU, "KeyboardEvent.DOM_KEY_LOCATION_LEFT");
testKeyEventWithLocation("ShiftRight", VK_SHIFT, "KeyboardEvent.DOM_KEY_LOCATION_RIGHT");
testKeyEventWithLocation("ControlRight", VK_CONTROL, "KeyboardEvent.DOM_KEY_LOCATION_RIGHT");
testKeyEventWithLocation("AltRight", VK_MENU, "KeyboardEvent.DOM_KEY_LOCATION_RIGHT");
} else {
debug("This test requires DumpRenderTree.");
}
</script>
</body>
</html>