2 <meta name=
"viewport" content=
"width=device-width, initial-scale=1, minimum-scale=1">
32 <iframe id=frame srcdoc='
<div id=
"innerContent" style=
"width: 75px; height: 50px; background: blue"><input></input<div>'
></iframe>
34 <p id=
"description"></p>
35 <div id=
"console"></div>
36 <script src=
"../../resources/js-test.js"></script>
39 setPrintTestResultsLazily();
40 if (window
.internals
) {
41 window
.internals
.settings
.setViewportEnabled(true);
42 window
.internals
.settings
.setMockScrollbarsEnabled(true);
45 description("Ensure hit test cache works in correct scenarios of scrolling, dom and style changes.");
47 function hitTestCountDelta()
50 if ('lastHitTestCount' in document
)
51 lastCount
= document
.lastHitTestCount
;
52 var newCount
= internals
.hitTestCount(document
);
53 document
.lastHitTestCount
= newCount
;
54 return newCount
- lastCount
;
57 function hitTestCacheHitsDelta()
60 if ('lastHitTestCacheHits' in document
)
61 lastCount
= document
.lastHitTestCacheHits
;
62 var newCount
= internals
.hitTestCacheHits(document
);
63 document
.lastHitTestCacheHits
= newCount
;
64 return newCount
- lastCount
;
67 function clearCounts()
69 internals
.clearHitTestCache(document
);
70 document
.lastHitTestCount
= internals
.hitTestCount(document
);
71 document
.lastHitTestCacheHits
= internals
.hitTestCacheHits(document
);
74 function checkElementAt(x
, y
, expectedHitTestCount
, expectedHitTestCacheCount
)
76 shouldBe("document.elementFromPoint(" + x
+ "," + y
+ ")",
77 "internals.clearHitTestCache(document); internals.elementFromPoint(document, " + x
+ ", " + y
+ ", false, false)");
78 shouldBeEqualToNumber("hitTestCountDelta()", expectedHitTestCount
);
79 shouldBeEqualToNumber("hitTestCacheHitsDelta()", expectedHitTestCacheCount
);
82 function checkChildFrameElementAt(x
, y
)
84 shouldBe("internals.elementFromPoint(document, " + x
+ ", " + y
+ ", false, true)",
85 "internals.clearHitTestCache(document); internals.elementFromPoint(document, " + x
+ ", " + y
+ ", false, true)");
90 debug('Hit test main div');
91 debug('---------------------');
93 // Verify that the cache is working; the second call
94 // to checkElementAt should end up using the cache from the first call.
95 checkElementAt(60, 60, 2, 0);
96 checkElementAt(60, 60, 2, 1);
99 debug('Hit test fixed div after scroll');
100 debug('---------------------');
102 // Verify that after scroll the hit cache isn't used but the
103 // correct element is returned for the fixed position elements.
104 document
.lastHitNode
= document
.elementFromPoint(12, 12);
106 checkElementAt(12, 12, 2, 0);
107 window
.scrollTo(0, 50);
108 checkElementAt(12, 12, 2, 0);
109 shouldBe("document.lastHitNode", "document.elementFromPoint(12, 12)");
112 debug('Hit test after main frame scroll');
113 debug('---------------------');
115 // Verify that after scroll the hit cache isn't used but
116 // the same element is returned for the adjusted co-ordinate.
117 window
.scrollTo(0, 0);
118 document
.lastHitNode
= document
.elementFromPoint(60, 75);
120 checkElementAt(60, 75, 2, 0);
121 window
.scrollTo(0, 50);
122 checkElementAt(60, 25, 2, 0);
123 shouldBe("document.lastHitNode", "document.elementFromPoint(60, 25)");
127 debug('Hit test after style change');
128 debug('---------------------');
129 checkElementAt(12, 12, 2, 0);
130 document
.getElementById('target').style
.background
= "blue";
131 checkElementAt(12, 12, 2, 0);
135 debug('Hit test after dom manipulation');
136 debug('---------------------');
137 checkElementAt(12, 12, 2, 0);
138 document
.getElementById('target').setAttribute("foo", "bar");
139 checkElementAt(12, 12, 2, 0);
142 document
.getElementById('target').style
.display
= "none";
143 window
.scrollTo(0, 0);
145 debug('Hit test iframe; ensuring child co-ordinates are not in parent cache');
146 debug('---------------------');
147 checkChildFrameElementAt(25, 80);
148 checkChildFrameElementAt(15, 40);