Use testRunner instead of layoutTestController in fast/doctypes, dom, dynamic, encodi...
[WebKit-https.git] / LayoutTests / fast / events / touch / script-tests / touch-target.js
1 var targetsDiv = document.createElement("div");
2 targetsDiv.id = "targetsDiv";
3
4 var div1 = document.createElement("div");
5 div1.id = "targetA";
6 div1.style.width = "100px";
7 div1.style.height = "100px";
8 div1.style.backgroundColor = "blue";
9
10 var div2 = document.createElement("div");
11 div2.id = "targetB";
12 div2.style.width = "100px";
13 div2.style.height = "100px";
14 div2.style.backgroundColor = "green";
15
16 document.body.insertBefore(targetsDiv, document.getElementById('console'));
17 targetsDiv.appendChild(div1);
18 targetsDiv.appendChild(document.createElement('br'));
19 targetsDiv.appendChild(div2);
20
21 function declareTouchStart()
22 {
23     var touchStartCount = 0;
24     return function touchStartHandler()
25     {
26         shouldBeEqualToString('event.type', 'touchstart');
27         switch (touchStartCount) {
28             case 0:
29                 shouldBeEqualToString('event.touches[0].target.id', div1.id);
30                 shouldBeEqualToString('event.touches[1].target.id', div2.id);
31                 break;
32             case 1:
33                 shouldBeEqualToString('event.touches[0].target.id', div2.id);
34                 shouldBeEqualToString('event.touches[1].target.id', div1.id);
35                 break;
36         }
37         shouldBe('event.targetTouches.length', '1');
38
39         touchStartCount++;
40     }
41 }
42
43 var totalTouchMoveCount = 0;
44
45 function declareTouchMove(div_id)
46 {
47     var touchMoveCount = 0;
48     return function touchMoveHandler()
49     {
50         shouldBeEqualToString('event.type', 'touchmove');
51         switch (touchMoveCount) {
52             case 0:
53             case 1:
54                 shouldBeEqualToString('event.touches[0].target.id', div1.id);
55                 shouldBeEqualToString('event.touches[1].target.id', div2.id);
56                 break;
57             case 2:
58                 shouldBeEqualToString('event.touches[0].target.id', div2.id);
59                 shouldBeEqualToString('event.touches[1].target.id', div1.id);
60                 break;
61         }
62         shouldBe('event.targetTouches.length', '1');
63         ++touchMoveCount;
64
65         if (++totalTouchMoveCount == 6)
66         {
67             testRunner.notifyDone();
68             isSuccessfullyParsed();
69         }
70     }
71 }
72
73 div1.addEventListener("touchstart", declareTouchStart(), false);
74 div1.addEventListener("touchmove", declareTouchMove(), false);
75
76 div2.addEventListener("touchstart", declareTouchStart(), false);
77 div2.addEventListener("touchmove", declareTouchMove(), false);
78
79 description("Tests that the target of touches match the element where the event originated, not where the touch is currently occurring.");
80
81 if (window.testRunner) {
82     testRunner.waitUntilDone();
83 }
84
85 if (window.eventSender) {
86     eventSender.clearTouchPoints();
87     eventSender.addTouchPoint(50, 150);
88     eventSender.addTouchPoint(50, 250);
89     eventSender.touchStart();
90
91     eventSender.updateTouchPoint(0, 50, 250);
92     eventSender.updateTouchPoint(1, 50, 150);
93     eventSender.touchMove();
94
95     eventSender.updateTouchPoint(0, 1000, 1000);
96     eventSender.updateTouchPoint(1, 1000, 1000);
97     eventSender.touchMove();
98
99     eventSender.releaseTouchPoint(0);
100     eventSender.touchEnd();
101
102     eventSender.addTouchPoint(50,150);
103     eventSender.touchStart();
104
105     eventSender.updateTouchPoint(0, 500, 500);
106     eventSender.updateTouchPoint(1, 500, 500);
107     eventSender.touchMove();
108 } else
109     debug('This test requires DRT.');
110