mouse-event-delivery.html 3.9 KB
Newer Older
1 2 3
<!DOCTYPE HTML>
<html>
<head>
4 5
<script src="../http/tests/resources/js-test-pre.js"></script>
<script src="../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
6 7 8 9 10 11 12 13 14 15 16 17 18
</head>
<body id="body">
<div>
  <div id="target1"></div>
  <div id="target2"></div>
</div>
<script>
    description("Test mouse events are routed to lock target.")
    window.jsTestIsAsync = true;

    targetdiv1 = document.getElementById("target1");
    targetdiv2 = document.getElementById("target2");

19 20 21 22 23 24
    // Expect change event only for all transitions below.
    expectedTargetToBeLockedString = "";
    document.onwebkitpointerlockchange = function ()
        {
            testPassed("document.onwebkitpointerlockchange event received.");
            shouldBe("document.webkitPointerLockElement", expectedTargetToBeLockedString);
25
            doNextStep();
26 27 28 29
        };
    document.onwebkitpointerlockerror =
        function () { testFailed("document.onwebkitpointerlockerror event received."); finishJSTest(); };

30 31 32 33 34 35 36 37 38 39
    function eventNotExpected(e) {
        testFailed("Unexpected event " + e.type + " on " + e.currentTarget.id);
        finishJSTest();
    }
    function eventExpected(e) {
      testPassed("event type: " + e.type + ", target: " + e.target.id + ", received on: " + e.currentTarget.id);
    }

    todo = [
        function () {
40 41 42
            targetdiv1.webkitRequestPointerLock();
            expectedTargetToBeLockedString = "targetdiv1";
            // doNextStep() called by onwebkitpointerlockchange handler.
43 44
        },
        function () {
45
            debug("     With a lock in place send a click.")
46 47 48
            targetdiv1.onmousedown = eventExpected;
            targetdiv2.onmousedown = eventNotExpected;
            document.body.onmousedown = eventExpected;
49 50 51 52 53
            if (window.eventSender) {
                window.eventSender.leapForward(1000);
                window.eventSender.mouseDown();
                window.eventSender.mouseUp();
            }
54
            doNextStepWithUserGesture();
55 56
        },
        function () {
57 58 59
            targetdiv2.webkitRequestPointerLock();
            expectedTargetToBeLockedString = "targetdiv2";
            // doNextStep() called by onwebkitpointerlockchange handler.
60 61
        },
        function () {
62
            debug("     With a lock in place send a click.")
63 64 65
            targetdiv1.onmousedown = eventNotExpected;
            targetdiv2.onmousedown = eventExpected;
            document.body.onmousedown = eventExpected;
66 67 68 69 70
            if (window.eventSender) {
                window.eventSender.leapForward(1000);
                window.eventSender.mouseDown();
                window.eventSender.mouseUp();
            }
71
            doNextStepWithUserGesture();
72 73
        },
        function () {
74 75 76
            debug("     Ensure double clicks work as expected, sending 4 clicks.")
            targetdiv1.onmousedown = undefined;
            document.body.onmousedown = undefined;
77 78 79 80
            targetdiv2.onmousedown = eventExpected;
            targetdiv2.onmouseup = eventExpected;
            targetdiv2.onclick = eventExpected;
            targetdiv2.ondblclick = eventExpected;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
            debug("     Creating a click and dblclick.");
            if (window.eventSender) {
                window.eventSender.leapForward(1000);
                window.eventSender.mouseDown();
                window.eventSender.mouseUp();
                window.eventSender.mouseDown();
                window.eventSender.mouseUp();
            }
            debug("     Ensuring no false dblclicks if we continue.");
            if (window.eventSender) {
                window.eventSender.mouseDown();
                window.eventSender.mouseUp();
                window.eventSender.mouseDown();
                window.eventSender.mouseUp();
            }
96
            doNextStepWithUserGesture();
97 98
        },
    ];
99
    doNextStepWithUserGesture();
100
</script>
101
<script src="../http/tests/resources/js-test-post.js"></script>
102 103
</body>
</html>