<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<style type="text/css">
</style>
</head>
<body>
<p id="description"></p>
<p><a href="https://bugs.webkit.org/show_bug.cgi?id=85343">Bug 85343</a></p>
<div id="test-container">
    <div id="target" style="cursor:default">Mouse idle, change cursor should not fire mousemove event</div>
</div>
<br/>
<div id="console"></div>
<script>

description("Test that there is no mousemove event fired when changing cursor.");

if (!window.eventSender) {
    testFailed('This test requires DumpRenderTree');
}

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
    window.jsTestIsAsync = true;
}

(async function()
{
    // Can't do anything useful here without eventSender
    if (!window.eventSender)
        return;

    var node = document.getElementById('target');
    debug('TEST CASE: ' + node.textContent);
    eventSender.mouseMoveTo(node.offsetLeft + 3, node.offsetTop + 3);
    debug('Cursor Info: ' + window.internals.getCurrentCursorInfo());
    node.addEventListener('mousemove', function() {
        testFailed('Mousemove event should not be fired when changing cursor');
        finishJSTest();
    });
    node.style.cursor = 'help';

    // Cursor will be updated immediately after the next animation frame.
    await new Promise(requestAnimationFrame);
    await new Promise(setTimeout);
    debug('Cursor Info: ' + window.internals.getCurrentCursorInfo());
    debug('');

    // Give some time for the change to resolve. Fake mousemove event that caused bug, is using a timer
    await new Promise(resolve => setTimeout(resolve, 100));
    document.getElementById('test-container').style.display = 'none';
    finishJSTest();
})();

</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
