OLD | NEW |
(Empty) | |
| 1 function listener() { |
| 2 } |
| 3 |
| 4 function log(msg) { |
| 5 var span = document.createElement("span"); |
| 6 document.getElementById("console").appendChild(span); |
| 7 span.innerHTML = msg + '<br />'; |
| 8 } |
| 9 |
| 10 function sortRects(a, b) { |
| 11 return a.layerRelativeRect.left - b.layerRelativeRect.left; |
| 12 } |
| 13 |
| 14 var preRunHandlerForTest = {}; |
| 15 |
| 16 function testElement(element) { |
| 17 element.addEventListener('touchstart', listener, false); |
| 18 |
| 19 // Run any test-specific handler AFTER adding the touch event listener |
| 20 // (which itself causes rects to be recomputed). |
| 21 if (element.id in preRunHandlerForTest) |
| 22 preRunHandlerForTest[element.id](element); |
| 23 |
| 24 logRects(element.id); |
| 25 element.removeEventListener('touchstart', listener, false); |
| 26 } |
| 27 |
| 28 function logRects(testName, opt_noOverlay) { |
| 29 if (!window.internals) { |
| 30 log(testName + ': not run'); |
| 31 return; |
| 32 } |
| 33 |
| 34 var rects = window.internals.touchEventTargetLayerRects(document); |
| 35 if (rects.length == 0) |
| 36 log(testName + ': no rects'); |
| 37 |
| 38 var sortedRects = new Array(); |
| 39 for ( var i = 0; i < rects.length; ++i) |
| 40 sortedRects[i] = rects[i]; |
| 41 sortedRects.sort(sortRects); |
| 42 for ( var i = 0; i < sortedRects.length; ++i) { |
| 43 var node = sortedRects[i].layerRootNode; |
| 44 var name = node.nodeName; |
| 45 if (node.id) |
| 46 name += '#' + node.id; |
| 47 var r = sortedRects[i].layerRelativeRect; |
| 48 log(testName + "[" + i + "]: " + name + " (" + r.left + ", " + r.top + "
, " + r.width + ", " + r.height + ")"); |
| 49 |
| 50 if (visualize && !opt_noOverlay && window.location.hash != '#nooverlay')
{ |
| 51 var patch = document.createElement("div"); |
| 52 patch.className = "overlay generated display-when-done"; |
| 53 patch.style.left = r.left + "px"; |
| 54 patch.style.top = r.top + "px"; |
| 55 patch.style.width = r.width + "px"; |
| 56 patch.style.height = r.height + "px"; |
| 57 |
| 58 if (node === document) { |
| 59 patch.style.position = "absolute"; |
| 60 document.body.appendChild(patch); |
| 61 } else { |
| 62 // Use a zero-size container to avoid changing the position of |
| 63 // the existing elements. |
| 64 var container = document.createElement("div"); |
| 65 container.className = "overlay-container generated"; |
| 66 patch.style.position = "relative"; |
| 67 node.appendChild(container); |
| 68 container.style.top = (node.offsetTop - container.offsetTop) + "
px"; |
| 69 container.style.left = (node.offsetLeft - container.offsetLeft)
+ "px"; |
| 70 container.classList.add("display-when-done"); |
| 71 container.appendChild(patch); |
| 72 } |
| 73 } |
| 74 } |
| 75 |
| 76 log(''); |
| 77 } |
| 78 |
| 79 function checkForRectUpdate(expectUpdate, operation) { |
| 80 if (window.internals) |
| 81 var oldCount = window.internals |
| 82 .touchEventTargetLayerRectsUpdateCount(document); |
| 83 |
| 84 operation(); |
| 85 |
| 86 if (window.internals) { |
| 87 var newCount = window.internals |
| 88 .touchEventTargetLayerRectsUpdateCount(document); |
| 89 if ((oldCount != newCount) != !!expectUpdate) |
| 90 log('FAIL: ' + (expectUpdate ? 'rects not updated' : 'rects updated
unexpectedly')); |
| 91 } |
| 92 } |
| 93 |
| 94 // Set this to true in order to visualize the results in an image. |
| 95 // Elements that are expected to be included in hit rects have a red border. |
| 96 // The actual hit rects are in a green tranlucent overlay. |
| 97 var visualize = false; |
| 98 |
| 99 if (window.testRunner) { |
| 100 window.testRunner.dumpAsText(visualize); |
| 101 document.documentElement.setAttribute('dumpRenderTree', 'true'); |
| 102 } else { |
| 103 // Note, this test can be run interactively in content-shell with |
| 104 // --expose-internals-for-testing. In that case we almost certainly |
| 105 // want to visualize the results. |
| 106 visualize = true; |
| 107 } |
| 108 |
| 109 if (window.internals) { |
| 110 window.internals.settings.setMockScrollbarsEnabled(true); |
| 111 window.internals.settings.setForceCompositingMode(true); |
| 112 } |
| 113 |
| 114 window.onload = function() { |
| 115 // Run each general test case. |
| 116 var tests = document.querySelectorAll('.testcase'); |
| 117 for ( var i = 0; i < tests.length; i++) |
| 118 testElement(tests[i]); |
| 119 |
| 120 if (window.additionalTests) |
| 121 additionalTests(); |
| 122 |
| 123 if (!visualize && window.internals) { |
| 124 var testContainer = document.getElementById("tests"); |
| 125 testContainer.parentNode.removeChild(testContainer); |
| 126 } |
| 127 |
| 128 document.documentElement.setAttribute('done', 'true'); |
| 129 }; |
OLD | NEW |