chromium/third_party/blink/web_tests/fast/events/keyboardevent-code.html

<!DOCTYPE html>
<link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent-code" />
<script src="../../resources/js-test.js"></script>-
<textarea id="textarea"></textarea>
<script>
description('Tests KeyboardEvent.code attribute');
var textarea = document.getElementById('textarea');
textarea.addEventListener('keydown', recordKeyEvent, false);
textarea.addEventListener('keyup', recordKeyEvent, false);
textarea.addEventListener('keypress', recordKeyEvent, false);
textarea.focus();

var lastKeyboardDownEvent, lastKeyboardPressEvent, lastKeyboardUpEvent;

function recordKeyEvent(ev) {
    if (window.eventSender) {
        if (ev.type === "keydown")
            lastKeyboardDownEvent = ev;
        else if (ev.type === "keyup")
            lastKeyboardUpEvent = ev;
        else if (ev.type === "keypress")
            lastKeyboardPressEvent = ev;
    } else {
        debug('Type=' + ev.type + ',' + 'code=' + ev.code);
    }
}

if (window.eventSender) {
    debug('AlphaNumeric Keys');
    eventSender.keyDown('A');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyA\'') ;
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'KeyA\'') ;
    shouldEvaluateTo('lastKeyboardPressEvent.code', '\'KeyA\'') ;
    eventSender.keyDown('a'); // Small letters.
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyA\'') ;
    eventSender.keyDown('M');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyM\'') ;
    eventSender.keyDown('m'); // Small letters.
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyM\'');
    eventSender.keyDown('Z');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyZ\'') ;
    eventSender.keyDown('z');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'KeyZ\'');
    eventSender.keyDown('0');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Digit0\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Digit0\'');
    shouldEvaluateTo('lastKeyboardPressEvent.code', '\'Digit0\'');
    eventSender.keyDown('4');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Digit4\'');
    eventSender.keyDown('9');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Digit9\'');
    eventSender.keyDown('Backspace');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Backspace\'');

    debug('Functional Keys');
    eventSender.keyDown('ControlLeft');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ControlLeft\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'ControlLeft\'');
    eventSender.keyDown('ControlRight');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ControlRight\'');
    eventSender.keyDown('ShiftLeft');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ShiftLeft\'');
    eventSender.keyDown('ShiftRight');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ShiftRight\'');
    eventSender.keyDown('AltLeft');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'AltLeft\'');
    eventSender.keyDown('AltRight');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'AltRight\'');
    eventSender.keyDown('Enter');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Enter\'');
    eventSender.keyDown('ContextMenu');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ContextMenu\'');
    eventSender.keyDown(' ');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Space\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Space\'');
    shouldEvaluateTo('lastKeyboardPressEvent.code', '\'Space\'');
    eventSender.keyDown('Tab');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Tab\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Tab\'');

    debug('Control Pad');
    eventSender.keyDown('Insert');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Insert\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Insert\'');
    eventSender.keyDown('Delete');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Delete\'');
    eventSender.keyDown('Home');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Home\'');
    eventSender.keyDown('End');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'End\'');
    eventSender.keyDown('PageUp');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'PageUp\'');
    eventSender.keyDown('PageDown');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'PageDown\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'PageDown\'');

    debug('Arrow Pad Section');
    eventSender.keyDown('ArrowRight');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowRight\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'ArrowRight\'');
    eventSender.keyDown('ArrowDown');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowDown\'');
    eventSender.keyDown('ArrowLeft');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowLeft\'');
    eventSender.keyDown('ArrowUp');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'ArrowUp\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'ArrowUp\'');

    debug('Number Pad Section');
    eventSender.keyDown('NumLock');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'NumLock\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'NumLock\'');

    debug('Function Section');
    eventSender.keyDown('Escape');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'Escape\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'Escape\'');
    eventSender.keyDown('F1');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'F1\'');
    eventSender.keyDown('F6');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'F6\'');
    eventSender.keyDown('F12');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'F12\'');
    eventSender.keyDown('PrintScreen');
    shouldEvaluateTo('lastKeyboardDownEvent.code', '\'PrintScreen\'');
    shouldEvaluateTo('lastKeyboardUpEvent.code', '\'PrintScreen\'');
}
</script>