<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<iframe src="data:text/html,"></iframe>
<button type="button">Button</button>
<script>
description('Mousedown without mouseup in a sub frame should not confuse a click in another frame.');
jsTestIsAsync = true;
window.onload = function() {
    var button = document.querySelector('button');
    button.addEventListener('mousedown', function(event) {
        event.preventDefault();
    }, false);
    button.addEventListener('click', function(event) {
        testPassed('Click event was dispatched.');
        finishJSTest();
    }, false);

    var iframe = document.querySelector('iframe');
    // Mousedown on the iframe, but no mouseup.
    eventSender.mouseMoveTo(iframe.offsetLeft + iframe.offsetWidth / 2, iframe.offsetTop + iframe.offsetHeight / 2);
    eventSender.mouseDown(1);
    // Click on the button in the main document.
    eventSender.mouseMoveTo(button.offsetLeft + button.offsetWidth / 2, button.offsetTop + button.offsetHeight / 2);
    eventSender.mouseDown(0);
    setTimeout(function() {
        testFailed('Click event was not dispatched.');
        finishJSTest();
    }, 100);
    eventSender.mouseUp(0);
}
</script>
