<body>
<script src="full-screen-test.js"></script>
<p>This tests that full screen mode does not allow alphanumeric key events.  Press space to continue, then press an alphanumeric key, followed by space.
<span></span>
<script>
    // Bail out early if the full screen API is not enabled or is missing:
    if (Element.prototype.webkitRequestFullScreen == undefined) {
        logResult(false, "Element.prototype.webkitRequestFullScreen == undefined");
        endTest();
    } else {
        var callback;
        var fullscreenChanged = function(event)
        {
            if (callback)
                callback(event)
        };
        waitForEvent(document, 'webkitfullscreenchange', fullscreenChanged);

        var spanEnteredFullScreen = function() {
            callback = null;
            testExpected("document.webkitIsFullScreen", true);
            if (window.testRunner && eventSender.keyDown) {
                waitForEvent(document, 'keypress', keyPressed);
                eventSender.keyDown('a', []);
                eventSender.keyDown(' ', []);
            }
        };

        var keyPressed = function(event) {
            testExpected('event.keyCode', 32); // Space
            endTest();
            document.webkitCancelFullScreen();
        }
        waitForEvent(document, 'webkitfullscreenchange', fullscreenChanged);

        var span = document.getElementsByTagName('span')[0];
        callback = spanEnteredFullScreen;
        runWithKeyDown(function(){span.webkitRequestFullScreen()});
    }
</script>
