blob: 80f7f5cbdcaea2182b60c49032f99b4c56950048 [file] [log] [blame]
<body>
<p>Test Range.comparePoint and Range.isPointInRange Firefox extensions.</p>
<div id=log></div>
<script>
if (window.testRunner)
testRunner.dumpAsText();
var hadError = false;
function logError(message)
{
document.getElementById("log").innerHTML += message + "<br>";
hadError = true;
}
function shouldThrow(expr, exceptionName)
{
try {
eval(expr);
logError('<code>' + expr + '</code> didn\'t raise an exception');
} catch (ex) {
if (ex.code != ex[exceptionName])
logError('<code>' + expr +'</code> raised a wrong exception: ' + ex.code + ' vs. ' + ex[exceptionName] + ' (' + exceptionName + ')');
}
}
function shouldBe(expr, expected)
{
try {
var actual = eval(expr);
if (actual != expected)
logError('<code>' + expr + '</code>: actual ' + actual + ", expected " + expected);
} catch (ex) {
logError('<code>' + expr +'</code> raised an exception: ' + ex);
}
}
var ra = document.createRange();
ra.selectNode(document.getElementsByTagName("p")[0]);
shouldThrow("ra.comparePoint(document.createElement('b'), 0)", "WRONG_DOCUMENT_ERR");
shouldThrow("ra.comparePoint(null, 0)", "HIERARCHY_REQUEST_ERR");
shouldBe("ra.comparePoint(document.body, 0)", -1);
shouldBe("ra.comparePoint(document.documentElement, 0)", -1);
shouldBe("ra.isPointInRange(document.createElement('b'), 0)", false);
shouldBe("ra.isPointInRange(document.documentElement, 0)", false);
shouldBe("ra.isPointInRange(document.body, 0)", false);
shouldThrow("ra.isPointInRange(null, 0)", "HIERARCHY_REQUEST_ERR");
if (!hadError)
document.getElementById("log").innerHTML = "PASS";
</script>