1var div = document.createElement("div");
2div.id = "touchtarget";
3div.style.width = "100px";
4div.style.height = "100px";
5div.style.backgroundColor = "blue";
6
7var lastEvent = null;
8var touchEventsReceived = 0;
9var EXPECTED_TOUCH_EVENTS_TOTAL = 3;
10
11function touchEventCallback() {
12    if (window.eventSender) {
13        lastEvent = event;
14        verifyTouch(touchEventsReceived++);
15    } else {
16        debug(event.type);
17    }
18
19    if (window.layoutTestController && 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        successfullyParsed = true;
24        isSuccessfullyParsed();
25        layoutTestController.notifyDone();
26    }
27}
28
29div.addEventListener("touchstart", touchEventCallback, false);
30div.addEventListener("touchmove", touchEventCallback, false);
31div.addEventListener("touchend", touchEventCallback, false);
32document.body.insertBefore(div, document.body.firstChild);
33
34function verifyTouchEvent(type, totalTouchCount, changedTouchCount, targetTouchCount)
35{
36    shouldBeEqualToString("lastEvent.type", type);
37    shouldBe("lastEvent.touches.length", totalTouchCount.toString());
38    shouldBe("lastEvent.changedTouches.length", changedTouchCount.toString());
39    shouldBe("lastEvent.targetTouches.length", targetTouchCount.toString());
40    shouldBe("lastEvent.pageX", "0");
41    shouldBe("lastEvent.pageY", "0");
42}
43
44function verifyTouchPoint(list, point, x, y, id)
45{
46    shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString());
47    shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString());
48    shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString());
49    shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString());
50    shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString());
51}
52
53function verifyTouch(which) {
54    switch (which) {
55        case 0:
56            verifyTouchEvent("touchstart", 2, 2, 2);
57            verifyTouchPoint("touches", 0, 10, 10, 0);
58            verifyTouchPoint("touches", 1, 20, 30, 1);
59            verifyTouchPoint("changedTouches", 0, 10, 10, 0);
60            verifyTouchPoint("changedTouches", 1, 20, 30, 1);
61            verifyTouchPoint("targetTouches", 0, 10, 10, 0);
62            verifyTouchPoint("targetTouches", 1, 20, 30, 1);
63        break;
64        case 1:
65            verifyTouchEvent("touchmove", 2, 2, 2);
66            verifyTouchPoint("touches", 0, 15, 15, 0);
67            verifyTouchPoint("touches", 1, 25, 35, 1);
68            verifyTouchPoint("changedTouches", 0, 15, 15, 0);
69            verifyTouchPoint("changedTouches", 1, 25, 35, 1);
70            verifyTouchPoint("targetTouches", 0, 15, 15, 0);
71            verifyTouchPoint("targetTouches", 1, 25, 35, 1);
72        break;
73        case 2:
74            verifyTouchEvent("touchend", 0, 2, 0);
75            verifyTouchPoint("changedTouches", 0, 15, 15, 0);
76            verifyTouchPoint("changedTouches", 1, 25, 35, 1);
77        break;
78
79        default: testFailed("Wrong number of touch events! (" + which + ")");
80    }
81}
82
83function multiTouchSequence()
84{
85    eventSender.addTouchPoint(10, 10);
86    eventSender.addTouchPoint(20, 30);
87    eventSender.touchStart();
88
89    eventSender.updateTouchPoint(0, 15, 15);
90    eventSender.updateTouchPoint(1, 25, 35);
91    eventSender.touchMove();
92
93    eventSender.releaseTouchPoint(0);
94    eventSender.releaseTouchPoint(1);
95    eventSender.touchEnd();
96}
97
98if (window.eventSender) {
99    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.");
100
101    lastEvent = null;
102    eventSender.clearTouchPoints();
103    multiTouchSequence();
104} else {
105    debug("This test requires DumpRenderTree.  Tap on the blue rect to log.")
106}
107
108var successfullyParsed = true;
109