<html>
<head>
<script src="../editing.js"></script>
</head>
<body>
<script src="../../resources/js-test-pre.js"></script>
<textarea id="testElement"></textarea>
<script type="text/javascript">
description('This test verifies if the misspelled word still remains spelling markers '
    + 'when user pressed the backspace key to move the caret at the end of the word or delete key to move '
    + 'the caret at the beginning of the word. '
    + 'This test succeeds when a word "meagesga" has red underline.');

jsTestIsAsync = true;

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

document.getElementById('testElement').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 checkSpellingMarker()
{
    if (window.internals)
        shouldBecomeEqual('internals.hasSpellingMarker(7, 8)', 'true', done);
}

function checkSpellingMarkerAfterDeleteCommand()
{
    evalAndLog('execDeleteCommand()');
    checkSpellingMarker();
}

function checkSpellingMarkerAfterForwardDelete()
{
    textarea = document.getElementById('testElement');
    textarea.setSelectionRange(6, 6);
    typeCharacterCommand(' ');
    evalAndLog('execForwardDeleteCommand()');

    checkSpellingMarker();
}

var tests = [
    function() { checkSpellingMarker(); },
    function() { checkSpellingMarkerAfterDeleteCommand(); },
    function() { checkSpellingMarkerAfterForwardDelete(); }
];

function done()
{
    var next = tests.shift();
    if (next)
        return window.setTimeout(next, 0);

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