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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
XUL Widget Test for timepicker
-->
<window title="timepicker" width="500" height="600"
onload="setTimeout(testtag_timepicker, 0);"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<timepicker id="timepicker"/>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
function testtag_timepicker()
{
var tp = document.getElementById("timepicker");
var testid = "timepicker ";
var today = new Date();
var thour = today.getHours();
var tminute = today.getMinutes();
var tsecond = today.getSeconds();
// testtag_comparetime(tp, testid + "initial", thour, tminute, tsecond);
// check that setting the value property works
tp.value = testtag_gettimestring(thour, tminute, tsecond);
testtag_comparetime(tp, testid + "set value", thour, tminute, tsecond);
var numberOrder = /^(\D*)\s*(\d+)(\D*)(\d+)(\D*)(\d+)\s*(\D*)$/;
var locale = Intl.DateTimeFormat().resolvedOptions().locale + "-u-ca-gregory-nu-latn";
var fdt = new Date(2000,0,1,16,7,9).toLocaleTimeString(locale);
is(tp.is24HourClock, Number(fdt.match(numberOrder)[2]) > 12, "is24HourClock");
// check that setting the dateValue property works
tp.dateValue = today;
testtag_comparetime(tp, testid + "set dateValue", thour, tminute, tsecond);
ok(tp.value !== today, testid + " set dateValue different time");
ok(!tp.readOnly, testid + "readOnly");
tp.readOnly = true;
ok(tp.readOnly, testid + "set readOnly");
tp.readOnly = false;
ok(!tp.readOnly, testid + "clear readOnly");
function setTimeField(field, value, expectException,
expectedHour, expectedMinute, expectedSecond)
{
var exh = false;
try {
tp[field] = value;
} catch (ex) { exh = true; }
is(exh, expectException, testid + "set " + field + " " + value);
testtag_comparetime(tp, testid + "set " + field + " " + value,
expectedHour, expectedMinute, expectedSecond);
}
// check the value property
setTimeField("value", "0:0:0", false, 0, 0, 0);
setTimeField("value", "21:1:40", false, 21, 1, 40);
setTimeField("value", "7:11:8", false, 7, 11, 8);
setTimeField("value", "04:07:02", false, 4, 7, 2);
setTimeField("value", "10:42:20", false, 10, 42, 20);
// check that the hour, minute and second fields can be set properly
setTimeField("hour", 7, false, 7, 42, 20);
setTimeField("hour", 0, false, 0, 42, 20);
setTimeField("hour", 21, false, 21, 42, 20);
setTimeField("hour", -1, true, 21, 42, 20);
setTimeField("hour", 24, true, 21, 42, 20);
setTimeField("minute", 0, false, 21, 0, 20);
setTimeField("minute", 9, false, 21, 9, 20);
setTimeField("minute", 10, false, 21, 10, 20);
setTimeField("minute", 35, false, 21, 35, 20);
setTimeField("minute", -1, true, 21, 35, 20);
setTimeField("minute", 60, true, 21, 35, 20);
setTimeField("second", 0, false, 21, 35, 0);
setTimeField("second", 9, false, 21, 35, 9);
setTimeField("second", 10, false, 21, 35, 10);
setTimeField("second", 51, false, 21, 35, 51);
setTimeField("second", -1, true, 21, 35, 51);
setTimeField("second", 60, true, 21, 35, 51);
// check when seconds is not specified
setTimeField("value", "06:05", false, 6, 5, 0);
setTimeField("value", "06:15", false, 6, 15, 0);
setTimeField("value", "16:15", false, 16, 15, 0);
// check that times overflow properly
setTimeField("value", "5:65:21", false, 6, 5, 21);
setTimeField("value", "5:25:72", false, 5, 26, 12);
// check invalid values for the value and dateValue properties
tp.value = "14:25:48";
setTimeField("value", "", true, 14, 25, 48);
setTimeField("value", "1:5:6:6", true, 14, 25, 48);
setTimeField("value", "2:a:19", true, 14, 25, 48);
setTimeField("dateValue", "none", true, 14, 25, 48);
// check the fields
ok(tp.hourField instanceof HTMLInputElement, testid + "hourField");
ok(tp.minuteField instanceof HTMLInputElement, testid + "minuteField");
ok(tp.secondField instanceof HTMLInputElement, testid + "secondField");
testtag_timepicker_UI(tp, testid);
tp.readOnly = true;
// check that keyboard usage doesn't change the value when the timepicker
// is read only
testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
tp.hourField, 14, 25, 48, 14, 25, 48);
testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
tp.minuteField, 14, 25, 48, 14, 25, 48);
testtag_timepicker_UI_key(tp, testid + "readonly ", "14:25:48",
tp.secondField, 14, 25, 48, 14, 25, 48);
SimpleTest.finish();
}
function testtag_timepicker_UI(tp, testid)
{
testid += "UI";
// test adjusting the time with the up and down keys
testtag_timepicker_UI_key(tp, testid, "0:12:25", tp.hourField, 1, 12, 25, 0, 12, 25);
testtag_timepicker_UI_key(tp, testid, "11:12:25", tp.hourField, 12, 12, 25, 11, 12, 25);
testtag_timepicker_UI_key(tp, testid, "7:12:25", tp.hourField, 8, 12, 25, 7, 12, 25);
testtag_timepicker_UI_key(tp, testid, "16:12:25", tp.hourField, 17, 12, 25, 16, 12, 25);
testtag_timepicker_UI_key(tp, testid, "23:12:25", tp.hourField, 0, 12, 25, 23, 12, 25);
testtag_timepicker_UI_key(tp, testid, "15:23:46", tp.minuteField, 15, 24, 46, 15, 23, 46);
testtag_timepicker_UI_key(tp, testid, "15:0:46", tp.minuteField, 15, 1, 46, 15, 0, 46);
testtag_timepicker_UI_key(tp, testid, "15:59:46", tp.minuteField, 15, 0, 46, 15, 59, 46);
testtag_timepicker_UI_key(tp, testid, "11:50:46", tp.secondField, 11, 50, 47, 11, 50, 46);
testtag_timepicker_UI_key(tp, testid, "11:50:0", tp.secondField, 11, 50, 1, 11, 50, 0);
testtag_timepicker_UI_key(tp, testid, "11:50:59", tp.secondField, 11, 50, 0, 11, 50, 59);
}
function testtag_timepicker_UI_key(tp, testid, value, field,
uhour, uminute, usecond,
dhour, dminute, dsecond)
{
tp.value = value;
field.focus();
var eventTarget = tp.readOnly ? null : tp;
var testname = testid + " " + value + " key up";
synthesizeKeyExpectEvent("VK_UP", { }, eventTarget, "change", testname);
testtag_comparetime(tp, testname, uhour, uminute, usecond);
testname = testid + " " + value + " key down";
synthesizeKeyExpectEvent("VK_DOWN", { }, eventTarget, "change", testname);
testtag_comparetime(tp, testname, dhour, dminute, dsecond);
}
function testtag_gettimestring(hour, minute, second)
{
if (minute < 10)
minute = "0" + minute;
if (second < 10)
second = "0" + second;
return hour + ":" + minute + ":" + second;
}
function testtag_comparetime(tp, testid, hour, minute, second)
{
is(tp.value, testtag_gettimestring(hour, minute, second), testid + " value");
is(tp.getAttribute("value"),
testtag_gettimestring(hour, minute, second),
testid + " value attribute");
var dateValue = tp.dateValue;
ok(dateValue.getHours() == hour &&
dateValue.getMinutes() == minute &&
dateValue.getSeconds() == second,
testid + " dateValue");
is(tp.hour, hour, testid + " hour");
is(tp.minute, minute, testid + " minute");
is(tp.second, second, testid + " second");
}
]]>
</script>
</window>
|