Refactoring: Pull all fullscreen code out of Document and into its own helper class
[WebKit-https.git] / LayoutTests / pointer-lock / mouse-event-delivery.html
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <script src="../http/tests/resources/js-test-pre.js"></script>
5 <script src="../http/tests/resources/pointer-lock/pointer-lock-test-harness.js"></script>
6 </head>
7 <body id="body">
8 <div>
9   <div id="target1"></div>
10   <div id="target2"></div>
11 </div>
12 <script>
13     description("Test mouse events are routed to lock target.")
14     window.jsTestIsAsync = true;
15
16     targetdiv1 = document.getElementById("target1");
17     targetdiv2 = document.getElementById("target2");
18
19     // Expect change event only for all transitions below.
20     expectedTargetToBeLockedString = "";
21     document.onpointerlockchange = function ()
22         {
23             testPassed("document.onpointerlockchange event received.");
24             shouldBe("document.pointerLockElement", expectedTargetToBeLockedString);
25             doNextStep();
26         };
27     document.onpointerlockerror =
28         function () { testFailed("document.onpointerlockerror event received."); finishJSTest(); };
29
30     function eventNotExpected(e) {
31         testFailed("Unexpected event " + e.type + " on " + e.currentTarget.id);
32         finishJSTest();
33     }
34     function eventExpected(e) {
35       testPassed("event type: " + e.type + ", target: " + e.target.id + ", received on: " + e.currentTarget.id);
36     }
37     function eventExpectedThenNextStep(e) {
38       testPassed("event type: " + e.type + ", target: " + e.target.id + ", received on: " + e.currentTarget.id);
39       doNextStep();
40     }
41     function eventDeltaExpected(e) {
42       testPassed("event type: " + e.type + ", movementX: " + e.movementX + ", movementY: " + e.movementY + ", target: " + e.target.id + ", received on: " + e.currentTarget.id);
43     }
44     function eventDeltaExpectedThenNextStep(e) {
45       testPassed("event type: " + e.type + ", movementX: " + e.movementX + ", movementY: " + e.movementY + ", target: " + e.target.id + ", received on: " + e.currentTarget.id);
46       doNextStep();
47     }
48
49     todo = [
50         function () {
51             targetdiv1.requestPointerLock();
52             expectedTargetToBeLockedString = "targetdiv1";
53             // doNextStep() called by onpointerlockchange handler.
54         },
55         function () {
56             debug("     With a lock in place send a wheel event.")
57             targetdiv1.onwheel = eventExpectedThenNextStep;
58             targetdiv2.onwheel = eventNotExpected;
59             document.body.onwheel = eventExpected;
60             if (window.eventSender) {
61                 window.eventSender.mouseMoveTo(20,20);
62                 window.eventSender.leapForward(1000);
63                 window.eventSender.mouseScrollBy(0,10);
64             }
65         },
66         function () {
67             debug("     With a lock in place move the mouse.")
68             targetdiv1.onmousemove = eventDeltaExpectedThenNextStep;
69             targetdiv2.onmousemove = eventNotExpected;
70             document.body.onmousemove = eventDeltaExpected;
71             if (window.eventSender) {
72                 window.eventSender.mouseMoveTo(45,50);
73             }
74         },
75         function () {
76             debug("     With a lock in place send a click.")
77             targetdiv1.onmousemove = null;
78             targetdiv2.onmousemove = null;
79             document.body.onmousemove = null;
80
81             targetdiv1.onmousedown = eventExpected;
82             targetdiv2.onmousedown = eventNotExpected;
83             document.body.onmousedown = eventExpected;
84             if (window.eventSender) {
85                 window.eventSender.leapForward(1000);
86                 window.eventSender.mouseDown();
87                 window.eventSender.mouseUp();
88             }
89             doNextStepWithUserGesture();
90         },
91         function () {
92             targetdiv2.requestPointerLock();
93             expectedTargetToBeLockedString = "targetdiv2";
94             // doNextStep() called by onpointerlockchange handler.
95         },
96         function () {
97             debug("     With a lock in place send a wheel event.")
98             targetdiv1.onwheel = eventNotExpected;
99             targetdiv2.onwheel = eventExpectedThenNextStep;
100             document.body.onwheel = eventExpected;
101             if (window.eventSender) {
102                 window.eventSender.leapForward(1000);
103                 window.eventSender.mouseScrollBy(0,10);
104             }
105         },
106         function () {
107             debug("     With a lock in place send a click.")
108             targetdiv1.onmousedown = eventNotExpected;
109             targetdiv2.onmousedown = eventExpected;
110             document.body.onmousedown = eventExpected;
111             if (window.eventSender) {
112                 window.eventSender.leapForward(1000);
113                 window.eventSender.mouseDown();
114                 window.eventSender.mouseUp();
115             }
116             doNextStepWithUserGesture();
117         },
118         function () {
119             debug("     Ensure double clicks work as expected, sending 4 clicks.")
120             targetdiv1.onmousedown = undefined;
121             document.body.onmousedown = undefined;
122             targetdiv2.onmousedown = eventExpected;
123             targetdiv2.onmouseup = eventExpected;
124             targetdiv2.onclick = eventExpected;
125             targetdiv2.ondblclick = eventExpected;
126             debug("     Creating a click and dblclick.");
127             if (window.eventSender) {
128                 window.eventSender.leapForward(1000);
129                 window.eventSender.mouseDown();
130                 window.eventSender.mouseUp();
131                 window.eventSender.mouseDown();
132                 window.eventSender.mouseUp();
133             }
134             debug("     Ensuring no false dblclicks if we continue.");
135             if (window.eventSender) {
136                 window.eventSender.mouseDown();
137                 window.eventSender.mouseUp();
138                 window.eventSender.mouseDown();
139                 window.eventSender.mouseUp();
140             }
141             doNextStepWithUserGesture();
142         },
143     ];
144     doNextStepWithUserGesture();
145 </script>
146 <script src="../http/tests/resources/js-test-post.js"></script>
147 </body>
148 </html>