4 <script src=
"../../../resources/js-test.js"></script>
8 description('Check stepUp() and stepDown() behavior for number type.');
10 var input
= document
.createElement('input');
11 var changeEventCounter
= 0;
12 input
.onchange = function() { ++changeEventCounter
; };
14 function setInputAttributes(min
, max
, step
, value
) {
21 function stepUp(value
, step
, max
, optionalStepCount
) {
22 setInputAttributes(null, max
, step
, value
);
23 if (typeof optionalStepCount
!= "undefined")
24 input
.stepUp(optionalStepCount
);
30 function stepDown(value
, step
, min
, optionalStepCount
) {
31 setInputAttributes(min
, null, step
, value
);
32 if (typeof optionalStepCount
!= "undefined")
33 input
.stepDown(optionalStepCount
);
39 function stepUpExplicitBounds(min
, max
, step
, value
, stepCount
) {
40 setInputAttributes(min
, max
, step
, value
);
41 if (typeof stepCount
!== 'undefined')
42 input
.stepUp(stepCount
);
48 function stepDownExplicitBounds(min
, max
, step
, value
, stepCount
) {
49 setInputAttributes(min
, max
, step
, value
);
50 if (typeof stepCount
!== 'undefined')
51 input
.stepDown(stepCount
);
58 input
.type
= 'number';
59 debug('Invalid value');
60 shouldBeEqualToString('stepUp("", null, null)', '1');
61 shouldBeEqualToString('stepDown("", null, null)', '-1');
62 debug('Non-number arguments');
63 shouldBe('stepUp("0", null, null, "0")', '"0"');
64 shouldBe('stepDown("0", null, null, "0")', '"0"');
65 shouldBe('stepUp("0", null, null, "foo")', '"0"');
66 shouldBe('stepDown("0", null, null, "foo")', '"0"');
67 shouldBe('stepUp("0", null, null, null)', '"0"');
68 shouldBe('stepDown("0", null, null, null)', '"0"');
69 debug('Normal cases');
70 shouldBe('stepUp("0", null, null)', '"1"');
71 shouldBe('stepUp("1", null, null, 2)', '"3"');
72 shouldBe('stepUp("3", null, null, -1)', '"2"');
73 shouldBe('stepDown("2", null, null)', '"1"');
74 shouldBe('stepDown("1", null, null, 2)', '"-1"');
75 shouldBe('stepDown("-1", null, null, -1)', '"0"');
76 debug('Extra arguments');
77 shouldBe('input.value = "0"; input.min = null; input.step = null; input.stepUp(1, 2); input.value', '"1"');
78 shouldBe('input.value = "1"; input.stepDown(1, 3); input.value', '"0"');
79 debug('Invalid step value');
80 shouldBe('stepUp("0", "foo", null)', '"1"');
81 shouldBe('stepUp("1", "0", null)', '"2"');
82 shouldBe('stepUp("2", "-1", null)', '"3"');
84 shouldThrow('stepUp("0", "any", null)');
85 shouldThrow('stepDown("0", "any", null)');
86 debug('Step=any corner case');
87 shouldThrow('stepUpExplicitBounds("0", "100", "any", "1.5", "1")');
88 shouldThrow('stepDownExplicitBounds("0", "100", "any", "1.5", "1")');
89 debug('Overflow/underflow');
90 shouldBe('stepDown("1", "1", "0")', '"0"');
91 shouldBeEqualToString('stepDown("0", "1", "0")', '0');
92 shouldBeEqualToString('stepDown("1", "1", "0", 2)', '0');
93 shouldBeEqualToString('stepDown("1", "1.797693134862315e+308", "", 2)', '-1.797693134862315e+308');
94 shouldBeEqualToString('stepUp("-1", "1", "0")', '0');
95 shouldBeEqualToString('stepUp("0", "1", "0")', '0');
96 shouldBeEqualToString('stepUp("-1", "1", "0", 2)', '0');
97 shouldBeEqualToString('stepUp("1", "1.797693134862315e+308", "", 2)', '1.797693134862315e+308');
98 debug('stepDown()/stepUp() for stepMismatch values');
99 shouldBeEqualToString('stepUpExplicitBounds("0", "", "2", "1"); input.value', '2');
100 shouldBeEqualToString('stepUp("1", "2", "")', '2');
101 shouldBeEqualToString('input.stepDown(); input.value', '0');
102 shouldBeEqualToString('input.min = "0"; stepUp("9", "10", "", 9)', '90');
103 shouldBeEqualToString('stepDown("19", "10", "0")', '10');
104 shouldBeEqualToString('stepUp("89", "10", "99")', '90');
105 debug('Huge value and small step');
106 shouldBe('input.min = ""; stepUp("1e+308", "1", "", 999999)', '"1e+308"');
107 shouldBe('input.max = ""; stepDown("1e+308", "1", "", 999999)', '"1e+308"');
108 debug('Fractional numbers');
109 shouldBe('input.min = ""; stepUp("0", "0.33333333333333333", "", 3)', '"1"');
110 shouldBe('stepUp("1", "0.1", "", 10)', '"2"');
111 shouldBe('input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.value', '"3"');
112 shouldBe('input.min = "0"; stepUp("0", "0.003921568627450980", "1", 255)', '"1"');
113 shouldBe('for (var i = 0; i < 255; i++) { input.stepDown(); }; input.value', '"0"');
115 shouldBe('stepUp("5.005", "0.005", "", 2)', '"5.015"');
116 shouldBe('stepUp("5.005", "0.005", "", 11)', '"5.06"');
117 shouldBe('stepUp("5.005", "0.005", "", 12)', '"5.065"');
118 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 2)', '"5.015"');
119 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 11)', '"5.06"');
120 shouldBe('stepUpExplicitBounds("4", "9", "0.005", "5.005", 12)', '"5.065"');
123 debug('This test should not dispatch any |change| events.');
124 shouldBe('changeEventCounter', '0');