blob: 2a77fde77e86ac416741d2a6149d328720074355 [file] [log] [blame]
<html>
<head>
<script>
if (window.layoutTestController)
layoutTestController.dumpEditingCallbacks();
</script>
<script>
var x1, x2, y;
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function runTest() {
var elem = document.getElementById("test");
var selection = window.getSelection();
var anchorNode = selection.anchorNode;
var anchorOffset = selection.anchorOffset;
var focusNode = selection.focusNode;
var focusOffset = selection.focusOffset;
var anchorString = "Anchor (" + anchorNode + ", " + anchorOffset + ")";
var anchorCorrect = (anchorNode == elem || anchorNode == elem.firstChild) && anchorOffset == 0;
if (anchorCorrect)
log(anchorString + " is correct.");
else
throw(anchorString + " is incorrect.");
var focusString = "Focus (" + focusNode + ", " + focusOffset + ")";
var focusCorrect = (focusNode == elem && focusOffset == 1 || focusNode == elem.firstChild && focusOffset == elem.firstChild.length);
if (focusCorrect)
log(focusString + " is correct.");
else
throw(focusString + " is incorrect.");
}
function manualTest() {
try {
runTest();
} catch(e) {
log("Test Failed. Error was: " + e);
}
}
function automaticTest() {
try {
if (!window.layoutTestController)
throw("This test uses the layoutTestController's eventSender to do mouse clicks. To run it manually, from left to right, select 'text' in the box below, then click the 'Run Test' button.");
window.layoutTestController.dumpAsText();
var elem = document.getElementById("test");
// (x1, y) to (x2, y) should select the element.
// selects the text from left to right.
x1 = elem.offsetLeft;
x2 = elem.offsetLeft + elem.offsetWidth;
y = elem.offsetTop + elem.offsetHeight / 2;
eventSender.mouseMoveTo(x1, y);
eventSender.mouseDown();
eventSender.mouseMoveTo(x1, y);
eventSender.mouseMoveTo(x2, y);
eventSender.mouseUp();
runTest();
} catch(e) {
log("Test Failed. Error was: " + e);
}
}
</script>
</head>
<body>
<p>This tests the anchorNode, anchorOffset, focusNode and focusOffset properties of the Selection object. These properties are part of Mozilla's Selection object API, and so their values should be consistent in both browsers.</p>
<input type="button" onclick="manualTest();" value="Run Test">
<div style="border: 1px solid blue;" id="test">text</div>
<ul id="console"></ul>
<script>automaticTest();</script>
</body>
</html>