[iOS] Add iOS-specific tests and consolidate iOS-specific accessibility tests
[WebKit-https.git] / LayoutTests / platform / ios-simulator / ios / fast / events / touch / script-tests / touch-event-pageXY.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         successfullyParsed = true;
24         isSuccessfullyParsed();
25         testRunner.notifyDone();
26     }
27 }
28
29 div.addEventListener("touchstart", touchEventCallback, false);
30 div.addEventListener("touchmove", touchEventCallback, false);
31 div.addEventListener("touchend", touchEventCallback, false);
32 document.body.insertBefore(div, document.body.firstChild);
33
34 function 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 }
41
42 function verifyTouchPoint(list, point, x, y, id)
43 {
44     shouldBe("lastEvent." + list + "[" + point + "].pageX", x.toString());
45     shouldBe("lastEvent." + list + "[" + point + "].pageY", y.toString());
46     shouldBe("lastEvent." + list + "[" + point + "].clientX", x.toString());
47     shouldBe("lastEvent." + list + "[" + point + "].clientY", y.toString());
48     shouldBe("lastEvent." + list + "[" + point + "].identifier", id.toString());
49 }
50
51 function verifyTouch(which) {
52     switch (which) {
53         case 0:
54            verifyTouchEvent("touchstart", 1, 1, 1);
55            shouldBeEqualToString("lastEvent.touches[0].target.id", "touchtarget");
56
57            verifyTouchPoint("touches", 0, 8, 12, 0);
58            verifyTouchPoint("changedTouches", 0, 8, 12, 0);
59            verifyTouchPoint("targetTouches", 0, 8, 12, 0);
60
61            shouldBe("lastEvent.pageX", '8');
62            shouldBe("lastEvent.pageY", '12');
63         break;
64         case 1:
65            verifyTouchEvent("touchmove", 1, 1, 1);
66            verifyTouchPoint("touches", 0, 10, 15, 0);
67
68            shouldBe("lastEvent.pageX", '10');
69            shouldBe("lastEvent.pageY", '15');
70         break;
71         case 2:
72            verifyTouchEvent("touchstart", 2, 1, 2);
73            verifyTouchPoint("touches", 0, 10, 15, 0);
74            verifyTouchPoint("touches", 1, 40, 45, 1);
75
76            shouldBe("lastEvent.pageX", '25');
77            shouldBe("lastEvent.pageY", '30');
78         break;
79         case 3:
80             verifyTouchEvent("touchend", 1, 1, 1);
81
82             shouldBe("lastEvent.pageX", '40');
83             shouldBe("lastEvent.pageY", '45');
84         break;
85
86         default: testFailed("Wrong number of touch events! (" + which + ")");
87     }
88 }
89
90 function sendTouchSequence()
91 {
92     eventSender.addTouchPoint(8, 12);
93     eventSender.touchStart();
94
95     debug('move');
96     eventSender.updateTouchPoint(0, 10, 15);
97     eventSender.touchMove();
98
99     debug('add second touch');
100     eventSender.addTouchPoint(40, 45);
101     eventSender.touchStart();
102
103     debug('end');
104     eventSender.releaseTouchPoint(0);
105     eventSender.touchEnd();
106 }
107
108 if (window.testRunner)
109     testRunner.waitUntilDone();
110
111 if (window.eventSender) {
112     description("This tests pageX and pageY coordinates on touch events and touches.");
113
114     lastEvent = null;
115     sendTouchSequence();
116
117 } else {
118     debug("This test requires DumpRenderTree.  Tap on the blue rect to log.")
119 }
120
121