blob: 82aa78c0c8b6a6ca9b28a6cabd8c32890c663ee0 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description('Check stepMismatch results for type=range.');
var input = document.createElement('input');
document.body.appendChild(input);
function stepMismatchFor(value, step, min, disabled) {
input.min = min;
input.step = step;
input.value = value;
input.disabled = !!disabled;
return input.validity.stepMismatch;
}
input.type = 'range';
// All expected results should be 'false'.
debug('Empty values');
shouldBe('stepMismatchFor("", null, null)', 'false');
shouldBe('stepMismatchFor("", "1.0", "0.1")', 'false');
debug('Integers');
shouldBe('stepMismatchFor("1", "2", "0")', 'false');
shouldBe('stepMismatchFor("-3", "2", "-4")', 'false');
shouldBe('input.max = "5"; stepMismatchFor("5", "3", "0")', 'false');
shouldBe('input.value', '"3"'); // Different from type=number.
debug('Invalid step values');
input.max = '';
shouldBe('stepMismatchFor("-3", "-2", "-4")', 'false');
shouldBe('stepMismatchFor("-3", null, "-4")', 'false');
shouldBe('stepMismatchFor("-3", undefined, "-4")', 'false');
debug('Updating step attribute');
stepMismatchFor('50', '10', '0');
shouldBeEqualToString('input.value', '50');
shouldBeEqualToString('input.step = "15"; input.value', '45');
shouldBeEqualToString('input.step = "20"; input.value', '40');
stepMismatchFor('50', '10', '0');
shouldBeEqualToString('input.value = "5", input.value', '10');
shouldBeEqualToString('input.step = "6"; input.value', '12');
debug('Huge numbers and small step; uncomparable');
shouldBe('stepMismatchFor("3.40282347e+38", "3", "")', 'false');
shouldBe('stepMismatchFor("3.40282346e+38", "3", "")', 'false');
shouldBe('stepMismatchFor("3.40282345e+38", "3", "")', 'false');
debug('Huge numbers and huge step');
shouldBe('stepMismatchFor("3.20e+38", "0.20e+38", "")', 'false');
shouldBe('stepMismatchFor("3.20e+38", "0.22e+38", "")', 'false');
debug('Fractional numbers');
shouldBe('stepMismatchFor("0.9", "0.1", "")', 'false');
shouldBe('stepMismatchFor("0.9", "0.1000001", "")', 'false');
shouldBe('stepMismatchFor("0.9", "0.1000000000000001", "")', 'false');
shouldBe('stepMismatchFor("1.0", "0.3333333333333333", "")', 'false');
debug('Disabled');
shouldBe('stepMismatchFor("1", "2", "0", true)', 'false');
</script>
</body>
</html>