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";
8 var touchEventsReceived = 0;
9 var EXPECTED_TOUCH_EVENTS_TOTAL = 5;
11 function touchEventCallback() {
12 if (window.eventSender) {
14 verifyTouch(touchEventsReceived++);
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
23 isSuccessfullyParsed();
24 testRunner.notifyDone();
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());
54 function verifyTouch(which) {
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);
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");
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");
79 verifyTouchEvent("touchstart", 1, 1, 1);
80 shouldBeEqualToString("lastEvent.targetTouches[0].target.tagName", "DIV");
83 verifyTouchEvent("touchmove", 1, 1, 1);
84 shouldBeEqualToString("lastEvent.touches[0].target.tagName", "DIV");
87 default: testFailed("Wrong number of touch events! (" + which + ")");
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.");
128 eventSender.clearTouchPoints();
129 singleTouchSequence();
132 eventSender.clearTouchPoints();
136 debug("This test requires DumpRenderTree. Tap on the blue rect to log.")