|
Line 0
a/LayoutTests/fast/forms/script-tests/input-step-number.js_sec1
|
|
|
1 |
description('Tests stepDown()/stepUp() for type=number.'); |
| 2 |
|
| 3 |
var input = document.createElement('input'); |
| 4 |
input.type = 'number'; |
| 5 |
var invalidStateErr = '"Error: INVALID_STATE_ERR: DOM Exception 11"'; |
| 6 |
|
| 7 |
// The value is unparsable. |
| 8 |
input.value = ''; |
| 9 |
shouldThrow('input.stepDown()', invalidStateErr); |
| 10 |
shouldThrow('input.stepUp()', invalidStateErr); |
| 11 |
|
| 12 |
// Non-number argument |
| 13 |
input.value = '0'; |
| 14 |
input.stepDown("foo"); |
| 15 |
shouldBe('input.value', '"0"'); |
| 16 |
input.stepUp("foo"); |
| 17 |
shouldBe('input.value', '"0"'); |
| 18 |
|
| 19 |
// Default step value for type=number is 1. |
| 20 |
input.value = '0'; |
| 21 |
input.stepUp(); |
| 22 |
shouldBe('input.value', '"1"'); |
| 23 |
input.stepUp(2); |
| 24 |
shouldBe('input.value', '"3"'); |
| 25 |
input.stepUp(-1); |
| 26 |
shouldBe('input.value', '"2"'); |
| 27 |
input.stepDown(); |
| 28 |
shouldBe('input.value', '"1"'); |
| 29 |
input.stepDown(2); |
| 30 |
shouldBe('input.value', '"-1"'); |
| 31 |
input.stepDown(-1); |
| 32 |
shouldBe('input.value', '"0"'); |
| 33 |
// The default value is used for invalid step values. |
| 34 |
input.value = '0'; |
| 35 |
input.step = 'foo'; |
| 36 |
input.stepUp(); |
| 37 |
shouldBe('input.value', '"1"'); |
| 38 |
input.step = '0'; |
| 39 |
input.stepUp(); |
| 40 |
shouldBe('input.value', '"2"'); |
| 41 |
input.step = '-1'; |
| 42 |
input.stepUp(); |
| 43 |
shouldBe('input.value', '"3"'); |
| 44 |
|
| 45 |
// No step value |
| 46 |
input.value = '0'; |
| 47 |
input.step = 'any'; |
| 48 |
shouldThrow('input.stepDown()', invalidStateErr); |
| 49 |
shouldThrow('input.stepUp()', invalidStateErr); |
| 50 |
|
| 51 |
// Minimum limit |
| 52 |
input.min = '0'; |
| 53 |
input.step = '1'; |
| 54 |
input.value = '1'; |
| 55 |
input.stepDown(); |
| 56 |
shouldBe('input.value', '"0"'); |
| 57 |
shouldThrow('input.stepDown()', invalidStateErr); |
| 58 |
input.value = '1'; |
| 59 |
shouldThrow('input.stepDown(2)', invalidStateErr); |
| 60 |
shouldBe('input.value', '"1"'); |
| 61 |
// Should not be -Infinity. |
| 62 |
input.value = '1'; |
| 63 |
input.min = ''; |
| 64 |
input.step = '1.7976931348623156e+308'; |
| 65 |
shouldThrow('input.stepDown(2)', invalidStateErr); |
| 66 |
|
| 67 |
// Maximum limit |
| 68 |
input.value = '-1'; |
| 69 |
input.min = ''; |
| 70 |
input.max = '0'; |
| 71 |
input.step = '1'; |
| 72 |
input.stepUp(); |
| 73 |
shouldBe('input.value', '"0"'); |
| 74 |
shouldThrow('input.stepUp()', invalidStateErr); |
| 75 |
input.value = '-1'; |
| 76 |
shouldThrow('input.stepUp(2)', invalidStateErr); |
| 77 |
shouldBe('input.value', '"-1"'); |
| 78 |
// Should not be Infinity. |
| 79 |
input.value = '1'; |
| 80 |
input.max = ''; |
| 81 |
input.step = '1.7976931348623156e+308'; |
| 82 |
shouldThrow('input.stepUp(2)', invalidStateErr); |
| 83 |
|
| 84 |
// stepDown()/stepUp() for stepMismatch values |
| 85 |
input.value = '0'; |
| 86 |
input.min = '-1'; |
| 87 |
input.step = '2'; |
| 88 |
input.stepUp(); |
| 89 |
shouldBe('input.value', '"3"'); |
| 90 |
input.stepDown(); |
| 91 |
shouldBe('input.value', '"1"'); |
| 92 |
input.value = '9'; |
| 93 |
input.min = '0'; |
| 94 |
input.max = ''; |
| 95 |
input.step = '10'; |
| 96 |
input.stepUp(9); |
| 97 |
shouldBe('input.value', '"100"'); |
| 98 |
input.value = '19'; |
| 99 |
input.stepDown(); |
| 100 |
shouldBe('input.value', '"10"'); |
| 101 |
// value + step is <= max, but rounded result would be > max. |
| 102 |
input.value = '89'; |
| 103 |
input.max = '99'; |
| 104 |
shouldThrow('input.stepUp()', invalidStateErr); |
| 105 |
|
| 106 |
// Huge value and small step |
| 107 |
input.value = '1e+308'; |
| 108 |
input.min = ''; |
| 109 |
input.max = ''; |
| 110 |
input.step = '1'; |
| 111 |
input.stepUp(999999); |
| 112 |
shouldBe('input.value', '"1e+308"'); |
| 113 |
input.stepDown(999999); |
| 114 |
shouldBe('input.value', '"1e+308"'); |
| 115 |
|
| 116 |
// Fractional numbers |
| 117 |
input.value = '0'; |
| 118 |
input.min = ''; |
| 119 |
input.max = ''; |
| 120 |
input.step = '0.33333333333333333'; |
| 121 |
input.stepUp(3); |
| 122 |
shouldBe('input.value', '"1"'); |
| 123 |
input.step = '0.1'; |
| 124 |
input.stepUp(10); |
| 125 |
shouldBe('input.value', '"2"'); |
| 126 |
for (var i = 0; i < 10; i++) |
| 127 |
input.stepUp(); |
| 128 |
shouldBe('input.value', '"3"'); |
| 129 |
|
| 130 |
input.value = '0'; |
| 131 |
input.min = '0'; |
| 132 |
input.max = '1'; |
| 133 |
input.step = '0.003921568627450980'; |
| 134 |
input.stepUp(255); |
| 135 |
shouldBe('input.value', '"1"'); |
| 136 |
for (var i = 0; i < 255; i++) |
| 137 |
input.stepDown(); |
| 138 |
shouldBe('input.value', '"0"'); |
| 139 |
|
| 140 |
var successfullyParsed = true; |