blob: 7b33699cb867d77fe171f4454455a9ffca9b26e1 [file] [log] [blame]
<body>
<p>Test Range.comparePoint and Range.isPointInRange Firefox extensions.</p>
<div id=log></div>
<script>
if (window.layoutTestController)
layoutTestController.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");
ra.detach();
shouldThrow("ra.comparePoint(document.createElement('b'), 0)", "INVALID_STATE_ERR");
shouldThrow("ra.comparePoint(document.body, 0)", "INVALID_STATE_ERR");
shouldThrow("ra.comparePoint(null, 0)", "INVALID_STATE_ERR");
shouldThrow("ra.isPointInRange(document.createElement('b'), 0)", "INVALID_STATE_ERR");
shouldThrow("ra.isPointInRange(document.body, 0)", "INVALID_STATE_ERR");
shouldThrow("ra.isPointInRange(null, 0)", "INVALID_STATE_ERR");
if (!hadError)
document.getElementById("log").innerHTML = "PASS";
</script>