4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
9 <div id=
"target1"></div>
10 <div id=
"target2"></div>
13 description("Test mouse events are routed to lock target.")
14 window
.jsTestIsAsync
= true;
16 targetdiv1
= document
.getElementById("target1");
17 targetdiv2
= document
.getElementById("target2");
19 // Expect change event only for all transitions below.
20 expectedTargetToBeLockedString
= "";
21 document
.onpointerlockchange = function ()
23 testPassed("document.onpointerlockchange event received.");
24 shouldBe("document.pointerLockElement", expectedTargetToBeLockedString
);
27 document
.onpointerlockerror
=
28 function () { testFailed("document.onpointerlockerror event received."); finishJSTest(); };
30 function eventNotExpected(e
) {
31 testFailed("Unexpected event " + e
.type
+ " on " + e
.currentTarget
.id
);
34 function eventExpected(e
) {
35 testPassed("event type: " + e
.type
+ ", target: " + e
.target
.id
+ ", received on: " + e
.currentTarget
.id
);
40 targetdiv1
.requestPointerLock();
41 expectedTargetToBeLockedString
= "targetdiv1";
42 // doNextStep() called by onpointerlockchange handler.
45 debug(" With a lock in place send a click.")
46 targetdiv1
.onmousedown
= eventExpected
;
47 targetdiv2
.onmousedown
= eventNotExpected
;
48 document
.body
.onmousedown
= eventExpected
;
49 if (window
.eventSender
) {
50 window
.eventSender
.leapForward(1000);
51 window
.eventSender
.mouseDown();
52 window
.eventSender
.mouseUp();
54 doNextStepWithUserGesture();
57 targetdiv2
.requestPointerLock();
58 expectedTargetToBeLockedString
= "targetdiv2";
59 // doNextStep() called by onpointerlockchange handler.
62 debug(" With a lock in place send a click.")
63 targetdiv1
.onmousedown
= eventNotExpected
;
64 targetdiv2
.onmousedown
= eventExpected
;
65 document
.body
.onmousedown
= eventExpected
;
66 if (window
.eventSender
) {
67 window
.eventSender
.leapForward(1000);
68 window
.eventSender
.mouseDown();
69 window
.eventSender
.mouseUp();
71 doNextStepWithUserGesture();
74 debug(" Ensure double clicks work as expected, sending 4 clicks.")
75 targetdiv1
.onmousedown
= undefined;
76 document
.body
.onmousedown
= undefined;
77 targetdiv2
.onmousedown
= eventExpected
;
78 targetdiv2
.onmouseup
= eventExpected
;
79 targetdiv2
.onclick
= eventExpected
;
80 targetdiv2
.ondblclick
= eventExpected
;
81 debug(" Creating a click and dblclick.");
82 if (window
.eventSender
) {
83 window
.eventSender
.leapForward(1000);
84 window
.eventSender
.mouseDown();
85 window
.eventSender
.mouseUp();
86 window
.eventSender
.mouseDown();
87 window
.eventSender
.mouseUp();
89 debug(" Ensuring no false dblclicks if we continue.");
90 if (window
.eventSender
) {
91 window
.eventSender
.mouseDown();
92 window
.eventSender
.mouseUp();
93 window
.eventSender
.mouseDown();
94 window
.eventSender
.mouseUp();
96 doNextStepWithUserGesture();
99 doNextStepWithUserGesture();