blob: 421bbd3b68ac83de1e16021a9b8ef40429eba8a4 [file] [log] [blame]
<!DOCTYPE html>
<html>
<body>
<p>This test checks that typing Enter into an input element does not fire input or textInput.<br>
To run manually, type enter in the input element below.</p>
<form id="form">
<input id="el">
</form>
<br>
<div id="result"></div>
<pre id="console"></pre>
<script>
function log(msg) {
document.getElementById('console').appendChild(document.createTextNode(msg + '\n'));
}
var unexpectedEvents = 0;
var enterChar = '\r'.charCodeAt(0);
function fail(event) {
if (lastKeyPressed != enterChar) {
log(event.type + ' fired.');
return;
}
unexpectedEvents++;
log('Unexpected ' + event.type + ' fired.');
result.innerHTML = '<span style="padding: 5px; background-color: red">FAIL</span>';
}
var lastKeyPressed = 0;
el.addEventListener('keypress', function(event) { lastKeyPressed = event.keyCode; });
el.addEventListener('input', fail);
el.addEventListener('textInput', fail);
// If the form is submitted on enter and no unexpected event has been fired, success!
form.addEventListener('submit', function(event) {
if (!unexpectedEvents && !result.hasChildNodes())
result.innerHTML = '<span style="padding: 5px; background-color: green">SUCCESS</span>';
event.preventDefault();
});
if (window.testRunner)
testRunner.dumpAsText();
el.focus();
if (window.eventSender) {
log('\nSending Enter to input element');
eventSender.keyDown('\r', []);
} else if (window.testRunner)
log('This test requires eventSender to run in LayoutTests.');
</script>
</body>
</html>