Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Document / CaretRangeFromPoint / basic.html
blob117b31697dcb2a456fa774bf45cbb1dc5814e0a4
1 <html>
2 <head>
3 <script src="../../../../resources/ahem.js"></script>
4 <style>
5 #test {
6 width: 400px;
7 font-family: "Ahem";
9 </style>
10 <script>
11 if (window.testRunner)
12 testRunner.dumpAsText();
14 var _log = "";
15 function log(msg)
17 _log += msg + "\n";
20 function swapInLog()
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);
30 var element;
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 + ".");
41 } else {
42 log("FAIL: range.startContainer == " + range.startContainer + ".");
45 if (range.startOffset == expectedOffset) {
46 log("PASS: range.startOffset == " + __expectedOffset + ".");
47 } else {
48 log("FAIL: range.startOffset == " + range.startOffset + ".");
52 function shouldBeNull(x, y)
54 var range = document.caretRangeFromPoint(x, y);
56 if (range === null) {
57 log("PASS: range is null.");
58 } else {
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);
95 swapInLog();
97 </script>
98 </head>
99 <body>
100 <div id="test">xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx</div>
101 </body>
102 </html>