<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
</head>
<body>
<p id="description">Tests to check behaviors of dirty flag and defaultValue change.</p>
<div id="console"></div>
<form id=form>
<textarea name=textarea id=textarea>
default
</textarea>
</form>

<script>
var form = document.getElementById('form');
var textarea = document.getElementById('textarea');

// Dirty by execCommand(), then setDefaultValue().
textarea.focus();
textarea.select();
shouldBe('document.execCommand("InsertText", false, "user-updated"); textarea.value', '"user-updated"');
shouldBe('textarea.defaultValue = "default 2"; textarea.value', '"user-updated"');
shouldBe('form.reset(); textarea.value', '"default 2"');
shouldBe('textarea.defaultValue = "default 3"; textarea.value', '"default 3"');

// Dirty by setValue(), then setDefaultValue().
shouldBe('textarea.value = "script-updated"; textarea.value', '"script-updated"');
shouldBe('textarea.defaultValue = "default 4"; textarea.value', '"script-updated"');
shouldBe('form.reset(); textarea.value', '"default 4"');

// Dirty by setValue(), then update defaultValue by innerHTML.
shouldBe('textarea.value = "script-updated"; textarea.value', '"script-updated"');
shouldBe('textarea.innerHTML = "default 5"; textarea.value', '"script-updated"');
shouldBe('form.reset(); textarea.value', '"default 5"');
shouldBe('textarea.innerHTML = "default 6"; textarea.value', '"default 6"');

// Dirty by setValue(), then update defaultValue by DOM tree operations.
shouldBe('textarea.value = "script-updated"; textarea.value', '"script-updated"');
shouldBe('textarea.removeChild(textarea.firstChild); textarea.appendChild(document.createTextNode("default 5")); textarea.value', '"script-updated"');
shouldBe('form.reset(); textarea.value', '"default 5"');
shouldBe('textarea.removeChild(textarea.firstChild); textarea.appendChild(document.createTextNode("default 6")); textarea.value', '"default 6"');
form.innerHTML = '';
</script>

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