Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Test for Bug 1301306</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
<input type="time" id="input_time" onfocus="++focusEvents[0]"
onblur="++blurEvents[0]" onfocusin="++focusInEvents[0]"
onfocusout="++focusOutEvents[0]">
<input type="date" id="input_date" onfocus="++focusEvents[1]"
onblur="++blurEvents[1]" onfocusin="++focusInEvents[1]"
onfocusout="++focusOutEvents[1]">
<input type="datetime-local" id="input_datetime-local" onfocus="++focusEvents[2]"
onblur="++blurEvents[2]" onfocusin="++focusInEvents[2]"
onfocusout="++focusOutEvents[2]">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/**
* Test for Bug 1301306.
* This test checks that when moving inside the time input element, e.g. jumping
* through the inner text boxes, does not fire extra focus/blur events.
**/
var inputTypes = ["time", "date", "datetime-local"];
var focusEvents = [0, 0, 0];
var focusInEvents = [0, 0, 0];
var focusOutEvents = [0, 0, 0];
var blurEvents = [0, 0, 0];
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
test();
SimpleTest.finish();
});
function test() {
for (var i = 0; i < inputTypes.length; i++) {
var input = document.getElementById("input_" + inputTypes[i]);
input.focus();
is(focusEvents[i], 1, inputTypes[i] + " input element should have dispatched focus event.");
is(focusInEvents[i], 1, inputTypes[i] + " input element should have dispatched focusin event.");
is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
// Move around inside the input element's input box.
synthesizeKey("KEY_Tab");
is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
is(blurEvents[i], 0, inputTypes[i] + " time input element should not have dispatched blur event.");
synthesizeKey("KEY_ArrowRight");
is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
synthesizeKey("KEY_ArrowLeft");
is(focusEvents[i], 1,inputTypes[i] + " input element should not have dispatched focus event.");
is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
synthesizeKey("KEY_ArrowRight");
is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
is(focusOutEvents[i], 0, inputTypes[i] + " input element should not have dispatched focusout event.");
is(blurEvents[i], 0, inputTypes[i] + " input element should not have dispatched blur event.");
input.blur();
is(focusEvents[i], 1, inputTypes[i] + " input element should not have dispatched focus event.");
is(focusInEvents[i], 1, inputTypes[i] + " input element should not have dispatched focusin event.");
is(focusOutEvents[i], 1, inputTypes[i] + " input element should have dispatched focusout event.");
is(blurEvents[i], 1, inputTypes[i] + " input element should have dispatched blur event.");
}
}
</script>
</pre>
</body>
</html>