Git init
[framework/web/webkit-efl.git] / LayoutTests / fast / forms / time / input-valueasnumber-time.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link rel="stylesheet" href="../../js/resources/js-test-style.css">
5 <script src="../../js/resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10 <script>
11 description('Tests for .valueAsNumber with &lt;input type=time>.');
12
13 var input = document.createElement('input');
14 input.type = 'time';
15
16 function valueAsNumberFor(stringValue) {
17     input.value = stringValue;
18     return input.valueAsNumber;
19 }
20
21 function setValueAsNumberAndGetValue(hour, minute, second, ms) {
22     input.valueAsNumber = ((hour * 60 + minute) * 60 + second) * 1000 + ms;
23     return input.value;
24 }
25
26 shouldBe('valueAsNumberFor("")', 'Number.NaN');
27 shouldBe('valueAsNumberFor("00:00:00.000")', 'Date.UTC(1970, 0, 1, 0, 0, 0, 0)');
28 shouldBe('valueAsNumberFor("04:35")', 'Date.UTC(1970, 0, 1, 4, 35, 0, 0)');
29 shouldBe('valueAsNumberFor("23:59:59.999")', 'Date.UTC(1970, 0, 1, 23, 59, 59, 999)');
30
31 shouldBe('setValueAsNumberAndGetValue(0, 0, 0, 0)', '"00:00"');
32 shouldBe('setValueAsNumberAndGetValue(0, 0, 1, 0)', '"00:00:01"');
33 shouldBe('setValueAsNumberAndGetValue(0, 0, 0, 2)', '"00:00:00.002"');
34 shouldBe('setValueAsNumberAndGetValue(11, 59, 59, 999)', '"11:59:59.999"');
35 shouldBe('setValueAsNumberAndGetValue(12, 0, 0, 0)', '"12:00"');
36 shouldBe('setValueAsNumberAndGetValue(23, 59, 59, 999)', '"23:59:59.999"');
37 shouldBe('setValueAsNumberAndGetValue(24, 0, 0, 0)', '"00:00"');
38 shouldBe('setValueAsNumberAndGetValue(48, 0, 13, 0)', '"00:00:13"');
39 shouldBe('setValueAsNumberAndGetValue(-23, -59, -59, 0)', '"00:00:01"');
40
41 debug('Tests to set invalid values to valueAsNumber:');
42 shouldBe('input.value = ""; input.valueAsNumber = null; input.value', '"00:00"');
43 shouldThrow('input.valueAsNumber = "foo"', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');
44 shouldThrow('input.valueAsNumber = NaN', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');
45 shouldThrow('input.valueAsNumber = Number.NaN', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');
46 shouldThrow('input.valueAsNumber = Infinity', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');
47 shouldThrow('input.valueAsNumber = Number.POSITIVE_INFINITY', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');
48 shouldThrow('input.valueAsNumber = Number.NEGATIVE_INFINITY', '"Error: NOT_SUPPORTED_ERR: DOM Exception 9"');
49
50 debug('Step attribute value and string representation:');
51 // If the step attribute value is 1 second and the second part is 0, we should show the second part.
52 shouldBe('input.step = "1"; setValueAsNumberAndGetValue(0, 0, 0, 0)', '"00:00:00"');
53 // If the step attribute value is 0.001 second and the millisecond part is 0, we should show the millisecond part.
54 shouldBe('input.step = "0.001"; setValueAsNumberAndGetValue(0, 0, 0, 0)', '"00:00:00.000"');
55
56 var successfullyParsed = true;
57 </script>
58 <script src="../../js/resources/js-test-post.js"></script>
59 </body>
60 </html>