tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / forms / time / time-stepup-stepdown-from-renderer.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10 description('Check stepping-up and -down for time input fields from renderer. No cases of empty initial values.');
11
12 var input = document.createElement('input');
13 var invalidStateErr = '"Error: INVALID_STATE_ERR: DOM Exception 11"';
14
15 function sendKey(keyName) {
16     var event = document.createEvent('KeyboardEvent');
17     event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName);
18     input.dispatchEvent(event);
19 }
20
21 function setInputAttributes(min, max, step, value) {
22     input.min = min;
23     input.max = max;
24     input.step = step;
25     input.value = value;
26 }
27
28 function stepUp(value, step, max, optionalStepCount) {
29     setInputAttributes(null, max, step, value);
30     if (typeof optionalStepCount != "undefined")
31         if (optionalStepCount < 0)
32             for (var i = 0; i < -optionalStepCount; i++)
33                 sendKey('Down');
34         else
35             for (var i = 0; i < optionalStepCount; i++)
36                 sendKey('Up');
37     else
38         sendKey('Up');
39     return input.value;
40 }
41
42 function stepDown(value, step, min, optionalStepCount) {
43     setInputAttributes(min, null, step, value);
44     if (typeof optionalStepCount != "undefined")
45         if (optionalStepCount < 0)
46             for (var i = 0; i < -optionalStepCount; i++)
47                 sendKey('Up');
48         else
49             for (var i = 0; i < optionalStepCount; i++)
50                 sendKey('Down');
51     else
52         sendKey('Down');
53     return input.value;
54 }
55
56 input.type = 'time';
57 debug('Function arguments are (value, step, {min or max}, [stepCount]).');
58 debug('Normal cases');
59 shouldBe('stepUp("20:13", null, null)', '"20:14"');
60 shouldBe('stepDown("20:13", null, null)', '"20:12"');
61 shouldBe('stepUp("20:13", null, null, 10)', '"20:23"');
62 shouldBe('stepDown("20:13", null, null, 11)', '"20:02"');
63 shouldBe('stepUp("20:13", "4", null, 2)', '"20:13:08"');
64 shouldBe('stepDown("20:13", "4", null, 3)', '"20:12:48"');
65 debug('Step=any');
66 shouldBe('stepUp("20:13", "any", null)', '"20:14"');
67 shouldBe('stepDown("20:13", "any", null)', '"20:12"');
68 debug('Overflow/underflow');
69 shouldBe('stepUp("20:13", "3.40282346e+38", null)', '"23:59:59.999"');
70 shouldBe('stepDown("20:13", "3.40282346e+38", null)', '"00:00:00.000"');
71 shouldBe('stepUp("20:13", "1", "20:13")', '"20:13"');
72 shouldBe('stepDown("20:13", "1", "20:13")', '"20:13"');
73 shouldBe('stepUp("23:59", null, null)', '"23:59"');
74 shouldBe('stepDown("00:00", null, null)', '"00:00"');
75 debug('stepDown()/stepUp() for stepMismatch values');
76 shouldBe('stepDown("20:13", "3", "20:12:56")', '"20:12:59"');
77 shouldBe('stepUp("00:13", "7", "")', '"00:13:04"');
78
79 debug('');
80 </script>
81 <script src="../../js/resources/js-test-post.js"></script>
82 </body>
83 </html>