summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_datetime_focus_blur_events.html
blob: 2e4e918119ff1845ef690c001df429fa778fc826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1301306
-->
<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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1301306">Mozilla Bug 722599</a>
<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>