summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-keyboard-events.html
blob: 194dcad50b60f71c8b7663f20b8665fba946c25e (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<script src="../../js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<p>
Please run this with DumpRenderTree.
</p>
Test following keys:
<ul>
    <li>Digit keys</li>
    <li>Left/Right - Move focus field inside element</li>
    <li>Up/Down - Increment/decrement value of focus field</li>
    <li>Tab - Move focus field</li>
    <li>Backspace - Make value empty</li>
</ul>
<input id="before">
<input id="input" type="time">
<input id="another">
<div id="console"></div>
<script>
description("Multiple fields UI of time input type with keyboard events");
if (window.internals)
    internals.settings.setLangAttributeAwareFormControlUIEnabled(true);
var input = document.getElementById("input");

function keyDown(key, modifiers)
{
    if (!window.eventSender)
        return;
    eventSender.keyDown(key, modifiers);
}

function beginTest(title, value)
{
    debug("== " + title + " ==");
    input.value = value;
    input.blur();
    input.focus();
}

beginTest('Digit keys');
keyDown('7');
keyDown('5');
keyDown('6');
keyDown('A');
shouldBeEqualToString('input.value', '07:56');

// FIXME: We should test type ahead time out. When event.leapForward() affects
// keyboard event time stamp, we can uncomment this fragment.
/*
beginTest('Digit keys with type ahead timeout');
keyDown('1');
leapForward(1100);
keyDown('1');
keyDown('5');
keyDown('6');
keyDown('A');
shouldBeEqualToString('input.value', '01:56');
*/

beginTest('Left/Right keys', '01:24');
keyDown('rightArrow');
keyDown('5');
keyDown('leftArrow');
keyDown('6');
shouldBeEqualToString('input.value', '06:05');
keyDown('leftArrow');
keyDown('leftArrow');
keyDown('leftArrow');
shouldBeEqualToString('document.activeElement.id', 'input');

beginTest('Up/Down keys', '04:56');
keyDown('upArrow');
shouldBeEqualToString('input.value', '05:56');
keyDown('downArrow');
keyDown('downArrow');
shouldBeEqualToString('input.value', '03:56');

beginTest('Up/Down keys on empty value', '');
keyDown('upArrow');
keyDown('upArrow');
keyDown('rightArrow');
keyDown('downArrow');
keyDown('downArrow');
keyDown('rightArrow');
keyDown('downArrow');
shouldBeEqualToString('input.value', '14:58');

beginTest('Tab key', '03:00');
keyDown('\t');
keyDown('5');
shouldBeEqualToString('input.value', '03:05');
keyDown('\t', ['shiftKey']);
keyDown('7');
shouldBeEqualToString('input.value', '07:05');
keyDown('\t');
keyDown('\t');
shouldBeEqualToString('document.activeElement.id', 'another');

beginTest('Tab navigation should skip disabled/readonly inputs', '');
before.focus();
input.disabled = true;
keyDown('\t');
shouldBeEqualToString('document.activeElement.id', 'another');
input.disabled = false;

before.focus();
input.readOnly = true;
keyDown('\t');
shouldBeEqualToString('document.activeElement.id', 'another');
input.readOnly = false;

beginTest('Shfit+Tab key', '03:00');
another.focus();
keyDown('\t', ['shiftKey']);
keyDown('P');
shouldBeEqualToString('input.value', '15:00');
keyDown('\t', ['shiftKey']);
keyDown('3');
shouldBeEqualToString('input.value', '15:03');
keyDown('\t', ['shiftKey']);
keyDown('\t', ['shiftKey']);
shouldBeEqualToString('document.activeElement.id', 'before');

beginTest('Up key on maximum value', '12:59:59.999');
keyDown('upArrow');
keyDown('\t');
keyDown('upArrow');
keyDown('\t');
keyDown('upArrow');
keyDown('\t');
keyDown('upArrow');
shouldBeEqualToString('input.value', '13:00');

beginTest('Down key on minimum value', '01:00');
input.step = 0.001;
keyDown('downArrow');
keyDown('\t');
keyDown('downArrow');
keyDown('\t');
keyDown('downArrow');
keyDown('\t');
keyDown('downArrow');
shouldBeEqualToString('input.value', '00:59:59.999');
input.step = 60;

beginTest('Backspace key', '12:34');
keyDown("\b");
shouldBeEqualToString('input.value', '');

beginTest('Delete key', '12:34');
keyDown("delete");
shouldBeEqualToString('input.value', '');

beginTest('Typeahead', '12:34:56');
keyDown('rightArrow');
keyDown('1');
shouldBeEqualToString('input.value', '12:01:56');
keyDown('rightArrow');
keyDown('leftArrow');
keyDown('2');
shouldBeEqualToString('input.value', '12:02:56');

input.setAttribute("lang", "he-il");
beginTest('RTL focus navigation', '04:56');
debug('The tests in this block fail on platforms without the lang-attribute-aware-form-control-UI feature.');
keyDown('1'); //          -> [01]:56
shouldBeEqualToString('input.value', '01:56');
keyDown('\t'); //          -> 01:[56]
keyDown('2'); //          -> 01:[02]
shouldBeEqualToString('input.value', '01:02');
keyDown('\t', ['shiftKey']); // -> [01]:02
keyDown('3'); //          -> [03]:02
shouldBeEqualToString('input.value', '03:02');
input.removeAttribute("lang");
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>