0def974eccfe7d018e1d3b4cd82e99d030e146ea
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / forms / number / number-stepup-stepdown.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description('Check stepUp() and stepDown() behavior for number type.');
9
10 var input = document.createElement('input');
11
12 function setInputAttributes(min, max, step, value) {
13     input.min = min;
14     input.max = max;
15     input.step = step;
16     input.value = value;
17 }
18
19 function stepUp(value, step, max, optionalStepCount) {
20     setInputAttributes(null, max, step, value);
21     if (typeof optionalStepCount != "undefined")
22         input.stepUp(optionalStepCount);
23     else
24         input.stepUp();
25     return input.value;
26 }
27
28 function stepDown(value, step, min, optionalStepCount) {
29     setInputAttributes(min, null, step, value);
30     if (typeof optionalStepCount != "undefined")
31         input.stepDown(optionalStepCount);
32     else
33         input.stepDown();
34     return input.value;
35 }
36
37 function stepUpExplicitBounds(min, max, step, value, stepCount) {
38     setInputAttributes(min, max, step, value);
39     if (typeof stepCount !== 'undefined')
40         input.stepUp(stepCount);
41     else
42         input.stepUp();
43     return input.value;
44 }
45
46 function stepDownExplicitBounds(min, max, step, value, stepCount) {
47     setInputAttributes(min, max, step, value);
48     if (typeof stepCount !== 'undefined')
49         input.stepDown(stepCount);
50     else
51         input.stepDown();
52     return input.value;
53 }
54
55 debug('Number type');
56 input.type = 'number';
57 debug('Invalid value');
58 shouldBeEqualToString('stepUp("", null, null)', '1');
59 shouldBeEqualToString('stepDown("", null, null)', '-1');
60 debug('Non-number arguments');
61 shouldBe('stepUp("0", null, null, "0")', '"0"');
62 shouldBe('stepDown("0", null, null, "0")', '"0"');
63 shouldBe('stepUp("0", null, null, "foo")', '"0"');
64 shouldBe('stepDown("0", null, null, "foo")', '"0"');
65 shouldBe('stepUp("0", null, null, null)', '"0"');
66 shouldBe('stepDown("0", null, null, null)', '"0"');
67 debug('Normal cases');
68 shouldBe('stepUp("0", null, null)', '"1"');
69 shouldBe('stepUp("1", null, null, 2)', '"3"');
70 shouldBe('stepUp("3", null, null, -1)', '"2"');
71 shouldBe('stepDown("2", null, null)', '"1"');
72 shouldBe('stepDown("1", null, null, 2)', '"-1"');
73 shouldBe('stepDown("-1", null, null, -1)', '"0"');
74 debug('Extra arguments');
75 shouldBe('input.value = "0"; input.min = null; input.step = null; input.stepUp(1, 2); input.value', '"1"');
76 shouldBe('input.value = "1"; input.stepDown(1, 3); input.value', '"0"');
77 debug('Invalid step value');
78 shouldBe('stepUp("0", "foo", null)', '"1"');
79 shouldBe('stepUp("1", "0", null)', '"2"');
80 shouldBe('stepUp("2", "-1", null)', '"3"');
81 debug('Step=any');
82 shouldThrow('stepUp("0", "any", null)');
83 shouldThrow('stepDown("0", "any", null)');
84 debug('Step=any corner case');
85 shouldThrow('stepUpExplicitBounds("0", "100", "any", "1.5", "1")');
86 shouldThrow('stepDownExplicitBounds("0", "100", "any", "1.5", "1")');
87 debug('Overflow/underflow');
88 shouldBe('stepDown("1", "1", "0")', '"0"');
89 shouldBeEqualToString('stepDown("0", "1", "0")', '0');
90 shouldBeEqualToString('stepDown("1", "1", "0", 2)', '0');
91 shouldBeEqualToString('stepDown("1", "3.40282346e+38", "", 2)', '-3.40282346e+38');
92 shouldBeEqualToString('stepUp("-1", "1", "0")', '0');
93 shouldBeEqualToString('stepUp("0", "1", "0")', '0');
94 shouldBeEqualToString('stepUp("-1", "1", "0", 2)', '0');
95 shouldBeEqualToString('stepUp("1", "3.40282346e+38", "", 2)', '3.40282346e+38');
96 debug('stepDown()/stepUp() for stepMismatch values');
97 shouldBeEqualToString('stepUpExplicitBounds("0", "", "2", "1"); input.value', '2');
98 shouldBeEqualToString('stepUp("1", "2", "")', '2');
99 shouldBeEqualToString('input.stepDown(); input.value', '0');
100 shouldBeEqualToString('input.min = "0"; stepUp("9", "10", "", 9)', '90');
101 shouldBeEqualToString('stepDown("19", "10", "0")', '10');
102 shouldBeEqualToString('stepUp("89", "10", "99")', '90');
103 debug('Huge value and small step');
104 shouldBe('input.min = ""; stepUp("1e+38", "1", "", 999999)', '"1e+38"');
105 shouldBe('input.max = ""; stepDown("1e+38", "1", "", 999999)', '"1e+38"');
106 debug('Fractional numbers');
107 shouldBe('input.min = ""; stepUp("0", "0.33333333333333333", "", 3)', '"1"');
108 shouldBe('stepUp("1", "0.1", "", 10)', '"2"');
109 shouldBe('input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.value', '"3"');
110 shouldBe('input.min = "0"; stepUp("0", "0.003921568627450980", "1", 255)', '"1"');
111 shouldBe('for (var i = 0; i < 255; i++) { input.stepDown(); }; input.value', '"0"');
112 debug('Rounding');
113 shouldBe('stepUp("5.005", "0.005", "", 2)', '"5.015"');
114 shouldBe('stepUp("5.005", "0.005", "", 11)', '"5.06"');
115 shouldBe('stepUp("5.005", "0.005", "", 12)', '"5.065"');
116 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 2)', '"5.015"');
117 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 11)', '"5.06"');
118 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 12)', '"5.065"');
119 </script>
120 </body>
121 </html>