summaryrefslogtreecommitdiffstats
path: root/dom/html/test/forms/test_input_time_focus_blur_events.html
blob: 48374147749c73d6104822b8db61d142d03d6da7 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1301306
-->
<head>
<title>Test for Bug 1301306</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" 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="++focusEvent" onblur="++blurEvent"
       onfocusin="++focusInEvent" onfocusout="++focusOutEvent">
</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 focusEvent = 0;
var focusInEvent = 0;
var focusOutEvent = 0;
var blurEvent = 0;

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
  test();
  SimpleTest.finish();
});

function test() {
  var time = document.getElementById("input_time");
  time.focus();
  is(focusEvent, 1, "time input element should have dispatched focus event.");
  is(focusInEvent, 1, "time input element should have dispatched focusin event.");
  is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
  is(blurEvent, 0, "time input element should not have dispatched blur event.");

  // Move around inside the input element's input box.
  synthesizeKey("VK_TAB", {});
  is(focusEvent, 1, "time input element should not have dispatched focus event.");
  is(focusInEvent, 1, "time input element should have dispatched focusin event.");
  is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
  is(blurEvent, 0, "time input element should not have dispatched blur event.");

  synthesizeKey("VK_RIGHT", {});
  is(focusEvent, 1, "time input element should not have dispatched focus event.");
  is(focusInEvent, 1, "time input element should have dispatched focusin event.");
  is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
  is(blurEvent, 0, "time input element should not have dispatched blur event.");

  synthesizeKey("VK_LEFT", {});
  is(focusEvent, 1, "time input element should not have dispatched focus event.");
  is(focusInEvent, 1, "time input element should have dispatched focusin event.");
  is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
  is(blurEvent, 0, "time input element should not have dispatched blur event.");

  synthesizeKey("VK_RIGHT", {});
  is(focusEvent, 1, "time input element should not have dispatched focus event.");
  is(focusInEvent, 1, "time input element should have dispatched focusin event.");
  is(focusOutEvent, 0, "time input element should not have dispatched focusout event.");
  is(blurEvent, 0, "time input element should not have dispatched blur event.");

  time.blur();
  is(focusEvent, 1, "time input element should not have dispatched focus event.");
  is(focusInEvent, 1, "time input element should have dispatched focusin event.");
  is(focusOutEvent, 1, "time input element should not have dispatched focusout event.");
  is(blurEvent, 1, "time input element should have dispatched blur event.");
}

</script>
</pre>
</body>
</html>