Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / touch / script-tests / basic-multi-touch-events-limited.js
blob6476433034affffd47187c81848bd5c731ed5f5c
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 = 3;
11 function touchEventCallback() {
12 if (window.eventSender) {
13 lastEvent = event;
14 verifyTouch(touchEventsReceived++);
15 } else {
16 debug(event.type);
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();
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)
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());
50 function verifyTouch(which) {
51 switch (which) {
52 case 0:
53 verifyTouchEvent("touchstart", 2, 2, 2);
54 verifyTouchPoint("touches", 0, 10, 10, 0);
55 verifyTouchPoint("touches", 1, 20, 30, 1);
56 verifyTouchPoint("changedTouches", 0, 10, 10, 0);
57 verifyTouchPoint("changedTouches", 1, 20, 30, 1);
58 verifyTouchPoint("targetTouches", 0, 10, 10, 0);
59 verifyTouchPoint("targetTouches", 1, 20, 30, 1);
60 break;
61 case 1:
62 verifyTouchEvent("touchmove", 2, 2, 2);
63 verifyTouchPoint("touches", 0, 15, 15, 0);
64 verifyTouchPoint("touches", 1, 25, 35, 1);
65 verifyTouchPoint("changedTouches", 0, 15, 15, 0);
66 verifyTouchPoint("changedTouches", 1, 25, 35, 1);
67 verifyTouchPoint("targetTouches", 0, 15, 15, 0);
68 verifyTouchPoint("targetTouches", 1, 25, 35, 1);
69 break;
70 case 2:
71 verifyTouchEvent("touchend", 0, 2, 0);
72 verifyTouchPoint("changedTouches", 0, 15, 15, 0);
73 verifyTouchPoint("changedTouches", 1, 25, 35, 1);
74 break;
76 default: testFailed("Wrong number of touch events! (" + which + ")");
80 function multiTouchSequence()
82 eventSender.addTouchPoint(10, 10);
83 eventSender.addTouchPoint(20, 30);
84 eventSender.touchStart();
86 eventSender.updateTouchPoint(0, 15, 15);
87 eventSender.updateTouchPoint(1, 25, 35);
88 eventSender.touchMove();
90 eventSender.releaseTouchPoint(0);
91 eventSender.releaseTouchPoint(1);
92 eventSender.touchEnd();
95 if (window.eventSender) {
96 description("This tests basic multi touch event support. This is a limited version of test basic-multi-touch-events.html that avoids the situation where one touch point is released while another is maintained.");
98 lastEvent = null;
99 eventSender.clearTouchPoints();
100 multiTouchSequence();
101 } else {
102 debug("This test requires DumpRenderTree. Tap on the blue rect to log.")