Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: timelapse
Fetching contributors…

Cannot retrieve contributors at this time

file 93 lines (74 sloc) 2.92 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
<body>
<p>Test for <a href="http://bugs.webkit.org/show_bug.cgi?id=3387">bug 3387</a>:
Redundant keydown, keypress, keyup events sent for arrow keys.</p>

<p>Try pressing arrow keys, PgUp/PgDown/Home/End, Esc, or function keys.
The test passes if the box below doesn't turn red.<p>

<div id="result" style="width:100px; height:100px; background-color:blue;"></div>

<script>

    var console_messages = document.createElement("ol");
    document.body.appendChild(console_messages);
    
    window.onkeydown = registerWindow;
    window.onkeypress = registerWindow;
    window.onkeyup = registerWindow;

    document.onkeydown = registerDocument;
    document.onkeypress = registerDocument;
    document.onkeyup = registerDocument;

    document.body.onkeydown = registerBody;
    document.body.onkeypress = registerBody;
    document.body.onkeyup = registerBody;

    document.documentElement.onkeydown = registerDocumentElement;
    document.documentElement.onkeypress = registerDocumentElement;
    document.documentElement.onkeyup = registerDocumentElement;

    var bodyKeyDownCount = 0;
    var documentElementKeyDownCount = 0;
    var windowKeyDownCount = 0;
    var documentKeyDownCount = 0;

    function log(message)
    {
        var item = document.createElement("li");
        item.appendChild(document.createTextNode(message));
        item.style.fontSize = '8px';
        console_messages.appendChild(item);
    }

    function registerBody(e)
    {
        if ((e.type == "keydown" && ++bodyKeyDownCount != 1)
                || (e.type == "keyup" && --bodyKeyDownCount != 0))
            document.getElementById("result").style.backgroundColor = "red";

        if (!e)
            e = window.event;
        log("body: " + e.type);
        return true;
    }

    function registerDocumentElement(e)
    {
        if ((e.type == "keydown" && ++documentElementKeyDownCount != 1)
                || (e.type == "keyup" && --documentElementKeyDownCount != 0))
            document.getElementById("result").style.backgroundColor = "red";

        if (!e)
            e = window.event;
        log(" documentElement: " + e.type);
        return true;
    }

    function registerDocument(e)
    {
        if ((e.type == "keydown" && ++documentKeyDownCount != 1)
                || (e.type == "keyup" && --documentKeyDownCount != 0))
            document.getElementById("result").style.backgroundColor = "red";

        if (!e)
            e = window.event;
        log("  document: " + e.type);
        return true;
    }

    function registerWindow(e)
    {
        if ((e.type == "keydown" && ++windowKeyDownCount != 1)
                || (e.type == "keyup" && --windowKeyDownCount != 0))
            document.getElementById("result").style.backgroundColor = "red";

        if (!e)
            e = window.event;
        log("   window: " + e.type);
        return true;
    }

</script>
</body>
Something went wrong with that request. Please try again.