<html><!-- webkit-test-runner [ JavaScriptCanOpenWindowsAutomatically=false ] -->
<head>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function test() {
    if (!window.testRunner)
        return;
    // Record current window count.
    window.windowCount = window.testRunner.windowCount();
    console.log("window count: " + window.testRunner.windowCount());
    // Send a mouse-click event to set the input focus to the test plug-in.
    eventSender.mouseMoveTo(0, 0);
    eventSender.mouseMoveTo(20, 20);
    eventSender.mouseDown();
    eventSender.mouseUp();
}

// This function will be called when plugin receives a mousedown event.
function popup_by_mousedown() {
    // Open a new window.
    window.open("data:text/html\, open new window by mouse down", "_blank");
    // Check the new opened window and logging the result.
    console.log("window count: " + window.testRunner.windowCount());
    if (window.testRunner.windowCount() == (window.windowCount + 1)) {
        document.getElementById("mousedown_output").innerHTML = "PASSED";
        window.windowCount++;
    }
   setTimeout(send_key_to_plugin, 100);
}

function send_key_to_plugin() {
    // Send keyboard events to the plug-in.
    eventSender.mouseMoveTo(0, 0);
    eventSender.mouseMoveTo(60, 60);
    eventSender.mouseDown();
    eventSender.mouseUp();
    eventSender.keyDown('p');
}

// This function will be called when plugin receives a keydown event.
function popup_by_keydown() {
    // Open a new window.
    window.open("data:text/html\, open new window by key down", "_blank");
    // Check the new opened window and logging the result.
    console.log("window count: " + window.testRunner.windowCount());
    if (window.testRunner.windowCount() == (window.windowCount + 1))
        document.getElementById("keydown_output").innerHTML = "PASSED";
    // Wait for plugin stopping and ending this test.
    setTimeout(end_test, 100);
}

function end_test() {
    // Change focus back to window to stop the plugin event logging.
    window.focus();
    // Close the test.
     setTimeout(function() {testRunner.notifyDone();}, 1);
}
</script>
</head>
<body onload="internals.updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks(); test();">
<embed type="application/x-webkit-test-netscape" width=100 height=40 evaluatescript="mouse::popup_by_mousedown()" windowedplugin="false"></embed><br>
<embed type="application/x-webkit-test-netscape" width=100 height=40 evaluatescript="key::popup_by_keydown()" windowedplugin="false"></embed><br>
Specify a script and a mouse/keyboard event to the plugin. The specified script will be evaluated in the browser when the specified event is received by the plugin. The test is for bug https://bugs.webkit.org/show_bug.cgi?id=41292.<br>
Opening window by mouse down is <span id="mousedown_output">FAILED</span><br>
Opening window by key down is <span id="keydown_output">FAILED</span>
</body>
</html>
