Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: LayoutTests/fast/events/touch/resources/compositor-touch-hit-rects.js

Issue 17471008: Rework compositor touch hit testing (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: CR feedback - accumulate LayoutRects instead of IntRects, disable when page isn't composited. Also… Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/events/touch/resources/compositor-touch-hit-rects.js
diff --git a/LayoutTests/fast/events/touch/resources/compositor-touch-hit-rects.js b/LayoutTests/fast/events/touch/resources/compositor-touch-hit-rects.js
new file mode 100644
index 0000000000000000000000000000000000000000..fd055edd2d877f351a40a0609284a3951e4bea7a
--- /dev/null
+++ b/LayoutTests/fast/events/touch/resources/compositor-touch-hit-rects.js
@@ -0,0 +1,129 @@
+function listener() {
+}
+
+function log(msg) {
+ var span = document.createElement("span");
+ document.getElementById("console").appendChild(span);
+ span.innerHTML = msg + '<br />';
+}
+
+function sortRects(a, b) {
+ return a.layerRelativeRect.left - b.layerRelativeRect.left;
+}
+
+var preRunHandlerForTest = {};
+
+function testElement(element) {
+ element.addEventListener('touchstart', listener, false);
+
+ // Run any test-specific handler AFTER adding the touch event listener
+ // (which itself causes rects to be recomputed).
+ if (element.id in preRunHandlerForTest)
+ preRunHandlerForTest[element.id](element);
+
+ logRects(element.id);
+ element.removeEventListener('touchstart', listener, false);
+}
+
+function logRects(testName, opt_noOverlay) {
+ if (!window.internals) {
+ log(testName + ': not run');
+ return;
+ }
+
+ var rects = window.internals.touchEventTargetLayerRects(document);
+ if (rects.length == 0)
+ log(testName + ': no rects');
+
+ var sortedRects = new Array();
+ for ( var i = 0; i < rects.length; ++i)
+ sortedRects[i] = rects[i];
+ sortedRects.sort(sortRects);
+ for ( var i = 0; i < sortedRects.length; ++i) {
+ var node = sortedRects[i].layerRootNode;
+ var name = node.nodeName;
+ if (node.id)
+ name += '#' + node.id;
+ var r = sortedRects[i].layerRelativeRect;
+ log(testName + "[" + i + "]: " + name + " (" + r.left + ", " + r.top + ", " + r.width + ", " + r.height + ")");
+
+ if (visualize && !opt_noOverlay && window.location.hash != '#nooverlay') {
+ var patch = document.createElement("div");
+ patch.className = "overlay generated display-when-done";
+ patch.style.left = r.left + "px";
+ patch.style.top = r.top + "px";
+ patch.style.width = r.width + "px";
+ patch.style.height = r.height + "px";
+
+ if (node === document) {
+ patch.style.position = "absolute";
+ document.body.appendChild(patch);
+ } else {
+ // Use a zero-size container to avoid changing the position of
+ // the existing elements.
+ var container = document.createElement("div");
+ container.className = "overlay-container generated";
+ patch.style.position = "relative";
+ node.appendChild(container);
+ container.style.top = (node.offsetTop - container.offsetTop) + "px";
+ container.style.left = (node.offsetLeft - container.offsetLeft) + "px";
+ container.classList.add("display-when-done");
+ container.appendChild(patch);
+ }
+ }
+ }
+
+ log('');
+}
+
+function checkForRectUpdate(expectUpdate, operation) {
+ if (window.internals)
+ var oldCount = window.internals
+ .touchEventTargetLayerRectsUpdateCount(document);
+
+ operation();
+
+ if (window.internals) {
+ var newCount = window.internals
+ .touchEventTargetLayerRectsUpdateCount(document);
+ if ((oldCount != newCount) != !!expectUpdate)
+ log('FAIL: ' + (expectUpdate ? 'rects not updated' : 'rects updated unexpectedly'));
+ }
+}
+
+// Set this to true in order to visualize the results in an image.
+// Elements that are expected to be included in hit rects have a red border.
+// The actual hit rects are in a green tranlucent overlay.
+var visualize = false;
+
+if (window.testRunner) {
+ window.testRunner.dumpAsText(visualize);
+ document.documentElement.setAttribute('dumpRenderTree', 'true');
+} else {
+ // Note, this test can be run interactively in content-shell with
+ // --expose-internals-for-testing. In that case we almost certainly
+ // want to visualize the results.
+ visualize = true;
+}
+
+if (window.internals) {
+ window.internals.settings.setMockScrollbarsEnabled(true);
+ window.internals.settings.setForceCompositingMode(true);
+}
+
+window.onload = function() {
+ // Run each general test case.
+ var tests = document.querySelectorAll('.testcase');
+ for ( var i = 0; i < tests.length; i++)
+ testElement(tests[i]);
+
+ if (window.additionalTests)
+ additionalTests();
+
+ if (!visualize && window.internals) {
+ var testContainer = document.getElementById("tests");
+ testContainer.parentNode.removeChild(testContainer);
+ }
+
+ document.documentElement.setAttribute('done', 'true');
+};

Powered by Google App Engine
This is Rietveld 408576698