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