3 <script src=
"../../../../resources/ahem.js"></script>
11 if (window
.testRunner
)
12 testRunner
.dumpAsText();
22 var element
= document
.getElementById('test');
23 var parent
= element
.parentNode
;
24 parent
.removeChild(element
);
25 var console
= document
.createElement("pre");
26 console
.textContent
= _log
;
27 parent
.appendChild(console
);
32 function test(x
, y
, __expectedContainer
, __expectedOffset
)
34 var expectedContainer
= eval(__expectedContainer
);
35 var expectedOffset
= eval(__expectedOffset
);
37 var range
= document
.caretRangeFromPoint(x
, y
);
39 if (range
.startContainer
== expectedContainer
) {
40 log("PASS: range.startContainer == " + __expectedContainer
+ ".");
42 log("FAIL: range.startContainer == " + range
.startContainer
+ ".");
45 if (range
.startOffset
== expectedOffset
) {
46 log("PASS: range.startOffset == " + __expectedOffset
+ ".");
48 log("FAIL: range.startOffset == " + range
.startOffset
+ ".");
52 function shouldBeNull(x
, y
)
54 var range
= document
.caretRangeFromPoint(x
, y
);
57 log("PASS: range is null.");
59 log("FAIL: range is not null.");
63 window
.onload = function()
65 element
= document
.getElementById('test');
66 text
= element
.firstChild
;
68 var rect
= element
.getBoundingClientRect();
70 log("Testing upper left");
71 test(rect
.left
, rect
.top
, "element.firstChild", "0");
73 log("Testing upper right");
74 test(rect
.left
+ rect
.width
, rect
.top
, "element.firstChild", "23");
76 log("Testing lower left");
77 test(rect
.left
, rect
.top
+ rect
.height
- 1, "element.firstChild", "72");
79 log("Testing lower right");
80 test(rect
.left
+ rect
.width
, rect
.top
+ rect
.height
- 1, "element.firstChild", "95");
82 log("Testing somewhere in the middle");
83 test((rect
.left
+ rect
.width
) / 2, (rect
.top
+ rect
.height
) / 2, "element.firstChild", "36");
85 log("Testing negative values");
86 shouldBeNull(-10, 10);
87 shouldBeNull(10, -10);
88 shouldBeNull(-10, -10);
90 log("Testing values larger than the viewport");
91 shouldBeNull(window
.innerWidth
+ 100, 10);
92 shouldBeNull(10, window
.innerHeight
+ 100);
93 shouldBeNull(window
.innerWidth
+ 100, window
.innerHeight
+ 100);
100 <div id=
"test">xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx
</div>