Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(684)

Unified Diff: third_party/WebKit/LayoutTests/fast/events/onchange-js.html

Issue 2467263002: INPUT/TEXTAREA elements: Dispatch 'change' event even if a user-edit value is overwritten by JS (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/events/onchange-js-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/fast/events/onchange-js.html
diff --git a/third_party/WebKit/LayoutTests/fast/events/onchange-js.html b/third_party/WebKit/LayoutTests/fast/events/onchange-js.html
index 1478587220a750e33c13271009d309143a6e1db6..72110fc39c3c9e54a7bf633177975a605cec9208 100644
--- a/third_party/WebKit/LayoutTests/fast/events/onchange-js.html
+++ b/third_party/WebKit/LayoutTests/fast/events/onchange-js.html
@@ -4,29 +4,79 @@
<script src="../../resources/js-test.js"></script>
</head>
<body>
+<div id=container>
<input id="input" type="text" onchange="changeHandler()">
+<input id="number" type="number" onchange="changeHandler()">
+<textarea id="textarea" onchange="changeHandler()"></textarea>
+</div>
<script>
-description('This test verifies that the change event is fired, when value is changed in change event handler.');
-var input = document.getElementById('input');
+description('This test verifies that the change event is fired, when value is changed by JavaScript code.');
var changeEventCounter = 0;
+// shouldBe*() can refer to only global variables.
+var element;
function changeHandler()
{
changeEventCounter++;
- input.value = '';
+ element.value = '';
}
-input.focus();
-document.execCommand('InsertText', false, 'foo bar baz');
-shouldBeEqualToString('input.value', 'foo bar baz');
-input.blur();
-shouldBe('changeEventCounter', '1');
-shouldBeEqualToString('input.value', '');
-
-input.focus();
-document.execCommand('InsertText', false, 'foo bar baz');
-shouldBeEqualToString('input.value', 'foo bar baz');
-input.blur();
-shouldBe('changeEventCounter', '2');
+function testValueUpdateOnChange(userInput) {
+ debug('Value is updated in change event handler.');
+ changeEventCounter = 0;
+ element.focus();
+ document.execCommand('InsertText', false, userInput);
+ shouldBeEqualToString('element.value', userInput);
+ element.blur();
+ shouldBe('changeEventCounter', '1');
+ shouldBeEqualToString('element.value', '');
+
+ element.focus();
+ document.execCommand('InsertText', false, userInput);
+ shouldBeEqualToString('element.value', userInput);
+ element.blur();
+ shouldBe('changeEventCounter', '2');
+}
+
+function testValueUpdateWithoutUserEdit(jsInput) {
+ debug('Value is updated while element is focused.');
+ changeEventCounter = 0;
+ element.value = '';
+ element.focus();
+ element.value = jsInput;
+ element.blur();
+ shouldBe('changeEventCounter', '0');
+}
+
+function testValueUpdateAfterUserEdit(userInput, jsInput) {
+ debug('Value is updated after a user edit.');
+ changeEventCounter = 0;
+ element.value = '0';
+ element.focus();
+ document.execCommand('InsertText', false, userInput);
+ element.value = jsInput;
+ element.blur();
+ shouldBe('changeEventCounter', '1');
+}
+
+debug('===> Tests for INPUT[type=text]');
+element = document.getElementById('input');
+testValueUpdateOnChange('foo bar');
+testValueUpdateWithoutUserEdit('FOO BAR');
+testValueUpdateAfterUserEdit('foo bar', 'FOO BAR');
+
+debug('===> Tests for INPUT[type=number]');
+element = document.getElementById('number');
+testValueUpdateOnChange('123');
+testValueUpdateWithoutUserEdit('999');
+testValueUpdateAfterUserEdit('123', '999');
+
+debug('===> Tests for TEXTAREA');
+element = document.getElementById('textarea');
+testValueUpdateOnChange('foo bar');
+testValueUpdateWithoutUserEdit('FOO BAR');
+testValueUpdateAfterUserEdit('foo bar', 'FOO BAR');
+
+document.querySelector('#container').remove();
</script>
</body>
</html>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/fast/events/onchange-js-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698