<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<script src="../../../resources/ui-helper.js"></script>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}
</script>
</head>
<body onkeydown="handleKeyDown(event)" onkeyup="handleKeyUp(event)">
<p>This tests that DOM keydown and keyup events are dispatched to a non-editable &lt;body&gt; on iOS for hardware key presses of non-special keys. To run this test manually, verify that two messages are emitted when you press the following keys: <kbd>a</kbd>, <kbd>b</kbd>, <kbd>c</kbd>, <kbd>d</kbd>, <kbd>e</kbd>, <kbd>f</kbd>, <kbd>g</kbd>, <kbd>h</kbd>, <kbd>i</kbd>, <kbd>j</kbd>, <kbd>k</kbd>, <kbd>l</kbd>, <kbd>m</kbd>, <kbd>n</kbd>, <kbd>o</kbd>, <kbd>p</kbd>, <kbd>q</kbd>, <kbd>r</kbd>, <kbd>s</kbd>, <kbd>t</kbd>, <kbd>u</kbd>, <kbd>v</kbd>, <kbd>w</kbd>, <kbd>x</kbd>, <kbd>y</kbd>, <kbd>z</kbd>, <kbd>0</kbd>, <kbd>1</kbd>, <kbd>2</kbd>, <kbd>3</kbd>, <kbd>4</kbd>, <kbd>5</kbd>, <kbd>6</kbd>, <kbd>7</kbd>, <kbd>8</kbd>, <kbd>9</kbd>, <kbd>-</kbd>, <kbd>=</kbd>, <kbd>[</kbd>, <kbd>]</kbd>, <kbd>\</kbd>, <kbd>;</kbd>, <kbd>'</kbd>, <kbd>,</kbd>, <kbd>.</kbd>, <kbd>/</kbd>.</p>
<pre id="console"></pre>
<script>
const asciiCharacters = "abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;',./".split("");
var remainingKeysToPress = asciiCharacters;

async function nextKeyPress()
{
    if (!remainingKeysToPress.length) {
        if (window.testRunner)
            testRunner.notifyDone();
        return;
    }
    let nextKey = remainingKeysToPress.shift();
    UIHelper.typeCharacter(nextKey);
}

function handleKeyDown(event)
{
    logKeyEvent(event);
}

function handleKeyUp(event)
{
    logKeyEvent(event);
    nextKeyPress();
}

function log(message)
{
    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
}

function logKeyEvent(event)
{
    let pieces = [];
    for (let propertyName of ["type", "key", "code", "keyIdentifier", "keyCode", "charCode", "keyCode", "which"])
        pieces.push(`${propertyName}: ${event[propertyName]}`);
    log(pieces.join(", "));
}

function runTest()
{
    if (!window.testRunner)
        return;
    nextKeyPress();
}

runTest();
</script>
</body>
</html>
