1 <script src=
"../../../../resources/ahem.js"></script>
2 <script src=
"../../../../resources/js-test.js"></script>
11 outline:
1px solid black;
16 <div id=
"test-top" class=
"test">xxxxx xxxxx xxxxx xxxxx
</div>
17 <div class=
"pusher">This box is here to create scrollbars.
</div>
18 <div id=
"test-bottom" class=
"test" style=
"margin-left: 900px;">xxxxx xxxxx xxxxx xxxxx
</div>
19 <div class=
"pusher">This box is here to create additional space for the hit tests which must initially be in the scroll area.
</div>
22 <p id=
"description"></p>
23 <div id=
"console"></div>
26 if (window
.testRunner
)
27 testRunner
.dumpAsText();
29 description('This checks for proper behavior of caretRangeFromPoint before and after scrolling.');
31 var elementTop
= document
.getElementById('test-top'),
32 elementBottom
= document
.getElementById('test-bottom');
34 var BASE_DEVICE_PIXEL_RATIO
= window
.devicePixelRatio
;
36 function testsWithBaseline(baselinePos
, expectedContainer
) {
37 function test(expectedOffset
, scrollByX
, scrollByY
) {
38 var zoomRatio
= BASE_DEVICE_PIXEL_RATIO
/ window
.devicePixelRatio
;
39 var hitPosition
= { x
: 15 * zoomRatio
, y
: 15 * zoomRatio
},
41 doesContainerPass = function() { return range
.startContainer
=== expectedContainer
},
42 doesOffsetPass = function() { return Math
.abs(range
.startOffset
- expectedOffset
) < zoomRatio
; };
44 // Scroll relative to target.
45 scrollRelativeToBaseline(scrollByX
, scrollByY
);
47 range
= document
.caretRangeFromPoint(hitPosition
.x
, hitPosition
.y
);
49 // shouldn't return null range on any of these tests
51 testFailed("null range was returned from document.caretRangeFromPoint(" + hitPosition
.x
+ ", " + hitPosition
.y
+ ") at window scroll position " + window
.scrollX
+ "x" + window
.scrollY
);
56 function check(thunk
, message
) {
62 check(doesContainerPass
, "Range.startContainer check (got " + range
.startContainer
+ ", expected " + expectedContainer
+ ")");
63 check(doesOffsetPass
, "Range.startOffset check (got " + range
.startOffset
+ ", expected " + expectedOffset
+ ")");
66 function scrollRelativeToBaseline(x
, y
) {
67 window
.scrollTo(baselinePos
.x
+ x
, baselinePos
.y
+ y
);
78 var rectTop
= elementTop
.getBoundingClientRect(),
79 rectBottom
= elementBottom
.getBoundingClientRect(),
80 // Subtract some distance so we aren't in the very top left of the target.
81 topBaseline
= { x
: rectTop
.left
- 8, y
: rectTop
.top
- 8 },
82 bottomBaseline
= { x
: rectBottom
.left
- 8, y
: rectBottom
.top
- 8 };
84 // Testing inside initial containing block (top left)
85 testsWithBaseline(topBaseline
, elementTop
.firstChild
);
87 // Testing outside initial containing block (mid-page)
88 testsWithBaseline(bottomBaseline
, elementBottom
.firstChild
);
90 eventSender
.zoomPageOut();
91 testsWithBaseline(topBaseline
, elementTop
.firstChild
);
93 if (window
.testRunner
) {
94 var area
= document
.getElementById('testArea');
95 area
.parentNode
.removeChild(area
);