1518d8916610ac51037fc4cc86813fc3ef1fa942
[WebKit-https.git] / LayoutTests / fast / events / touch / multi-touch-inside-iframes.html
1 <html>
2 <script src="../../js/resources/js-test-pre.js"></script>
3 <style>
4 iframe {
5   width: 100px;
6   height: 100px;
7   margin: 0;
8   padding: 0;
9   border: 1px solid black;
10 }
11
12 #iframe1
13 {
14 position:absolute;
15 left:50px;
16 top:50px;
17 }
18
19 #iframe2
20 {
21 position:absolute;
22 left:200px;
23 top:50px;
24 }
25
26 #output
27 {
28 position:absolute;
29 top:150px;
30 }
31
32 </style>
33 <body onload="runTest()">
34 <iframe id="iframe1" src="./resources/multi-touch-inside-iframes2.html"></iframe>
35 <iframe id="iframe2" src="./resources/multi-touch-inside-iframes2.html"></iframe>
36 <div id="output">
37 <p id="description"></p>
38 <div id="console"></div>
39 </div>
40 <script type="text/javascript">
41 description('Test multi-touch is sent to the same iframe.');
42
43 var touchEventCount = 0;
44 var title = 0;
45
46 function onTouch(event, receiver)
47 {
48     ev = event;
49     touchreceiver = receiver;
50     switch (touchEventCount) {
51         case 0:
52             shouldBeEqualToString('ev.type', 'touchstart');
53             shouldBeEqualToString('touchreceiver', 'iframe1');
54             shouldBe("ev.changedTouches.length", "1");
55             shouldBe("ev.touches.length", "1");
56             shouldBe("ev.targetTouches.length", "1");
57             shouldBe("ev.touches[0].pageX", "50");
58             shouldBe("ev.touches[0].pageY", "50");
59             shouldBeEqualToString('ev.touches[0].target.ownerDocument.title', 'iframe1');
60             shouldBeEqualToString('ev.changedTouches[0].target.ownerDocument.title', 'iframe1');
61             shouldBeEqualToString('ev.targetTouches[0].target.ownerDocument.title', 'iframe1');
62             break;
63         case 1:
64             shouldBeEqualToString('ev.type', 'touchmove');
65             shouldBeEqualToString('touchreceiver', 'iframe1');
66             shouldBe("ev.changedTouches.length", "1");
67             shouldBe("ev.touches.length", "1");
68             shouldBe("ev.targetTouches.length", "1");
69             shouldBe("ev.touches[0].pageX", "150");
70             shouldBe("ev.touches[0].pageY", "150");
71             shouldBeEqualToString('ev.touches[0].target.ownerDocument.title', 'iframe1');
72             shouldBeEqualToString('ev.changedTouches[0].target.ownerDocument.title', 'iframe1');
73             shouldBeEqualToString('ev.targetTouches[0].target.ownerDocument.title', 'iframe1');
74             break;
75         case 2:
76             shouldBeEqualToString('ev.type', 'touchend');
77             shouldBeEqualToString('touchreceiver', 'iframe1');
78             shouldBe("ev.changedTouches.length", "1");
79             shouldBe("ev.touches.length", "0");
80             shouldBe("ev.targetTouches.length", "0");
81             shouldBeEqualToString('ev.changedTouches[0].target.ownerDocument.title', 'iframe1');
82             break;
83         case 3:
84             shouldBeEqualToString('ev.type', 'touchstart');
85             shouldBeEqualToString('touchreceiver', 'iframe2');
86             shouldBe("ev.changedTouches.length", "1");
87             shouldBe("ev.touches.length", "1");
88             shouldBe("ev.targetTouches.length", "1");
89             shouldBe("ev.touches[0].pageX", "50");
90             shouldBe("ev.touches[0].pageY", "50");
91             shouldBeEqualToString('ev.touches[0].target.ownerDocument.title', 'iframe2');
92             shouldBeEqualToString('ev.changedTouches[0].target.ownerDocument.title', 'iframe2');
93             shouldBeEqualToString('ev.targetTouches[0].target.ownerDocument.title', 'iframe2');
94             break;
95         case 4:
96             shouldBeEqualToString('ev.type', 'touchend');
97             shouldBeEqualToString('touchreceiver', 'iframe2');
98             shouldBe("ev.changedTouches.length", "1");
99             shouldBe("ev.touches.length", "0");
100             shouldBe("ev.targetTouches.length", "0");
101             shouldBeEqualToString('ev.changedTouches[0].target.ownerDocument.title', 'iframe2');
102             isSuccessfullyParsed();
103             testRunner.notifyDone();
104     }
105     touchEventCount++;
106 }
107
108 function runTest() {
109     document.getElementById("iframe1").contentWindow.document.title = "iframe1";
110     document.getElementById("iframe2").contentWindow.document.title = "iframe2";
111     if (window.eventSender) {
112         eventSender.clearTouchPoints();
113         // Touch the center of iframe1. 50px is offset to iframe1 in main frame,
114         // 1px for the iframe border, 50px to get to centre.
115         debug('First touch is on iframe1.');
116         shouldBeEqualToString('document.elementFromPoint(101, 101).id', 'iframe1');
117         eventSender.addTouchPoint(101, 101);
118         eventSender.touchStart();
119         debug('');
120
121         debug('Second touch is on iframe2, nothing should happen.');
122         shouldBeEqualToString('document.elementFromPoint(251, 101).id', 'iframe2');
123         eventSender.addTouchPoint(251, 101);
124         eventSender.touchStart();
125         debug('');
126
127         debug('Moves the first touch outside iframe1.');
128         eventSender.updateTouchPoint(0, 201, 201);
129         eventSender.touchMove();
130         debug('');
131
132         debug('Release the first touch.');
133         eventSender.releaseTouchPoint(0);
134         eventSender.touchEnd();
135         debug('');
136
137         debug('Third touch is on iframe2, nothing should happen.');
138         shouldBeEqualToString('document.elementFromPoint(261, 101).id', 'iframe2');
139         eventSender.addTouchPoint(261, 101);
140         eventSender.touchStart();
141         debug('');
142
143         debug('Release all touches on iframe2, and touch iframe2 again.');
144         eventSender.releaseTouchPoint(0);
145         eventSender.releaseTouchPoint(1);
146         eventSender.touchEnd();
147         eventSender.addTouchPoint(251, 101);
148         eventSender.touchStart();
149         debug('');
150
151         debug('Touch iframe1, nothing shoud happen.');
152         eventSender.addTouchPoint(101, 101);
153         eventSender.touchStart();
154         debug('');
155
156         debug('Release all touches.');
157         eventSender.releaseTouchPoint(0);
158         eventSender.releaseTouchPoint(1);
159         eventSender.touchEnd();
160     } else {
161        debug('This test requires DRT.');
162     }
163 }
164
165 if (window.testRunner) {
166     testRunner.waitUntilDone();
167 }
168 </script>
169 </body>
170 </html>