Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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; | |
| 7 } | |
| 8 #testArea { | |
| 9 height: 6000px; | |
| 10 width: 500px; | |
| 11 background: red; | |
| 12 } | |
| 13 #target { | |
| 14 position: fixed; | |
| 15 left: 10px; | |
| 16 top: 10px; | |
| 17 width: 40px; | |
| 18 height: 40px; | |
| 19 background: yellow; | |
| 20 } | |
| 21 </style> | |
| 22 <div id=testArea> | |
| 23 <div id=target></div> | |
| 24 </div> | |
| 25 <p id="description"></p> | |
| 26 <div id="console"></div> | |
| 27 <script src="../../resources/js-test.js"></script> | |
| 28 <script> | |
| 29 if (window.internals) { | |
| 30 window.internals.settings.setViewportEnabled(true); | |
| 31 window.internals.settings.setMockScrollbarsEnabled(true); | |
| 32 } | |
| 33 | |
| 34 description("Ensure hit test cache works in correct scenarios of scrolling, dom and style changes."); | |
| 35 | |
| 36 function hitTestCountDelta() | |
| 37 { | |
| 38 var lastCount = 0; | |
| 39 if ('lastHitTestCount' in document) | |
| 40 lastCount = document.lastHitTestCount; | |
| 41 var newCount = internals.hitTestCount(document); | |
| 42 document.lastHitTestCount = newCount; | |
| 43 return newCount - lastCount; | |
| 44 } | |
| 45 | |
| 46 function hitTestCacheHitsDelta() | |
| 47 { | |
| 48 var lastCount = 0; | |
| 49 if ('lastHitTestCacheHits' in document) | |
| 50 lastCount = document.lastHitTestCacheHits; | |
| 51 var newCount = internals.hitTestCacheHits(document); | |
| 52 document.lastHitTestCacheHits = newCount; | |
| 53 return newCount - lastCount; | |
| 54 } | |
| 55 | |
| 56 function clearCounts() | |
| 57 { | |
| 58 document.lastHitTestCount = internals.hitTestCount(document); | |
| 59 document.lastHitTestCacheHits = internals.hitTestCacheHits(document); | |
| 60 } | |
| 61 | |
| 62 function reportElementAt(x, y) | |
| 63 { | |
| 64 var element = document.elementFromPoint(x, y); | |
| 65 debug("Element is " + element.nodeName + ", " + element.id); | |
| 66 element = internals.elementFromPointNoCache(document, x, y); | |
| 67 debug("Element (no cache) is " + element.nodeName + ", " + element.id); | |
| 68 debug("Hit Test " + hitTestCountDelta() + "/" + hitTestCacheHitsDelta()); | |
| 69 } | |
| 70 | |
| 71 onload = function() { | |
| 72 clearCounts(); | |
| 73 debug('Hit test fixed div after scroll'); | |
|
Rick Byers
2015/06/05 20:48:58
please add at least one simple test case where the
dtapuska
2015/06/09 18:21:23
Done.
| |
| 74 debug('---------------------'); | |
| 75 | |
| 76 reportElementAt(12, 12); | |
| 77 reportElementAt(10, 60); | |
| 78 window.scrollTo(0, 50); | |
| 79 reportElementAt(12, 12); | |
| 80 | |
|
Rick Byers
2015/06/05 20:48:59
nit: debug('') here to make the output more readab
dtapuska
2015/06/09 18:21:23
Done.
| |
| 81 debug('Hit test after style change'); | |
| 82 debug('---------------------'); | |
| 83 reportElementAt(12, 12); | |
| 84 document.getElementById('target').style.background = "blue"; | |
| 85 reportElementAt(12, 12); | |
|
Rick Byers
2015/06/05 20:48:58
I'd prefer if the test code indicated what the exp
dtapuska
2015/06/09 18:21:23
Done.
| |
| 86 } | |
| 87 </script> | |
| OLD | NEW |