<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="../editing.js"></script>
<script src="../../resources/js-test-pre.js" type="text/javascript"></script>
</head>
<body style="font: 20px Ahem">
<p>This test checks that the cursor covers the next character to be overwritten in overtype mode instead of being painted as a caret (1px width bar)</p>
<div id="ltrtext" style="direction: ltr;" contenteditable="true">ABC</div>
<div id="ltrtext-rtl" style="direction: rtl;" contenteditable="true">ABC</div>
<div id="rtltext" style="direction: ltr;" contenteditable="true">&#x05e9;&#x05d3;&#x05df;</div>
<div id="rtltext-rtl" style="direction: rtl;" contenteditable="true">&#x05e9;&#x05d3;&#x05df;</div>
<div id="mixed" style="direction: ltr;" contenteditable="true">&#x05e9;&#x05d3;&#x05df;ABC</div>
<div id="mixed-rtl" style="direction: rtl;" contenteditable="true">&#x05e9;&#x05d3;&#x05df;ABC</div>
<div id="console"></div>
</body>
<script>

var blockCursorStartPosition;
var blockCursor;
var textNode;

function verifyBlockCursorLeftPositionAndWidth(elementId, expected)
{
    blockCursorStartPosition = new Array();

    var element = document.getElementById(elementId);
    textNode = element.firstChild;
    debug("Verifying block cursor position and width for each position in '" + textNode.nodeValue + "' in a " + element.style.direction + " block");

    for (var i = 0; i < textNode.length; i++) {
        evalAndLog("getSelection().collapse(textNode, "+i+")");

        blockCursor = internals.selectionBounds();
        blockCursorStartPosition.push(blockCursor.left);

        if (i > 0 && i < textNode.length) {
            if (expected[i-1] == ">")
                shouldBeTrue("blockCursorStartPosition["+(i-1)+"] > blockCursorStartPosition["+i+"]");
            else
                shouldBeTrue("blockCursorStartPosition["+(i-1)+"] < blockCursorStartPosition["+i+"]");
        }

        shouldBeTrue("getSelection().isCollapsed");
        shouldBeTrue("blockCursor.width > 1");
        shouldBe("internals.absoluteCaretBounds().width", "1");
    }

    evalAndLog("getSelection().collapse(textNode, "+i+")");
    blockCursor = internals.selectionBounds();
    shouldBeZero("blockCursor.width");
    shouldBe("internals.absoluteCaretBounds().width", "1");
    debug("");
}

if (window.testRunner) {

    internals.toggleOverwriteModeEnabled();

    verifyBlockCursorLeftPositionAndWidth("ltrtext", ["<", "<"]);
    verifyBlockCursorLeftPositionAndWidth("ltrtext-rtl", ["<", "<"]);
    verifyBlockCursorLeftPositionAndWidth("rtltext", [">", ">"]);
    verifyBlockCursorLeftPositionAndWidth("rtltext-rtl", [">", ">"]);
    verifyBlockCursorLeftPositionAndWidth("mixed", [">", ">", "<", "<", "<"]);
    verifyBlockCursorLeftPositionAndWidth("mixed-rtl", [">", ">", ">", "<", "<"]);
}
</script>
<script src="../../resources/js-test-post.js" type="text/javascript"></script>
</html>
