| 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 setPrintTestResultsLazily(); | |
| 30 if (window.internals) { | |
| 31 window.internals.settings.setViewportEnabled(true); | |
| 32 window.internals.settings.setMockScrollbarsEnabled(true); | |
| 33 } | |
| 34 | |
| 35 description("Ensure hit test cache works in correct scenarios of scrolling, dom
and style changes."); | |
| 36 | |
| 37 function hitTestCountDelta() | |
| 38 { | |
| 39 var lastCount = 0; | |
| 40 if ('lastHitTestCount' in document) | |
| 41 lastCount = document.lastHitTestCount; | |
| 42 var newCount = internals.hitTestCount(document); | |
| 43 document.lastHitTestCount = newCount; | |
| 44 return newCount - lastCount; | |
| 45 } | |
| 46 | |
| 47 function hitTestCacheHitsDelta() | |
| 48 { | |
| 49 var lastCount = 0; | |
| 50 if ('lastHitTestCacheHits' in document) | |
| 51 lastCount = document.lastHitTestCacheHits; | |
| 52 var newCount = internals.hitTestCacheHits(document); | |
| 53 document.lastHitTestCacheHits = newCount; | |
| 54 return newCount - lastCount; | |
| 55 } | |
| 56 | |
| 57 function clearCounts() | |
| 58 { | |
| 59 internals.clearHitTestCache(document); | |
| 60 document.lastHitTestCount = internals.hitTestCount(document); | |
| 61 document.lastHitTestCacheHits = internals.hitTestCacheHits(document); | |
| 62 } | |
| 63 | |
| 64 function checkElementAt(x, y, expectedHitTestCount, expectedHitTestCacheCount) | |
| 65 { | |
| 66 shouldBe("document.elementFromPoint(" + x + "," + y + ")", | |
| 67 "internals.elementFromPointNoCache(document, " + x + ", " + y + ")"
); | |
| 68 shouldBeEqualToNumber("hitTestCountDelta()", expectedHitTestCount); | |
| 69 shouldBeEqualToNumber("hitTestCacheHitsDelta()", expectedHitTestCacheCount); | |
| 70 } | |
| 71 | |
| 72 onload = function() { | |
| 73 clearCounts(); | |
| 74 debug('Hit test main div'); | |
| 75 debug('---------------------'); | |
| 76 | |
| 77 // Verify that the cache is working; the second call | |
| 78 // to checkElementAt should end up using the cache from the first call. | |
| 79 checkElementAt(60, 60, 2, 0); | |
| 80 checkElementAt(60, 60, 2, 1); | |
| 81 | |
| 82 clearCounts(); | |
| 83 debug(''); | |
| 84 debug('Hit test fixed div after scroll'); | |
| 85 debug('---------------------'); | |
| 86 | |
| 87 // Verify that after we scroll an element the hit cache isn't used. | |
| 88 checkElementAt(12, 12, 2, 0); | |
| 89 checkElementAt(10, 60, 2, 0); | |
| 90 window.scrollTo(0, 50); | |
| 91 checkElementAt(12, 12, 2, 0); | |
| 92 | |
| 93 clearCounts(); | |
| 94 debug(''); | |
| 95 debug('Hit test after style change'); | |
| 96 debug('---------------------'); | |
| 97 checkElementAt(12, 12, 2, 0); | |
| 98 document.getElementById('target').style.background = "blue"; | |
| 99 checkElementAt(12, 12, 2, 0); | |
| 100 | |
| 101 clearCounts(); | |
| 102 debug(''); | |
| 103 debug('Hit test after dom manipulation'); | |
| 104 debug('---------------------'); | |
| 105 checkElementAt(12, 12, 2, 0); | |
| 106 document.getElementById('target').setAttribute("foo", "bar"); | |
| 107 checkElementAt(12, 12, 2, 0); | |
| 108 finishJSTest(); | |
| 109 } | |
| 110 </script> | |
| OLD | NEW |