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