Index: LayoutTests/fast/events/hit-test-cache.html |
diff --git a/LayoutTests/fast/events/hit-test-cache.html b/LayoutTests/fast/events/hit-test-cache.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9e907838fc86feeb06ac70ed4e9bd31c19b4eefc |
--- /dev/null |
+++ b/LayoutTests/fast/events/hit-test-cache.html |
@@ -0,0 +1,110 @@ |
+<!DOCTYPE html> |
+<meta name="viewport" content="width=device-width, initial-scale=1"> |
+<style> |
+html { |
+ font-family: Ahem; |
+ font-size: 10px; |
+} |
+#testArea { |
+ height: 6000px; |
+ width: 500px; |
+ background: red; |
+} |
+#target { |
+ position: fixed; |
+ left: 10px; |
+ top: 10px; |
+ width: 40px; |
+ height: 40px; |
+ background: yellow; |
+} |
+</style> |
+<div id=testArea> |
+ <div id=target></div> |
+</div> |
+<p id="description"></p> |
+<div id="console"></div> |
+<script src="../../resources/js-test.js"></script> |
+<script> |
+setPrintTestResultsLazily(); |
+if (window.internals) { |
+ window.internals.settings.setViewportEnabled(true); |
+ window.internals.settings.setMockScrollbarsEnabled(true); |
+} |
+ |
+description("Ensure hit test cache works in correct scenarios of scrolling, dom and style changes."); |
+ |
+function hitTestCountDelta() |
+{ |
+ var lastCount = 0; |
+ if ('lastHitTestCount' in document) |
+ lastCount = document.lastHitTestCount; |
+ var newCount = internals.hitTestCount(document); |
+ document.lastHitTestCount = newCount; |
+ return newCount - lastCount; |
+} |
+ |
+function hitTestCacheHitsDelta() |
+{ |
+ var lastCount = 0; |
+ if ('lastHitTestCacheHits' in document) |
+ lastCount = document.lastHitTestCacheHits; |
+ var newCount = internals.hitTestCacheHits(document); |
+ document.lastHitTestCacheHits = newCount; |
+ return newCount - lastCount; |
+} |
+ |
+function clearCounts() |
+{ |
+ internals.clearHitTestCache(document); |
+ document.lastHitTestCount = internals.hitTestCount(document); |
+ document.lastHitTestCacheHits = internals.hitTestCacheHits(document); |
+} |
+ |
+function checkElementAt(x, y, expectedHitTestCount, expectedHitTestCacheCount) |
+{ |
+ shouldBe("document.elementFromPoint(" + x + "," + y + ")", |
+ "internals.elementFromPointNoCache(document, " + x + ", " + y + ")"); |
+ shouldBeEqualToNumber("hitTestCountDelta()", expectedHitTestCount); |
+ shouldBeEqualToNumber("hitTestCacheHitsDelta()", expectedHitTestCacheCount); |
+} |
+ |
+onload = function() { |
+ clearCounts(); |
+ debug('Hit test main div'); |
+ debug('---------------------'); |
+ |
+ // Verify that the cache is working; the second call |
+ // to checkElementAt should end up using the cache from the first call. |
+ checkElementAt(60, 60, 2, 0); |
+ checkElementAt(60, 60, 2, 1); |
+ |
+ clearCounts(); |
+ debug(''); |
+ debug('Hit test fixed div after scroll'); |
+ debug('---------------------'); |
+ |
+ // Verify that after we scroll an element the hit cache isn't used. |
+ checkElementAt(12, 12, 2, 0); |
+ checkElementAt(10, 60, 2, 0); |
+ window.scrollTo(0, 50); |
+ checkElementAt(12, 12, 2, 0); |
+ |
+ clearCounts(); |
+ debug(''); |
+ debug('Hit test after style change'); |
+ debug('---------------------'); |
+ checkElementAt(12, 12, 2, 0); |
+ document.getElementById('target').style.background = "blue"; |
+ checkElementAt(12, 12, 2, 0); |
+ |
+ clearCounts(); |
+ debug(''); |
+ debug('Hit test after dom manipulation'); |
+ debug('---------------------'); |
+ checkElementAt(12, 12, 2, 0); |
+ document.getElementById('target').setAttribute("foo", "bar"); |
+ checkElementAt(12, 12, 2, 0); |
+ finishJSTest(); |
+} |
+</script> |