Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Document / CaretRangeFromPoint / replace-element.html
blob59b66445866d47f0abd045d5bb9128b3b23e97db
1 <html>
2 <head>
3 <style>
4 #test {
5 width: 400px;
6 font-family: "Ahem";
8 </style>
9 <script>
10 if (window.testRunner)
11 testRunner.dumpAsText();
13 var _log = "";
14 function log(msg)
16 _log += msg + "\n";
19 function swapInLog()
21 var element = document.getElementById('test');
22 var parent = element.parentNode;
23 parent.removeChild(element);
24 var console = document.createElement("pre");
25 console.textContent = _log;
26 parent.appendChild(console);
29 var element;
30 var image;
32 function test(x, y, __expectedContainer, __expectedOffset)
34 var expectedContainer = eval(__expectedContainer);
35 var expectedOffset = eval(__expectedOffset);
38 var range = document.caretRangeFromPoint(x, y);
40 if (range.startContainer == expectedContainer) {
41 log("PASS: range.startContainer == " + __expectedContainer + ".");
42 } else {
43 log("FAIL: range.startContainer == " + range.startContainer + ".");
47 if (range.startOffset == expectedOffset) {
48 log("PASS: range.startOffset == " + __expectedOffset + ".");
49 } else {
50 log("FAIL: range.startOffset == " + range.startOffset + ".");
54 window.onload = function()
56 element = document.getElementById('test');
57 image = document.getElementById('image');
59 var rect = element.getBoundingClientRect();
60 var imageRect = image.getBoundingClientRect();
62 log("Testing left of the image");
63 test(imageRect.left - 10, (imageRect.top + imageRect.height) - 5, "image.previousSibling", "34");
65 log("Testing right of the image");
66 test((imageRect.left + imageRect.width) + 10, (imageRect.top + imageRect.height) - 5, "image.nextSibling", "1");
68 log("Testing on the image");
69 test((imageRect.left + (imageRect.width / 2) + 1) , (imageRect.top + imageRect.height) - 5, "image.parentNode", "2");
71 swapInLog();
73 </script>
74 </head>
75 <body>
76 <div id="test">xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx<img id="image" src="../../resources/abe.png">xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx</div>
77 </body>
78 </html>