1 <div id=
"first" style=
"width: 4000px; height: 1000px">A long text to test document caretRangeFromPoint. Test scroll, zoom, zoomAndScroll .................................... The End
</div>
4 <script src=
"../../../../resources/js-test.js"></script>
6 function sendClick(x
, y
)
8 eventSender
.mouseMoveTo(x
, y
);
9 eventSender
.mouseDown();
10 eventSender
.mouseUp();
13 // 29 is the character offset in the div text "A long text to test document caretRangeFromPoint".
14 var expectedOffset
= 29;
17 function checkNodeAndOffsetFromCaretRangeFromPoint(message
, event
)
19 var range
= document
.caretRangeFromPoint(event
.clientX
, event
.clientY
);
22 offset
= range
.startOffset
;
24 alert("range is null");
28 var node
= document
.getElementById("first").firstChild
;
29 if (range
.startContainer
!= node
) {
30 testFailed(message
+ " node should be div's child text node");
33 if (offset
!= expectedOffset
) {
34 testFailed(message
+ " offset actual: " + offset
+ "; expected: " + expectedOffset
);
39 function checkBase(event
)
41 checkNodeAndOffsetFromCaretRangeFromPoint("check base", event
);
44 function checkScroll(event
)
46 checkNodeAndOffsetFromCaretRangeFromPoint("check scroll", event
);
49 function checkZoom(event
)
51 checkNodeAndOffsetFromCaretRangeFromPoint("check zoom", event
);
54 function checkZoomScroll(event
)
56 checkNodeAndOffsetFromCaretRangeFromPoint("check zoom and scroll", event
);
59 function scrollPage(x
, y
)
61 window
.scrollTo(x
, y
);
66 if (!window
.testRunner
)
69 testRunner
.dumpAsText();
71 var range
= document
.createRange();
72 var node
= document
.getElementById("first");
73 // Set range in the middle of word "document".
74 range
.setStart(node
.firstChild
, expectedOffset
);
75 range
.setEnd(node
.firstChild
, expectedOffset
+ 1);
78 window
.addEventListener("click", checkBase
, false);
79 rects
= range
.getClientRects();
80 var x
= rects
[0].left
;
81 var y
= rects
[0].top
+ rects
[0].width
/ 2;
83 window
.removeEventListener("click", checkBase
, false);
86 window
.addEventListener("click", checkScroll
, false);
90 window
.removeEventListener("click", checkScroll
, false);
93 window
.addEventListener("click", checkZoom
, false);
94 node
.style
.zoom
= 2.0;
95 rects
= range
.getClientRects();
96 var x
= rects
[0].left
;
97 var y
= rects
[0].top
+ rects
[0].width
/ 2;
99 window
.removeEventListener("click", checkZoom
, false);
101 // Test scroll and Zoom.
102 window
.addEventListener("click", checkZoomScroll
, false);
106 node
.style
.zoom
= 1.0;
107 window
.removeEventListener("click", checkZoomScroll
, false);
110 testPassed("Test completed successfully");