<!DOCTYPE>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description">This test ensures WebKit returns correct values for HTMLInputElement.lastChangeWasUserEdit and
HTMLTextAreaElement.lastChangeWasUserEdit, which are exposed via WebKit API.</p>
<div id="console"></div>
<input type="text"><textarea></textarea>
<script>

if (!window.testRunner || !window.internals)
    testFailed('This test requires access to window.internals');

var textField;
function runTest(element) {
    debug((textField ? '\n' : '') + element.localName);

    textField = element;

    shouldBeFalse('internals.wasLastChangeUserEdit(textField)');
    shouldBeFalse('textField.value = "hello"; internals.wasLastChangeUserEdit(textField)');

    textField.focus();
    textField.selectionStart = textField.value.length;
    textField.selectionEnd = textField.selectionStart;
    shouldBeTrue('document.execCommand("InsertText", false, " world"); internals.wasLastChangeUserEdit(textField)');

    shouldBeTrue('textField.style.display = "none"; internals.wasLastChangeUserEdit(textField)');
    shouldBeFalse('textField.value = "WebKit"; internals.wasLastChangeUserEdit(textField)');
    shouldBeFalse('textField.style.display = null; internals.wasLastChangeUserEdit(textField)');

    textField.focus();
    shouldBeFalse('document.execCommand("SelectAll", false, null); internals.wasLastChangeUserEdit(textField)');
    shouldBeTrue('document.execCommand("Delete", false, null); internals.wasLastChangeUserEdit(textField)');

    if (textField.localName == 'textarea') {
        shouldBeFalse('textField.textContent = "hello\\nworld"; internals.wasLastChangeUserEdit(textField)');

        textField.focus();
        textField.selectionStart = textField.value.length;
        textField.selectionEnd = textField.selectionStart;
        shouldBeTrue('document.execCommand("InsertText", false, "\\nWebKit rocks"); internals.wasLastChangeUserEdit(textField)');

        shouldBeFalse('textField.innerText = " WebKit "; internals.wasLastChangeUserEdit(textField)');
    }

    textField.parentNode.removeChild(textField);
}

runTest(document.getElementsByTagName('input')[0]);
runTest(document.getElementsByTagName('textarea')[0]);

</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>
