<html>
<head>
<script src="../editing.js"></script>
</head>
<body>
<textarea id="test"></textarea>
<script src="../../resources/js-test-pre.js"></script>
<script>
description("The test verifies if the misspelled underline remains "
    + "when the caret is moved to the beginning, end and in middle of a word "
    + "that is marked as misspelled. The test succeeds if the word 'meagesga' "
    + "has red underline.");

jsTestIsAsync = true;

if (window.internals) {
    internals.settings.setUnifiedTextCheckerEnabled(true);
    internals.settings.setAsynchronousSpellCheckingEnabled(true);
}

document.getElementById('test').focus();
typeCharacterCommand('i');
typeCharacterCommand('t');
typeCharacterCommand('\'');
typeCharacterCommand('s');
typeCharacterCommand(' ');
typeCharacterCommand('a');
typeCharacterCommand(' ');
typeCharacterCommand('m');
typeCharacterCommand('e');
typeCharacterCommand('a');
typeCharacterCommand('g');
typeCharacterCommand('e');
typeCharacterCommand('s');
typeCharacterCommand('g');
typeCharacterCommand('a');
typeCharacterCommand(' ');

function checkSpellingMarkerAfterCaretChange(updateCaretPosition)
{
    updateCaretPosition();
    if (window.internals)
        shouldBecomeEqual("internals.hasSpellingMarker(7,8)", "true", done);
    else
        done();
}

var updateCaretTestCases = [
    function() { }, // doesn't change caret at all, just checks spelling after typing  meagesga ^
    function() { evalAndLog("execMoveSelectionBackwardByCharacterCommand()"); },    // meagesga^
    function() { evalAndLog("execMoveSelectionBackwardByWordCommand()"); },         // ^meagesga
    function() { evalAndLog("execMoveSelectionForwardByCharacterCommand()"); }      // m^eagesga
];

function done()
{
    var updateCaretPosition = updateCaretTestCases.shift();
    if (updateCaretPosition)
        return setTimeout(checkSpellingMarkerAfterCaretChange(updateCaretPosition), 0);

    finishJSTest();
}
done();
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
