Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / touch / touch-fractional-coordinates.html
blobc868c01f0cf701e07aae474fded6501193bdb7de
1 <!DOCTYPE html>
2 <script src='../../../resources/js-test.js'></script>
3 <style>
4 #spacer {
5 height: 1000px;
6 width: 1000px;
8 iframe {
9 width: 100px;
10 height: 100px;
11 border: 0;
13 #rotatedFrame {
14 transform: rotate(180deg);
16 #scaledFrame {
17 transform: scale(2);
18 width: 50px;
19 height: 50px;
20 margin-left: 50px;
21 margin-bottom: 20px;
23 #container {
24 /* Want this at a stable place across platforms so the output co-ords are stable */
25 position: absolute;
26 top: 100px;
27 left: 10px;
29 #console {
30 margin-top: 200px;
32 </style>
33 <p id='description'></p>
34 <div id='container'>
35 <iframe id=simpleFrame src='resources/frame-touchevent-forwarder.html'></iframe>
36 <iframe id=rotatedFrame src='resources/frame-touchevent-forwarder.html'></iframe>
37 <iframe id=scaledFrame src='resources/frame-touchevent-forwarder.html'></iframe>
38 </div>
39 <div id='console'></div>
40 <div id='spacer'></div>
41 <script>
42 description('Tests non-integer TouchEvent co-ordinates and radii');
44 var scrollX = 3;
45 var scrollY = 10;
46 scrollTo(scrollX, scrollY);
48 eventCount = 0;
49 function onTouchStart(e) {
50 eventCount++;
51 lastEvent = e;
53 function expectEvent(eventName) {
54 shouldBeEqualToNumber('eventCount', 1);
55 var origEventCount = eventCount;
56 eventCount = 0;
57 if (origEventCount > 0) {
58 shouldBeEqualToString('lastEvent.type', eventName);
59 return true;
61 return false;
64 document.addEventListener('touchstart', onTouchStart);
65 var floatPrecision = 0.00001;
67 function runTest() {
68 if (!eventSender) {
69 debug('This test requires eventSender.');
70 return;
73 debug('Testing simple fractional touch');
74 eventSender.addTouchPoint(30.33, 4.5, 5.2, 6.3);
75 eventSender.touchStart();
76 if (expectEvent('touchstart')) {
77 shouldBeCloseTo('lastEvent.changedTouches[0].screenX', 30.33, floatPrecision);
78 shouldBeCloseTo('lastEvent.changedTouches[0].screenY', 4.5, floatPrecision);
79 shouldBeCloseTo('lastEvent.changedTouches[0].clientX', 30.33, floatPrecision);
80 shouldBeCloseTo('lastEvent.changedTouches[0].clientY', 4.5, floatPrecision);
81 shouldBeCloseTo('lastEvent.changedTouches[0].pageX', 30.33 + scrollX, floatPrecision);
82 shouldBeCloseTo('lastEvent.changedTouches[0].pageY', 4.5 + scrollY, floatPrecision);
83 shouldBeCloseTo('lastEvent.changedTouches[0].radiusX', 5.2, floatPrecision);
84 shouldBeCloseTo('lastEvent.changedTouches[0].radiusY', 6.3, floatPrecision);
86 eventSender.releaseTouchPoint(0);
87 eventSender.touchEnd();
88 debug('');
90 debug('Testing fractional touch inside simple iframe');
91 frameRect = document.getElementById('simpleFrame').getBoundingClientRect();
92 eventSender.addTouchPoint(frameRect.left + 4.5, frameRect.top + 2.2);
93 eventSender.touchStart();
94 if (expectEvent('touchstart')) {
95 shouldBeCloseTo('lastEvent.changedTouches[0].screenX', frameRect.left + 4.5, floatPrecision);
96 shouldBeCloseTo('lastEvent.changedTouches[0].screenY', frameRect.top + 2.2, floatPrecision);
97 shouldBeCloseTo('lastEvent.changedTouches[0].clientX', 4.5, floatPrecision);
98 shouldBeCloseTo('lastEvent.changedTouches[0].clientY', 2.2, floatPrecision);
99 shouldBeCloseTo('lastEvent.changedTouches[0].pageX', 4.5, floatPrecision);
100 shouldBeCloseTo('lastEvent.changedTouches[0].pageY', 2.2, floatPrecision);
102 eventSender.releaseTouchPoint(0);
103 eventSender.touchEnd();
104 debug('');
106 debug('Testing fractional touch inside rotated iframe');
107 frameRect = document.getElementById('rotatedFrame').getBoundingClientRect();
108 eventSender.addTouchPoint(frameRect.left + 4.5, frameRect.top + 2.2);
109 eventSender.touchStart();
110 if (expectEvent('touchstart')) {
111 shouldBeCloseTo('lastEvent.changedTouches[0].screenX', frameRect.left + 4.5, floatPrecision);
112 shouldBeCloseTo('lastEvent.changedTouches[0].screenY', frameRect.top + 2.2, floatPrecision);
113 shouldBeCloseTo('lastEvent.changedTouches[0].clientX', 100 - 4.5, floatPrecision);
114 shouldBeCloseTo('lastEvent.changedTouches[0].clientY', 100 - 2.2, floatPrecision);
115 shouldBeCloseTo('lastEvent.changedTouches[0].pageX', 100 - 4.5, floatPrecision);
116 shouldBeCloseTo('lastEvent.changedTouches[0].pageY', 100 - 2.2, floatPrecision);
118 eventSender.releaseTouchPoint(0);
119 eventSender.touchEnd();
120 debug('');
122 debug('Testing fractional touch inside scaled iframe');
123 frameRect = document.getElementById('scaledFrame').getBoundingClientRect();
124 eventSender.addTouchPoint(frameRect.left + 4.5, frameRect.top + 2.2);
125 eventSender.touchStart();
126 if (expectEvent('touchstart')) {
127 shouldBeCloseTo('lastEvent.changedTouches[0].screenX', frameRect.left + 4.5, floatPrecision);
128 shouldBeCloseTo('lastEvent.changedTouches[0].screenY', frameRect.top + 2.2, floatPrecision);
129 shouldBeCloseTo('lastEvent.changedTouches[0].clientX', 4.5 / 2, floatPrecision);
130 shouldBeCloseTo('lastEvent.changedTouches[0].clientY', 2.2 / 2, floatPrecision);
131 shouldBeCloseTo('lastEvent.changedTouches[0].pageX', 4.5 / 2, floatPrecision);
132 shouldBeCloseTo('lastEvent.changedTouches[0].pageY', 2.2 / 2, floatPrecision);
134 eventSender.releaseTouchPoint(0);
135 eventSender.touchEnd();
136 debug('');
139 addEventListener('load', runTest);
140 </script>