| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../js/resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <p id="description"></p> |
| <div id="console"></div> |
| <script> |
| description('Check stepping-up and -down for range input from renderer.'); |
| |
| var input = document.createElement('input'); |
| var invalidStateErr = '"Error: InvalidStateError: DOM Exception 11"'; |
| |
| function sendKey(keyName) { |
| var event = document.createEvent('KeyboardEvent'); |
| event.initKeyboardEvent('keydown', true, true, document.defaultView, keyName); |
| input.dispatchEvent(event); |
| } |
| |
| function setInputAttributes(min, max, step, value) { |
| input.min = min; |
| input.max = max; |
| input.step = step; |
| input.value = value; |
| } |
| |
| function stepUp(value, step, max, optionalStepCount) { |
| setInputAttributes(null, max, step, value); |
| if (typeof optionalStepCount != "undefined") |
| if (optionalStepCount < 0) |
| for (var i = 0; i < -optionalStepCount; i++) |
| sendKey('Down'); |
| else |
| for (var i = 0; i < optionalStepCount; i++) |
| sendKey('Up'); |
| else |
| sendKey('Up'); |
| return input.value; |
| } |
| |
| function stepDown(value, step, min, optionalStepCount) { |
| setInputAttributes(min, null, step, value); |
| if (typeof optionalStepCount != "undefined") |
| if (optionalStepCount < 0) |
| for (var i = 0; i < -optionalStepCount; i++) |
| sendKey('Up'); |
| else |
| for (var i = 0; i < optionalStepCount; i++) |
| sendKey('Down'); |
| else |
| sendKey('Down'); |
| return input.value; |
| } |
| |
| // Range value gets automatically shifted based on bounds, |
| // So always set the min and max first to get expected behavior |
| |
| function stepUpExplicitBounds(min, max, step, value, stepCount) { |
| setInputAttributes(min, max, step, value); |
| if (typeof stepCount !== 'undefined') |
| if (stepCount < 0) { |
| for (var i = 0; i < -stepCount; i++) |
| sendKey('Down'); |
| } else { |
| for (var i = 0; i < stepCount; i++) |
| sendKey('Up'); |
| } |
| else |
| sendKey('Up'); |
| return input.value; |
| } |
| |
| function stepDownExplicitBounds(min, max, step, value, stepCount) { |
| setInputAttributes(min, max, step, value); |
| if (typeof stepCount !== 'undefined') |
| if (stepCount < 0) { |
| for (var i = 0; i < -stepCount; i++) |
| sendKey('Up'); |
| } else { |
| for (var i = 0; i < stepCount; i++) |
| sendKey('Down'); |
| } |
| else |
| sendKey('Down'); |
| return input.value; |
| } |
| |
| input.type = 'range'; |
| debug('Function arguments are (min, max, step, value, [stepCount]).'); |
| debug('Using the default values'); |
| shouldBe('stepUpExplicitBounds(null, null, null, "")', '"51"'); |
| shouldBe('stepDownExplicitBounds(null, null, null, "")', '"49"'); |
| shouldBe('stepUpExplicitBounds(null, null, "any", "")', '"51"'); |
| shouldBe('stepDownExplicitBounds(null, null, "any", "")', '"49"'); |
| shouldBe('stepUpExplicitBounds(null, null, "foo", "")', '"51"'); |
| shouldBe('stepDownExplicitBounds(null, null, "foo", "")', '"49"'); |
| shouldBe('stepUpExplicitBounds(null, null, null, "foo")', '"51"'); |
| shouldBe('stepDownExplicitBounds(null, null, null, "foo")', '"49"'); |
| shouldBe('stepUpExplicitBounds(null, null, "any", "foo")', '"51"'); |
| shouldBe('stepDownExplicitBounds(null, null, "any", "foo")', '"49"'); |
| shouldBe('stepUpExplicitBounds(null, null, "foo", "foo")', '"51"'); |
| shouldBe('stepDownExplicitBounds(null, null, "foo", "foo")', '"49"'); |
| debug('Normal cases'); |
| shouldBe('stepUpExplicitBounds(null, null, null, "0")', '"1"'); |
| shouldBe('stepUpExplicitBounds(null, null, null, "1", 2)', '"3"'); |
| shouldBe('stepUpExplicitBounds(null, null, null, "3", -1)', '"2"'); |
| shouldBe('stepDownExplicitBounds("-100", null, null, "2")', '"1"'); |
| shouldBe('stepDownExplicitBounds("-100", null, null, "1", 2)', '"-1"'); |
| shouldBe('stepDownExplicitBounds("-100", null, null, "-1", -1)', '"0"'); |
| debug('Invalid step value'); |
| shouldBe('stepUpExplicitBounds(null, null, "foo", "0")', '"1"'); |
| shouldBe('stepUpExplicitBounds(null, null, "0", "1")', '"2"'); |
| shouldBe('stepUpExplicitBounds(null, null, "-1", "2")', '"3"'); |
| shouldBe('stepDownExplicitBounds(null, null, "foo", "1")', '"0"'); |
| shouldBe('stepDownExplicitBounds(null, null, "0", "2")', '"1"'); |
| shouldBe('stepDownExplicitBounds(null, null, "-1", "3")', '"2"'); |
| debug('Step=any'); |
| shouldBe('stepUpExplicitBounds(null, null, "any", "1")', '"2"'); |
| shouldBe('stepDownExplicitBounds(null, null, "any", "1")', '"0"'); |
| debug('Overflow/underflow'); |
| shouldBe('stepUpExplicitBounds(null, "100", "1", "99")', '"100"'); |
| shouldBe('stepUpExplicitBounds(null, "100", "1", "100")', '"100"'); |
| shouldBe('stepUpExplicitBounds(null, "100", "1", "99", 2)', '"100"'); |
| shouldBe('stepDownExplicitBounds("0", null, "1", "1")', '"0"'); |
| shouldBe('stepDownExplicitBounds("0", null, "1", "0")', '"0"'); |
| shouldBe('stepDownExplicitBounds("0", null, "1", "1", 2)', '"0"'); |
| shouldBe('stepDownExplicitBounds(null, null, "3.40282346e+38", "1", 2)', '"0"'); |
| shouldBe('stepUpExplicitBounds(-100, 0, 1, -1)', '"0"'); |
| shouldBe('stepUpExplicitBounds(null, 0, 1, 0)', '"0"'); |
| shouldBe('stepUpExplicitBounds(-100, 0, 1, -1, 2)', '"0"'); |
| shouldBe('stepUpExplicitBounds(null, null, "3.40282346e+38", "1", 2)', '"0"'); |
| debug('stepDown()/stepUp() for stepMismatch values'); |
| shouldBe('stepUpExplicitBounds(null, null, 2, 1)', '"4"'); |
| shouldBe('stepUpExplicitBounds(0, null, 10, 9, 9)', '"100"'); |
| shouldBe('stepDownExplicitBounds(0, null, 10, 19)', '"10"'); |
| debug('value + step is <= max, but rounded result would be > max.'); |
| shouldBe('stepUpExplicitBounds(null, 99, 10, 89)', '"90"'); |
| debug('Huge value and small step'); |
| shouldBe('stepUpExplicitBounds(0, 1e38, 1, 1e38, 999)', '"1e+38"'); |
| shouldBe('stepDownExplicitBounds(0, 1e38, 1, 1e38, 999)', '"1e+38"'); |
| debug('Fractional numbers'); |
| shouldBe('stepUpExplicitBounds(null, null, 0.33333333333333333, 0, 3)', '"1"'); |
| shouldBe('stepUpExplicitBounds(null, null, 0.1, 1)', '"1.1"'); |
| shouldBe('stepUpExplicitBounds(null, null, 0.1, 1, 8)', '"1.8"'); |
| shouldBe('stepUpExplicitBounds(null, null, 0.1, 1, 10)', '"2"'); |
| shouldBe('stepUpExplicitBounds(0, 1, 0.003921568627450980, 0, 255)', '"1"'); |
| shouldBe('stepDownExplicitBounds(null, null, 0.1, 1, 8)', '"0.2"'); |
| shouldBe('stepDownExplicitBounds(null, null, 0.1, 1)', '"0.9"'); |
| |
| debug(''); |
| </script> |
| <script src="../../js/resources/js-test-post.js"></script> |
| </body> |
| </html> |