<html>
<head>
<style>
#test {
width: 400px;
font-family: "Ahem";
}
</style>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var _log = "";
function log(msg)
{
_log += msg + "\n";
}
function swapInLog()
{
var element = document.getElementById('test');
var parent = element.parentNode;
parent.removeChild(element);
var console = document.createElement("pre");
console.textContent = _log;
parent.appendChild(console);
}
var element;
var image;
function test(x, y, __expectedContainer, __expectedOffset)
{
var expectedContainer = eval(__expectedContainer);
var expectedOffset = eval(__expectedOffset);
var range = document.caretRangeFromPoint(x, y);
if (range.startContainer == expectedContainer) {
log("PASS: range.startContainer == " + __expectedContainer + ".");
} else {
log("FAIL: range.startContainer == " + range.startContainer + ".");
}
if (range.startOffset == expectedOffset) {
log("PASS: range.startOffset == " + __expectedOffset + ".");
} else {
log("FAIL: range.startOffset == " + range.startOffset + ".");
}
}
window.onload = function()
{
element = document.getElementById('test');
image = document.getElementById('image');
var rect = element.getBoundingClientRect();
var imageRect = image.getBoundingClientRect();
log("Testing left of the image");
test(imageRect.left - 10, (imageRect.top + imageRect.height) - 5, "image.previousSibling", "34");
log("Testing right of the image");
test((imageRect.left + imageRect.width) + 10, (imageRect.top + imageRect.height) - 5, "image.nextSibling", "1");
log("Testing on the image");
test((imageRect.left + (imageRect.width / 2) + 1) , (imageRect.top + imageRect.height) - 5, "image.parentNode", "2");
swapInLog();
}
</script>
</head>
<body>
<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>
</body>
</html>