Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / touch / script-tests / basic-single-touch-events.js
blob24a340a38ca62ac877c2ec562ea598aaf4cc8c1b
1 var div = document.createElement("div");
2 div.id = "touchtarget";
3 div.style.width = "100px";
4 div.style.height = "100px";
5 div.style.backgroundColor = "blue";
7 var lastEvent = null;
8 var touchEventsReceived = 0;
9 var EXPECTED_TOUCH_EVENTS_TOTAL = 5;
11 function touchEventCallback() {
12     if (window.eventSender) {
13         lastEvent = event;
14         verifyTouch(touchEventsReceived++);
15     } else {
16         debug(event.type);
17     }
19     if (window.testRunner && touchEventsReceived == EXPECTED_TOUCH_EVENTS_TOTAL) {
20         // If we've got here, we can safely say we were successfully parsed :) We need to
21         // call the isSucccessfullyParsed function to output the correct TEST COMPLETE
22         // footer message.
23         isSuccessfullyParsed();
24         testRunner.notifyDone();
25     }
28 div.addEventListener("touchstart", touchEventCallback, false);
29 div.addEventListener("touchmove", touchEventCallback, false);
30 div.addEventListener("touchend", touchEventCallback, false);
31 document.body.insertBefore(div, document.body.firstChild);
33 function verifyTouchEvent(type, totalTouchCount, changedTouchCount, targetTouchCount)
35     shouldBeEqualToString("lastEvent.type", type);
36     shouldBe("lastEvent.touches.length", totalTouchCount.toString());
37     shouldBe("lastEvent.changedTouches.length", changedTouchCount.toString());
38     shouldBe("lastEvent.targetTouches.length", targetTouchCount.toString());
41 function verifyTouchPoint(list, point, x, y, id, rx, ry)
43     shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString());
44     shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString());
45     shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString());
46     shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString());
47     shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString());
48     if (eventSender.setTouchPointRadius) {
49         shouldBe("lastEvent." + list + "[" + point + "].radiusX", rx.toString());
50         shouldBe("lastEvent." + list + "[" + point + "].radiusY", ry.toString());
51     }
54 function verifyTouch(which) {
55     switch (which) {
56         case 0:
57            verifyTouchEvent("touchstart", 1, 1, 1);
58            shouldBe("lastEvent.shiftKey", "false");
59            shouldBeEqualToString("lastEvent.touches[0].target.id", "touchtarget");
60            verifyTouchPoint("touches", 0, 10, 10, 0, 10, 10);
61            verifyTouchPoint("changedTouches", 0, 10, 10, 0, 10, 10);
62            verifyTouchPoint("targetTouches", 0, 10, 10, 0, 10, 10);
63         break;
64         case 1:
65            verifyTouchEvent("touchmove", 1, 1, 1);
66            verifyTouchPoint("touches", 0, 50, 50, 0, 12, 12);
67            shouldBe("lastEvent.shiftKey", "true");
68            shouldBe("lastEvent.altKey", "true");
69            shouldBe("lastEvent.ctrlKey", "false");
70            shouldBe("lastEvent.metaKey", "false");
71         break;
72         case 2:
73             verifyTouchEvent("touchend", 0, 1, 0);
74             verifyTouchPoint("changedTouches", 0, 50, 50, 0, 12, 12);
75             shouldBe("lastEvent.shiftKey", "false");
76             shouldBe("lastEvent.altKey", "false");
77         break;
78         case 3:
79             verifyTouchEvent("touchstart", 1, 1, 1);
80             shouldBeEqualToString("lastEvent.targetTouches[0].target.tagName", "DIV");
81         break;
82         case 4:
83             verifyTouchEvent("touchmove", 1, 1, 1);
84             shouldBeEqualToString("lastEvent.touches[0].target.tagName", "DIV");
85         break;
87         default: testFailed("Wrong number of touch events! (" + which + ")");
88     }
91 function singleTouchSequence()
93     if (eventSender.setTouchPointRadius)
94         eventSender.setTouchPointRadius(10,10);
95     eventSender.addTouchPoint(10, 10);
96     eventSender.touchStart();
98     if (eventSender.setTouchPointRadius)
99         eventSender.setTouchPointRadius(12,12);
100     eventSender.updateTouchPoint(0, 50, 50);
101     eventSender.setTouchModifier("shift", true);
102     eventSender.setTouchModifier("alt", true);
103     eventSender.touchMove();
105     eventSender.setTouchModifier("shift", false);
106     eventSender.setTouchModifier("alt", false);
108     eventSender.releaseTouchPoint(0);
109     eventSender.touchEnd();
112 function touchTargets()
114     eventSender.addTouchPoint(20, 20);
115     eventSender.touchStart();
117     eventSender.updateTouchPoint(0, 1000, 1000);
118     eventSender.touchMove();
121 if (window.testRunner)
122     testRunner.waitUntilDone();
124 if (window.eventSender) {
125     description("This tests basic single touch event support.");
127     lastEvent = null;
128     eventSender.clearTouchPoints();
129     singleTouchSequence();
131     lastEvent = null;
132     eventSender.clearTouchPoints();
133     touchTargets();
135 } else {
136     debug("This test requires DumpRenderTree.  Tap on the blue rect to log.")