2010-12-13 Dai Mikurube <dmikurube@google.com>
[WebKit.git] / LayoutTests / fast / forms / script-tests / ValidityState-stepMismatch.js
1 description('Check stepMismatch results for type=date, datetime, datetime-local, month, time, week.');
2
3 var input = document.createElement('input');
4 document.body.appendChild(input);
5
6 function stepMismatchFor(value, step, min, disabled) {
7     input.min = min;
8     input.step = step;
9     input.value = value;
10     input.disabled = !!disabled;
11     return input.validity.stepMismatch;
12 }
13
14 debug('Date type');
15 input.type = 'date';
16 debug('Empty values');
17 shouldBeFalse('stepMismatchFor("", null, null)');
18 shouldBeFalse('stepMismatchFor("", "2", "1969-12-31")');
19 debug('Normal step values');
20 shouldBeTrue('stepMismatchFor("2010-02-10", "2", "2010-02-09")');
21 shouldBeFalse('stepMismatchFor("2010-02-09", "2", "2010-02-09")');
22 shouldBeFalse('stepMismatchFor("2010-02-11", "2", "2010-02-09")');
23 shouldBeTrue('stepMismatchFor("1800-11-11", "3", "1800-11-09")');
24 shouldBeFalse('stepMismatchFor("1800-11-09", "3", "1800-11-09")');
25 shouldBeFalse('stepMismatchFor("1800-11-12", "3", "1800-11-09")');
26 shouldBeTrue('stepMismatchFor("275760-09-13", "3", "275760-09-11")');
27 shouldBeFalse('stepMismatchFor("275760-09-13", "2", "275760-09-11")');
28 debug('Implicit step base');
29 shouldBeTrue('stepMismatchFor("1970-01-02", "2", null)');
30 shouldBeFalse('stepMismatchFor("1970-01-03", "2", null)');
31 debug('Fractional step values');
32 shouldBeFalse('stepMismatchFor("2010-02-10", "0.1", "2010-02-09")');
33 shouldBeFalse('stepMismatchFor("2010-02-10", "1.1", "2010-02-09")');
34 shouldBeTrue('stepMismatchFor("2010-02-10", "1.9", "2010-02-09")');
35 debug('Invalid or no step values');
36 shouldBeFalse('stepMismatchFor("2010-02-10", null, "2010-02-09")');
37 shouldBeFalse('stepMismatchFor("2010-02-10", "-1", "2010-02-09")');
38 shouldBeFalse('stepMismatchFor("2010-02-10", "foo", "2010-02-09")');
39 debug('Special step value');
40 shouldBeFalse('stepMismatchFor("2010-02-10", "any", "2010-02-09")');
41 debug('Disabled');
42 shouldBeFalse('stepMismatchFor("2010-02-10", "2", "2010-02-09", true)');
43
44 debug('');
45 debug('Datetime type');
46 input.type = 'datetime';
47 debug('Empty values');
48 shouldBeFalse('stepMismatchFor("", null, null)');
49 shouldBeFalse('stepMismatchFor("", "2", "1969-12-31T12:34:56Z")');
50 debug('Normal step values');
51 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55Z", "1", "2010-02-09T12:34:56Z")');
52 shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55.001Z", "1", "2010-02-09T12:34:56Z")');
53 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:56.001Z", "0.001", "2010-02-09T12:34:56Z")');
54 shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55Z", "0.333", "2010-02-09T12:34:56Z")');
55 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55.001Z", "0.333", "2010-02-09T12:34:56Z")');
56 shouldBeFalse('stepMismatchFor("2010-02-09T12:34Z", "86400", "2010-02-08T12:34Z")');
57 shouldBeTrue('stepMismatchFor("2010-02-09T12:34:56Z", "86400", "2010-02-08T12:34Z")');
58 shouldBeTrue('stepMismatchFor("275760-09-13T00:00Z", "3", "275760-09-12T23:59:50Z")');
59 shouldBeFalse('stepMismatchFor("275760-09-13T00:00Z", "2", "275760-09-12T23:59:50Z")');
60 shouldBeTrue('stepMismatchFor("0001-01-01T00:00Z", "3", "0001-01-11T00:00:02Z")');
61 shouldBeFalse('stepMismatchFor("0001-01-01T00:00Z", "2", "0001-01-11T00:00:02Z")');
62 debug('Implicit step base');
63 shouldBeFalse('stepMismatchFor("1970-01-01T12:34Z", "120", null)');
64 shouldBeTrue('stepMismatchFor("1970-01-01T12:35Z", "120", null)');
65 debug('Small step values');
66 shouldBeFalse('stepMismatchFor("2010-02-10T12:34:56.000Z", "0.0003", "2010-02-10T12:34.55.000Z")');
67 shouldBeTrue('stepMismatchFor("2010-02-10T12:34:55.001Z", "0.0019", "2010-02-10T12:34.55.000Z")');
68 debug('Invalid or no step values');
69 shouldBeFalse('stepMismatchFor("2010-02-10T12:34Z", null, "2010-02-09T12:34Z")');
70 shouldBeTrue('stepMismatchFor("2010-02-10T12:34:56Z", null, "2010-02-09T12:34Z")');
71 shouldBeFalse('stepMismatchFor("2010-02-10T12:34Z", "-1", "2010-02-09T12:34Z")');
72 shouldBeFalse('stepMismatchFor("2010-02-10T12:34Z", "foo", "2010-02-09T12:34Z")');
73 debug('Special step value');
74 shouldBeFalse('stepMismatchFor("2010-02-09T12:34Z", "any", "2010-02-09T12:34Z")');
75 debug('Disabled');
76 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55.001Z", "1", "2010-02-09T12:34:56Z", true)');
77
78 debug('');
79 debug('Datetime-local type');
80 input.type = 'datetime-local';
81 debug('Empty values');
82 shouldBeFalse('stepMismatchFor("", null, null)');
83 shouldBeFalse('stepMismatchFor("", "2", "1969-12-31T12:34:56")');
84 debug('Normal step values');
85 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55", "1", "2010-02-09T12:34:56")');
86 shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55.001", "1", "2010-02-09T12:34:56")');
87 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:56.001", "0.001", "2010-02-09T12:34:56")');
88 shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55", "0.333", "2010-02-09T12:34:56")');
89 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55.001", "0.333", "2010-02-09T12:34:56")');
90 shouldBeFalse('stepMismatchFor("2010-02-09T12:34", "86400", "2010-02-08T12:34")');
91 shouldBeTrue('stepMismatchFor("2010-02-09T12:34:56", "86400", "2010-02-08T12:34")');
92 shouldBeTrue('stepMismatchFor("275760-09-13T00:00", "3", "275760-09-12T23:59:50")');
93 shouldBeFalse('stepMismatchFor("275760-09-13T00:00", "2", "275760-09-12T23:59:50")');
94 shouldBeTrue('stepMismatchFor("0001-01-01T00:00", "3", "0001-01-11T00:00:02")');
95 shouldBeFalse('stepMismatchFor("0001-01-01T00:00", "2", "0001-01-11T00:00:02")');
96 debug('Implicit step base');
97 shouldBeFalse('stepMismatchFor("1970-01-01T12:34", "120", null)');
98 shouldBeTrue('stepMismatchFor("1970-01-01T12:35", "120", null)');
99 debug('Small step values');
100 shouldBeFalse('stepMismatchFor("2010-02-10T12:34:56.000", "0.0003", "2010-02-10T12:34.55.000")');
101 shouldBeTrue('stepMismatchFor("2010-02-10T12:34:55.001", "0.0019", "2010-02-10T12:34.55.000")');
102 debug('Invalid or no step values');
103 shouldBeFalse('stepMismatchFor("2010-02-10T12:34", null, "2010-02-09T12:34")');
104 shouldBeTrue('stepMismatchFor("2010-02-10T12:34:56", null, "2010-02-09T12:34")');
105 shouldBeFalse('stepMismatchFor("2010-02-10T12:34", "-1", "2010-02-09T12:34")');
106 shouldBeFalse('stepMismatchFor("2010-02-10T12:34", "foo", "2010-02-09T12:34")');
107 debug('Special step value');
108 shouldBeFalse('stepMismatchFor("2010-02-09T12:34", "any", "2010-02-09T12:34")');
109 debug('Disabled');
110 shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55.001", "1", "2010-02-09T12:34:56", true)');
111
112 debug('');
113 debug('Month type');
114 input.type = 'month';
115 debug('Empty values');
116 shouldBeFalse('stepMismatchFor("", null, null)');
117 shouldBeFalse('stepMismatchFor("", "2", "1969-12")');
118 debug('Normal step values');
119 shouldBeTrue('stepMismatchFor("2010-03", "2", "2010-02")');
120 shouldBeFalse('stepMismatchFor("2010-02", "2", "2010-02")');
121 shouldBeFalse('stepMismatchFor("2010-04", "2", "2010-02")');
122 shouldBeTrue('stepMismatchFor("1800-11", "3", "1800-09")');
123 shouldBeFalse('stepMismatchFor("1800-09", "3", "1800-09")');
124 shouldBeFalse('stepMismatchFor("1800-12", "3", "1800-09")');
125 shouldBeTrue('stepMismatchFor("275760-09", "3", "275760-08")');
126 shouldBeFalse('stepMismatchFor("275760-09", "2", "275760-09")');
127 debug('Implicit step base');
128 shouldBeTrue('stepMismatchFor("1970-02", "2", null)');
129 shouldBeFalse('stepMismatchFor("1970-03", "2", null)');
130 debug('Fractional step values');
131 shouldBeFalse('stepMismatchFor("2010-03", "0.1", "2010-02")');
132 shouldBeFalse('stepMismatchFor("2010-03", "1.1", "2010-02")');
133 shouldBeTrue('stepMismatchFor("2010-03", "1.9", "2010-02")');
134 debug('Invalid or no step values');
135 shouldBeFalse('stepMismatchFor("2010-03", null, "2010-02")');
136 shouldBeFalse('stepMismatchFor("2010-03", "-1", "2010-02")');
137 shouldBeFalse('stepMismatchFor("2010-03", "foo", "2010-02")');
138 debug('Special step value');
139 shouldBeFalse('stepMismatchFor("2010-03", "any", "2010-02")');
140 debug('Disabled');
141 shouldBeFalse('stepMismatchFor("2010-03", "2", "2010-02", true)');
142
143 debug('');
144 debug('Number type');
145 input.type = 'number';
146 debug('Empty values');
147 shouldBe('stepMismatchFor("", null, null)', 'false');
148 shouldBe('stepMismatchFor("", "1.0", "0.1")', 'false');
149 debug('Integers');
150 shouldBe('stepMismatchFor("1", "2", "0")', 'true');
151 shouldBe('stepMismatchFor("-3", "2", "-4")', 'true');
152 shouldBe('input.max = "5"; stepMismatchFor("5", "3", "0")', 'true');
153 shouldBe('input.value', '"5"');
154 debug('Invalid step values');
155 input.max = '';
156 shouldBe('stepMismatchFor("-3", "-2", "-4")', 'false');
157 shouldBe('stepMismatchFor("-3", null, "-4")', 'false');
158 shouldBe('stepMismatchFor("-3", undefined, "-4")', 'false');
159 debug('Huge numbers and small step; uncomparable');
160 shouldBe('stepMismatchFor("3.40282347e+38", "3", "")', 'false');
161 shouldBe('stepMismatchFor("3.40282346e+38", "3", "")', 'false');
162 shouldBe('stepMismatchFor("3.40282345e+38", "3", "")', 'false');
163 debug('Huge numbers and huge step');
164 shouldBe('stepMismatchFor("3.20e+38", "0.20e+38", "")', 'false');
165 shouldBe('stepMismatchFor("3.20e+38", "0.22e+38", "")', 'true');
166 debug('Fractional numbers');
167 shouldBe('stepMismatchFor("0.9", "0.1", "")', 'false');
168 shouldBe('stepMismatchFor("0.9", "0.1000001", "")', 'true');
169 shouldBe('stepMismatchFor("0.9", "0.1000000000000001", "")', 'false');
170 shouldBe('stepMismatchFor("1.0", "0.3333333333333333", "")', 'false');
171 debug('Rounding');
172 shouldBe('stepMismatchFor("5.005", "0.005", "4")', 'false');
173 debug('Disabled');
174 shouldBe('stepMismatchFor("1", "2", "0", true)', 'false');
175
176 debug('');
177 debug('Range type');
178 input.type = 'range';
179 // The following test inputs are the same as inputs for type=numbe,
180 // but all expected results should be 'false'.
181 debug('Empty values');
182 shouldBe('stepMismatchFor("", null, null)', 'false');
183 shouldBe('stepMismatchFor("", "1.0", "0.1")', 'false');
184 debug('Integers');
185 shouldBe('stepMismatchFor("1", "2", "0")', 'false');
186 shouldBe('stepMismatchFor("-3", "2", "-4")', 'false');
187 shouldBe('input.max = "5"; stepMismatchFor("5", "3", "0")', 'false');
188 shouldBe('input.value', '"3"'); // Different from type=number.
189 debug('Invalid step values');
190 input.max = '';
191 shouldBe('stepMismatchFor("-3", "-2", "-4")', 'false');
192 shouldBe('stepMismatchFor("-3", null, "-4")', 'false');
193 shouldBe('stepMismatchFor("-3", undefined, "-4")', 'false');
194 debug('Huge numbers and small step; uncomparable');
195 shouldBe('stepMismatchFor("3.40282347e+38", "3", "")', 'false');
196 shouldBe('stepMismatchFor("3.40282346e+38", "3", "")', 'false');
197 shouldBe('stepMismatchFor("3.40282345e+38", "3", "")', 'false');
198 debug('Huge numbers and huge step');
199 shouldBe('stepMismatchFor("3.20e+38", "0.20e+38", "")', 'false');
200 shouldBe('stepMismatchFor("3.20e+38", "0.22e+38", "")', 'false');
201 debug('Fractional numbers');
202 shouldBe('stepMismatchFor("0.9", "0.1", "")', 'false');
203 shouldBe('stepMismatchFor("0.9", "0.1000001", "")', 'false');
204 shouldBe('stepMismatchFor("0.9", "0.1000000000000001", "")', 'false');
205 shouldBe('stepMismatchFor("1.0", "0.3333333333333333", "")', 'false');
206 debug('Disabled');
207 shouldBe('stepMismatchFor("1", "2", "0", true)', 'false');
208
209 debug('');
210 debug('Time type');
211 input.type = 'time';
212 debug('Empty values');
213 shouldBeFalse('stepMismatchFor("", null, null)');
214 shouldBeFalse('stepMismatchFor("", "2", "12:34:56")');
215 debug('Normal step values');
216 shouldBeFalse('stepMismatchFor("12:34:55", "1", "12:34:56")');
217 shouldBeTrue('stepMismatchFor("12:34:55.001", "1", "12:34:56")');
218 shouldBeFalse('stepMismatchFor("12:34:56.001", "0.001", "12:34:56")');
219 shouldBeTrue('stepMismatchFor("12:34:55", "0.333", "12:34:56")');
220 shouldBeFalse('stepMismatchFor("12:34:55.001", "0.333", "12:34:56")');
221 shouldBeFalse('stepMismatchFor("12:34", "86400", "12:34")');
222 shouldBeTrue('stepMismatchFor("23:59:59.998", "86399.999", "00:00")');
223 shouldBeFalse('stepMismatchFor("23:59:59.999", "86399.999", "00:00")');
224 debug('Implicit step base');
225 shouldBeFalse('stepMismatchFor("12:34", "120", null)');
226 shouldBeTrue('stepMismatchFor("12:35", "120", null)');
227 debug('Small step values');
228 shouldBeFalse('stepMismatchFor("12:34:55.001", "0.0003", "12:34.55.000")');
229 shouldBeTrue('stepMismatchFor("12:34:55.001", "0.0019", "12:34.55.000")');
230 shouldBeFalse('stepMismatchFor("12:34:55.004", "0.0019", "12:34.55.000")');
231 debug('Invalid or no step values');
232 shouldBeFalse('stepMismatchFor("12:34", null, "12:34")');
233 shouldBeTrue('stepMismatchFor("12:34:56", null, "12:34")');
234 shouldBeFalse('stepMismatchFor("12:34", "-1", "12:34")');
235 shouldBeFalse('stepMismatchFor("12:34", "foo", "12:34")');
236 debug('Special step value');
237 shouldBeFalse('stepMismatchFor("12:35", "any", "12:34")');
238 debug('Disabled');
239 shouldBeFalse('stepMismatchFor("12:34:55.001", "1", "12:34:56", true)');
240
241 debug('');
242 debug('Week type');
243 input.type = 'week';
244 debug('Empty values');
245 shouldBeFalse('stepMismatchFor("", null, null)');
246 shouldBeFalse('stepMismatchFor("", "2", "1970-W02")');
247 debug('Normal step values');
248 shouldBeTrue('stepMismatchFor("2010-W03", "2", "2010-W02")');
249 shouldBeFalse('stepMismatchFor("2010-W02", "2", "2010-W02")');
250 shouldBeFalse('stepMismatchFor("2010-W04", "2", "2010-W02")');
251 shouldBeTrue('stepMismatchFor("1800-W11", "3", "1800-W09")');
252 shouldBeFalse('stepMismatchFor("1800-W09", "3", "1800-W09")');
253 shouldBeFalse('stepMismatchFor("1800-W12", "3", "1800-W09")');
254 shouldBeTrue('stepMismatchFor("275760-W35", "3", "275760-W33")');
255 shouldBeFalse('stepMismatchFor("275760-W35", "2", "275760-W33")');
256 debug('Implicit step base');
257 shouldBeFalse('stepMismatchFor("1970-W01", "2", null)');
258 shouldBeTrue('stepMismatchFor("1970-W02", "2", null)');
259 shouldBeFalse('stepMismatchFor("1970-W03", "2", null)');
260 shouldBeTrue('stepMismatchFor("1970-W04", "2", null)');
261 debug('Fractional step values');
262 shouldBeFalse('stepMismatchFor("2010-W03", "0.1", "2010-W02")');
263 shouldBeFalse('stepMismatchFor("2010-W03", "1.1", "2010-W02")');
264 shouldBeTrue('stepMismatchFor("2010-W03", "1.9", "2010-W02")');
265 debug('Invalid or no step values');
266 shouldBeFalse('stepMismatchFor("2010-W03", null, "2010-W02")');
267 shouldBeFalse('stepMismatchFor("2010-W03", "-1", "2010-W02")');
268 shouldBeFalse('stepMismatchFor("2010-W03", "foo", "2010-W02")');
269 debug('Special step value');
270 shouldBeFalse('stepMismatchFor("2010-W03", "any", "2010-W02")');
271 debug('Disabled');
272 shouldBeFalse('stepMismatchFor("2010-W03", "2", "2010-W02", true)');
273
274 debug('');
275 debug('Unsupported types');
276 shouldBe('input.type = "text"; input.step = "3"; input.min = ""; input.value = "2"; input.validity.stepMismatch', 'false');
277 shouldBe('input.type = "button"; input.validity.stepMismatch', 'false');
278 shouldBe('input.type = "checkbox"; input.validity.stepMismatch', 'false');
279 shouldBe('input.type = "color"; input.validity.stepMismatch', 'false');
280 shouldBe('input.type = "email"; input.validity.stepMismatch', 'false');
281 shouldBe('input.type = "hidden"; input.validity.stepMismatch', 'false');
282 shouldBe('input.type = "image"; input.validity.stepMismatch', 'false');
283 shouldBe('input.type = "khtml_isindex"; input.validity.stepMismatch', 'false');
284 shouldBe('input.type = "passwd"; input.validity.stepMismatch', 'false');
285 shouldBe('input.type = "radio"; input.validity.stepMismatch', 'false');
286 shouldBe('input.type = "reset"; input.validity.stepMismatch', 'false');
287 shouldBe('input.type = "search"; input.validity.stepMismatch', 'false');
288 shouldBe('input.type = "submit"; input.validity.stepMismatch', 'false');
289 shouldBe('input.type = "tel"; input.validity.stepMismatch', 'false');
290 shouldBe('input.type = "url"; input.validity.stepMismatch', 'false');
291 shouldBe('input.type = "file"; input.validity.stepMismatch', 'false');
292
293 var successfullyParsed = true;