JS Test Harness: Insert the stylesheet dynamically
[WebKit-https.git] / LayoutTests / fast / events / touch / touch-gesture-click.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../js/resources/js-test-pre.js"></script>
5 <script src="../../js/resources/js-test-post-function.js"></script>
6 <style type="text/css">
7 #touchtarget {
8   width: 100px;
9   height: 100px;
10   background: blue;
11 }
12 </style>
13 </head>
14 <body onload="runTest();">
15 <div id="touchtarget">
16
17 <p id="description"></p>
18 <div id="console"></div>
19
20 <script>
21 var clickEventsReceived = 0;
22 var expectedMouseEvents = 4;
23 var touchEventsReceived = 0;
24 var mouseEventsReceived = 0;
25 var eventTypes = [ 'mousemove', 'mousedown', 'mouseup', 'click' ];
26
27 function gestureEventCallback(event)
28 {
29     if (window.eventSender) {
30         shouldBeEqualToString('event.type', eventTypes[mouseEventsReceived]);
31         shouldBe('event.clientX', '10');
32         shouldBe('event.clientY', '12');
33         shouldBe("event.shiftKey", "true");
34         shouldBe("event.altKey", "true");
35         shouldBe("event.ctrlKey", "false");
36         shouldBe("event.metaKey", "false");
37         mouseEventsReceived++;
38     } else {
39         debug(event.type);
40         debug(event.clientX);
41         debug(event.clientY);
42     }
43 }
44
45 // Because we may not have a gesture recognizer, we send a key press
46 // event to end the test without temporal flakiness.
47 function quitKeyToEndTest(event) {
48     endTest();
49 }
50
51 // Log that we still got the touch events.
52 function touchEventCallback(event) {
53     touchEventsReceived++;
54     debug('have received: ' + touchEventsReceived + ' touch events');
55     return true;
56 }
57
58 function singleTouchSequence()
59 {
60     eventSender.clearTouchPoints();
61     eventSender.addTouchPoint(10, 12);
62     eventSender.touchStart();
63
64     // Insert some delay. NB: this value depends on minClickDownTime,
65     // maxClickDownTime from GestureRecognizerChromium.cpp
66     eventSender.leapForward(20);
67     eventSender.setTouchModifier("shift", true);
68     eventSender.setTouchModifier("alt", true);
69
70     eventSender.releaseTouchPoint(0);
71     eventSender.touchEnd();
72 }
73
74 function endTest()
75 {
76     if (mouseEventsReceived < expectedMouseEvents) {
77         debug('Gesture manager not implemented on this platform.');
78     }
79     // Bail.
80     successfullyParsed = true;
81     isSuccessfullyParsed();
82     layoutTestController.notifyDone();
83 }
84
85 function runTest() {
86     var div = document.getElementById('touchtarget');
87     div.addEventListener("mousedown", gestureEventCallback, false);
88     div.addEventListener("click", gestureEventCallback, false);
89     div.addEventListener("mouseup", gestureEventCallback, false);
90     div.addEventListener("mousemove", gestureEventCallback, false);
91     document.addEventListener("keydown", quitKeyToEndTest, false);
92     div.addEventListener("touchstart", touchEventCallback, false);
93     div.addEventListener("touchmove", touchEventCallback, false);
94     div.addEventListener("touchend", touchEventCallback, false);
95
96     if (window.layoutTestController)
97         layoutTestController.waitUntilDone();
98
99     if (window.eventSender) {
100         description("This tests basic single touch gesture generation.");
101         if (eventSender.clearTouchPoints) {
102             singleTouchSequence();
103             eventSender.leapForward(10);
104             eventSender.keyDown(' ');
105         } else {
106             endTest();
107         }
108     } else {
109         debug("This test requires DumpRenderTree.  Tap on the blue rect to log.")
110     }
111 }
112 </script>
113 </body>
114 </html>