4 <script src="../../../resources/js-test.js"></script>
5 <div id="touchtarget" style="width: 100px; height: 100px; background-color: blue"></div>
6 <p id="description"></p>
7 <div id="console"></div>
9 var div = document.getElementById("touchtarget");
11 var touchEventsReceived = 0;
12 var EXPECTED_TOUCH_EVENTS_TOTAL = 3;
14 function touchEventCallback(event) {
15 if (window.eventSender) {
17 verifyTouch(touchEventsReceived++);
21 // TODO: Touch emulation shouldn't generate mouse events regardless of whether
22 // preventDefault is called. http://crbug.com/278300.
23 event.preventDefault();
25 if (window.testRunner && touchEventsReceived == EXPECTED_TOUCH_EVENTS_TOTAL) {
26 window.internals.settings.setTouchEventEmulationEnabled(false);
31 function mouseMoveCallback(e) {
32 debug("FAIL: Unexpected mousemove event: " + e.clientX + ", " + e.clientY);
35 div.addEventListener("touchstart", touchEventCallback, false);
36 div.addEventListener("touchmove", touchEventCallback, false);
37 div.addEventListener("touchend", touchEventCallback, false);
38 div.addEventListener("mousemove", mouseMoveCallback, false);
40 function verifyTouchEvent(type, totalTouchCount, changedTouchCount, targetTouchCount)
42 shouldBeEqualToString("lastEvent.type", type);
43 shouldBe("lastEvent.touches.length", totalTouchCount.toString());
44 shouldBe("lastEvent.changedTouches.length", changedTouchCount.toString());
45 shouldBe("lastEvent.targetTouches.length", targetTouchCount.toString());
46 shouldBe("lastEvent.pageX", "0");
47 shouldBe("lastEvent.pageY", "0");
50 function verifyTouchPoint(list, point, x, y, id)
52 shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString());
53 shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString());
54 shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString());
55 shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString());
56 shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString());
59 function verifyTouch(which) {
62 verifyTouchEvent("touchstart", 1, 1, 1);
63 shouldBe("lastEvent.shiftKey", "true");
64 shouldBe("lastEvent.altKey", "true");
65 shouldBe("lastEvent.ctrlKey", "false");
66 shouldBe("lastEvent.metaKey", "false");
67 shouldBeEqualToString("lastEvent.touches[0].target.id", "touchtarget");
68 verifyTouchPoint("touches", 0, 10, 10, 0);
69 verifyTouchPoint("changedTouches", 0, 10, 10, 0);
70 verifyTouchPoint("targetTouches", 0, 10, 10, 0);
73 verifyTouchEvent("touchmove", 1, 1, 1);
74 verifyTouchPoint("touches", 0, 20, 30, 0);
77 verifyTouchEvent("touchend", 0, 1, 0);
78 verifyTouchPoint("changedTouches", 0, 20, 30, 0);
79 shouldBe("lastEvent.shiftKey", "false");
80 shouldBe("lastEvent.altKey", "true");
81 shouldBe("lastEvent.ctrlKey", "true");
82 shouldBe("lastEvent.metaKey", "false");
85 testFailed("Wrong number of touch events! (" + which + ")");
89 function mouseEventSequence()
91 eventSender.mouseMoveTo(10, 10);
92 eventSender.mouseDown(0, ["shiftKey", "altKey"]);
93 eventSender.mouseMoveTo(20, 30);
94 eventSender.mouseUp(0, ["altKey", "ctrlKey"]);
97 if (window.eventSender && window.internals && window.internals.settings) {
98 description("This tests single touch event emulation using mouse events.");
100 window.eventSender.dragMode = false;
101 window.jsTestIsAsync = true;
102 window.internals.settings.setTouchEventEmulationEnabled(true);
104 shouldBe("'ontouchstart' in window", "true");
105 shouldBe("'ontouchend' in document", "true");
107 mouseEventSequence();
109 debug("This test requires DumpRenderTree. Tap on the blue rect to log.");