Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / hit-test-counts.html
blob5de7f6f67440c4cab3a4bdc1ed77430ca1d923e8
1 <!DOCTYPE html>
2 <meta name="viewport" content="width=device-width, initial-scale=1">
3 <style>
4 html {
5 font-family: Ahem;
6 font-size: 10px;
8 #testArea {
9 position: absolute;
10 right: 50px;
11 top: 50px;
13 #target {
14 width: 10px;
15 height: 10px;
17 #frame {
18 width: 100px;
19 height: 100px;
20 margin-top: 30px;
22 </style>
23 <div id=testArea>
24 <div id=target></div>
25 <iframe id=frame srcdoc='<iframe width=75 height=75></iframe>'></iframe>
26 </div>
27 <script src="../../resources/js-test.js"></script>
28 <script>
29 setPrintTestResultsLazily();
30 if (window.internals) {
31 window.internals.settings.setViewportEnabled(true);
32 window.internals.settings.setMockScrollbarsEnabled(true);
35 description("Count how many hit tests are required for various event scenarios. Hit tests can be expensive and it's often tempting to add more. These values should only ever be changed to go down, not up.");
37 function hitTestCountDelta(doc)
39 var lastCount = 0;
40 if ('lastHitTestCount' in doc)
41 lastCount = doc.lastHitTestCount;
42 var newCount = internals.hitTestCount(doc);
43 doc.lastHitTestCount = newCount;
44 return newCount - lastCount;
47 function hitTestCacheHitsDelta(doc)
49 var lastCount = 0;
50 if ('lastHitTestCacheHits' in doc)
51 lastCount = doc.lastHitTestCacheHits;
52 var newCount = internals.hitTestCacheHits(doc);
53 doc.lastHitTestCacheHits = newCount;
54 return newCount - lastCount;
57 function logCounts(label, documents, multiTapNotification, eventSenderFunction)
59 if (eventSenderFunction)
60 eventSenderFunction();
62 var countStr = '';
63 for(var i = 0; i < documents.length; i++) {
64 var hits = hitTestCountDelta(documents[i]);
65 var cacheHits = hitTestCacheHitsDelta(documents[i]);
66 countStr += ' ' + (hits - cacheHits) + "+" + cacheHits;
69 if (multiTapNotification) {
70 debug(label + ':' + eventCounts[label]
71 + ((countStr == eventCounts[label])? '': ' [with multiTargetTapNotification:' + countStr + ']'));
72 } else {
73 // store the count for later; to be compared when the
74 // multiTapNotification test is run.
75 eventCounts[label] = countStr;
79 function clearCounts(documents)
81 for(var i = 0; i < documents.length; i++) {
82 documents[i].lastHitTestCount = internals.hitTestCount(documents[i]);
83 documents[i].lastHitTestCacheHits = internals.hitTestCacheHits(documents[i]);
87 function sendEvents(targetX, targetY, documents, multiTapNotification)
89 logCounts('Initial', documents, multiTapNotification);
91 logCounts('MouseMove', documents, multiTapNotification, function() {
92 eventSender.mouseMoveTo(targetX, targetY);
93 });
95 logCounts('MouseDown', documents, multiTapNotification, function() {
96 eventSender.mouseDown();
97 });
99 logCounts('MouseUp', documents, multiTapNotification, function() {
100 eventSender.mouseUp();
103 logCounts('Wheel', documents, multiTapNotification, function() {
104 eventSender.mouseScrollBy(0, 5);
107 logCounts('TouchStart', documents, multiTapNotification, function() {
108 eventSender.addTouchPoint(targetX, targetY);
109 eventSender.touchStart();
112 logCounts('TouchMove', documents, multiTapNotification, function() {
113 eventSender.updateTouchPoint(0, targetX + 1, targetY);
114 eventSender.touchMove();
117 logCounts('TouchEnd', documents, multiTapNotification, function() {
118 eventSender.releaseTouchPoint(0);
119 eventSender.touchEnd();
121 logCounts('GestureTapDown', documents, multiTapNotification, function() {
122 eventSender.gestureTapDown(targetX, targetY, 30, 30);
125 logCounts('GestureShowPress', documents, multiTapNotification, function() {
126 eventSender.gestureShowPress(targetX, targetY, 30, 30);
129 logCounts('GestureTap', documents, multiTapNotification, function() {
130 eventSender.gestureTap(targetX, targetY, 1, 30, 30);
133 logCounts('GestureScrollBegin', documents, multiTapNotification, function() {
134 eventSender.gestureTapDown(targetX, targetY, 30, 30);
135 clearCounts(documents);
136 eventSender.gestureScrollBegin(targetX, targetY);
139 logCounts('GestureTapCancel', documents, multiTapNotification, function() {
140 eventSender.gestureTapCancel(targetX, targetY);
143 logCounts('GestureScrollUpdate', documents, multiTapNotification, function() {
144 eventSender.gestureScrollUpdate(0, 5);
147 logCounts('GestureScrollEnd', documents, multiTapNotification, function() {
148 eventSender.gestureScrollEnd(0, 5);
152 function runTestForDocuments(targetX, targetY, documents)
154 sendEvents(targetX, targetY, documents, false);
155 window.internals.settings.setMultiTargetTapNotificationEnabled(true);
156 for(var i = 0; i < documents.length; i++) {
157 internals.clearHitTestCache(documents[i]);
159 sendEvents(targetX, targetY, documents, true);
160 window.internals.settings.setMultiTargetTapNotificationEnabled(false);
163 function centerOf(element) {
164 var targetRect = element.getBoundingClientRect();
165 return {
166 x: targetRect.left + targetRect.width / 2,
167 y: targetRect.top + targetRect.height / 2
171 eventCounts = {};
172 onload = function() {
173 window.internals.settings.setMultiTargetTapNotificationEnabled(false);
175 debug('Event on a simple div');
176 debug('---------------------');
177 var point = centerOf(document.getElementById('target'));
178 runTestForDocuments(point.x, point.y, [document]);
179 debug('');
181 debug('Event entirely over one iframe nested in another');
182 debug('---------------------');
183 var frame = document.getElementById('frame');
184 var doc2 = frame.contentDocument;
185 var doc3 = doc2.querySelector('iframe').contentDocument;
186 var point = centerOf(frame);
187 runTestForDocuments(point.x, point.y, [document, doc2, doc3]);
188 debug('');
190 debug('Event near boundary of two iframes');
191 debug('---------------------');
192 var rect = frame.getBoundingClientRect();
193 runTestForDocuments(rect.left + 3, rect.top + 3, [document, doc2, doc3]);
194 debug('');
196 window.internals.settings.setViewportEnabled(false);
197 debug('Event on a simple div (desktop viewport)');
198 debug('---------------------');
199 var point = centerOf(document.getElementById('target'));
200 runTestForDocuments(point.x, point.y, [document]);
201 debug('');
202 window.internals.settings.setViewportEnabled(true);
203 finishJSTest();
205 </script>