Use testRunner instead of layoutTestController in fast/doctypes, dom, dynamic, encodi...
[WebKit-https.git] / LayoutTests / fast / events / touch / script-tests / basic-multi-touch-events.js
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";
6
7 var lastEvent = null;
8 var touchEventsReceived = 0;
9 var EXPECTED_TOUCH_EVENTS_TOTAL = 4;
10
11 function touchEventCallback() {
12     if (window.eventSender) {
13         lastEvent = event;
14         verifyTouch(touchEventsReceived++);
15     } else {
16         debug(event.type);
17     }
18
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     }
26 }
27
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);
32
33 function verifyTouchEvent(type, totalTouchCount, changedTouchCount, targetTouchCount)
34 {
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());
39     shouldBe("lastEvent.pageX", "0");
40     shouldBe("lastEvent.pageY", "0");
41 }
42
43 function verifyTouchPoint(list, point, x, y, id)
44 {
45     shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString());
46     shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString());
47     shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString());
48     shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString());
49     shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString());
50 }
51
52 function verifyTouch(which) {
53     switch (which) {
54         case 0:
55             verifyTouchEvent("touchstart", 2, 2, 2);
56             verifyTouchPoint("touches", 0, 10, 10, 0);
57             verifyTouchPoint("touches", 1, 20, 30, 1);
58             verifyTouchPoint("changedTouches", 0, 10, 10, 0);
59             verifyTouchPoint("changedTouches", 1, 20, 30, 1);
60             verifyTouchPoint("targetTouches", 0, 10, 10, 0);
61             verifyTouchPoint("targetTouches", 1, 20, 30, 1);
62         break;
63         case 1:
64             verifyTouchEvent("touchmove", 2, 1, 2);
65             verifyTouchPoint("touches", 0, 15, 15, 0);
66             verifyTouchPoint("changedTouches", 0, 15, 15, 0);
67             verifyTouchPoint("touches", 1, 20, 30, 1);
68         break;
69         case 2:
70             verifyTouchEvent("touchend", 1, 1, 1);
71             verifyTouchPoint("touches", 0, 20, 30, 1);
72             verifyTouchPoint("changedTouches", 0, 15, 15, 0);
73             verifyTouchPoint("targetTouches", 0, 20, 30, 1);
74         break;
75         case 3:
76             verifyTouchEvent("touchend", 0, 1, 0);
77             verifyTouchPoint("changedTouches", 0, 20, 30, 1);
78         break;
79
80         default: testFailed("Wrong number of touch events! (" + which + ")");
81     }
82 }
83
84 function multiTouchSequence()
85 {
86     debug("multi touch sequence");
87
88     debug("Two touchpoints pressed");
89     eventSender.addTouchPoint(10, 10);
90     eventSender.addTouchPoint(20, 30);
91     eventSender.touchStart();
92
93     debug("First touchpoint moved");
94     eventSender.updateTouchPoint(0, 15, 15);
95     eventSender.touchMove();
96
97     debug("First touchpoint is released");
98     eventSender.releaseTouchPoint(0);
99     eventSender.touchEnd();
100
101     debug("Last remaining touchpoint is released");
102     eventSender.releaseTouchPoint(0);
103     eventSender.touchEnd();
104 }
105
106 if (window.eventSender) {
107     description("This tests basic multi touch event support.");
108
109     lastEvent = null;
110     eventSender.clearTouchPoints();
111     multiTouchSequence();
112 } else {
113     debug("This test requires DumpRenderTree.  Tap on the blue rect to log.")
114 }