<body>
<p>This tests that keydown events aren't sent to the main frame for command key presses that occur when a subframe is first responder.  To run it manually, click inside the subframe, type a few characters, then do Command-A to Select All.  Only the subframe should report a keydown event.</p>
<iframe id="iframe" style="border: 1px solid black;" src="../../editing/resources/contenteditable-iframe-src.html"></iframe>
<ul id="console"></ul>

<script>
function log(str) {
    var console = document.getElementById("console");
    var li = document.createElement("li");
    li.appendChild(document.createTextNode(str));
    console.appendChild(li);
}

function addEventListeners() {
    window.addEventListener("keydown", 
    function(e) {
        log("keydown in mainframe: " + e);
    },
false);

    window.frames[0].addEventListener("keydown", 
    function(e) {
        log("keydown in subframe: " + e);
    },
false);
}

function step2() {
    addEventListeners();
    
    if (!window.layoutTestController)
        return;
        
    var iframe = document.getElementById("iframe");
    var x = iframe.offsetParent.offsetLeft + iframe.offsetLeft + iframe.offsetWidth / 2;
    var y = iframe.offsetParent.offsetTop + iframe.offsetTop + iframe.offsetHeight / 2;
    
    eventSender.mouseMoveTo(x, y);
    eventSender.mouseDown();
    eventSender.mouseUp();
    
    window.frames[0].document.execCommand("InsertText", false, "This sentence should not end with a period.");
    // Move backward by one character.
    eventSender.keyDown("b", Array("ctrlKey"));
    // Delete forward by one character.
    eventSender.keyDown("d", Array("ctrlKey"));
    window.layoutTestController.notifyDone();
}

function runTest() {
    if (window.layoutTestController)
        window.layoutTestController.waitUntilDone();
    
    window.setTimeout(step2, 200);
}

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