Skip to content
Permalink
Browse files
2010-03-19 Joseph Pecoraro <joepeck@webkit.org>
        Reviewed by David Kilzer.

        <input type=range> does not validate correctly without a renderer and the tests are incorrect
        https://bugs.webkit.org/show_bug.cgi?id=36259

        Setting value attribute on an <input type=range> to an out-of-range value fires oninput
        https://bugs.webkit.org/show_bug.cgi?id=16990

        Part 2 of 2: When setting the range element's value, overflows and underflows
        are automatically sanitized to valid values. Moved the general case
        sanitization code out of the Renderer into HTMLInputElement::sanitizeValue.

        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::value): when getting a default value on reset() ensure the defaultValue is provided
        (WebCore::HTMLInputElement::sanitizeValue): clamp the value within the max/min/step range constraints
        * html/StepRange.cpp:
        (WebCore::StepRange::StepRange): allow const element in the constructor
        (WebCore::StepRange::clampValue): clamp from a String value
        * html/StepRange.h:
        (WebCore::StepRange::defaultValue): easy calculation of the default value for max/min/step range constraints
        * rendering/RenderSlider.cpp:
        (WebCore::RenderSlider::updateFromElement): no longer handle the general case sanitization in the renderer

2010-03-19  Joseph Pecoraro  <joepeck@webkit.org>

        Reviewed by David Kilzer.

        <input type=range> does not validate correctly without a renderer and the tests are incorrect
        https://bugs.webkit.org/show_bug.cgi?id=36259

        Setting value attribute on an <input type=range> to an out-of-range value fires oninput
        https://bugs.webkit.org/show_bug.cgi?id=16990

        When setting the range element's value, overflows and underflows are
        automatically sanitized to valid values. Fixed the behavior and removed
        tests that were testing for improper behavior.

        * fast/forms/ValidityState-rangeOverflow-expected.txt:
        * fast/forms/ValidityState-rangeUnderflow-expected.txt:
        * fast/forms/input-stepup-stepdown-expected.txt:
        * fast/forms/script-tests/ValidityState-rangeOverflow.js:
        * fast/forms/script-tests/ValidityState-rangeUnderflow.js:
        * fast/forms/script-tests/input-stepup-stepdown.js:
        * fast/forms/script-tests/validationMessage.js:
        * fast/forms/validationMessage-expected.txt:

          Added test verifying that bug 16990 was fixed as well.

        * fast/forms/range-input-dynamic-oninput-expected.txt: Added.
        * fast/forms/range-input-dynamic-oninput.html Added.

          Improved test because handling of this case changed.

        * fast/forms/range-reset-expected.txt:
        * fast/forms/range-reset.html:

Canonical link: https://commits.webkit.org/47536@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@56242 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JosephPecoraro committed Mar 19, 2010
1 parent bdaf6ba commit 923f2ba7853a8ec0760ace45c3faba0ef68d779e
@@ -1,3 +1,36 @@
2010-03-19 Joseph Pecoraro <joepeck@webkit.org>

Reviewed by David Kilzer.

<input type=range> does not validate correctly without a renderer and the tests are incorrect
https://bugs.webkit.org/show_bug.cgi?id=36259

Setting value attribute on an <input type=range> to an out-of-range value fires oninput
https://bugs.webkit.org/show_bug.cgi?id=16990

When setting the range element's value, overflows and underflows are
automatically sanitized to valid values. Fixed the behavior and removed
tests that were testing for improper behavior.

* fast/forms/ValidityState-rangeOverflow-expected.txt:
* fast/forms/ValidityState-rangeUnderflow-expected.txt:
* fast/forms/input-stepup-stepdown-expected.txt:
* fast/forms/script-tests/ValidityState-rangeOverflow.js:
* fast/forms/script-tests/ValidityState-rangeUnderflow.js:
* fast/forms/script-tests/input-stepup-stepdown.js:
* fast/forms/script-tests/validationMessage.js:
* fast/forms/validationMessage-expected.txt:

Added test verifying that bug 16990 was fixed as well.

* fast/forms/range-input-dynamic-oninput-expected.txt: Added.
* fast/forms/range-input-dynamic-oninput.html Added.

Improved test because handling of this case changed.

* fast/forms/range-reset-expected.txt:
* fast/forms/range-reset.html:

2010-03-19 Darin Fisher <darin@chromium.org>

Fix expected results for fast/loader/frame-src-change-added-to-history.html
@@ -73,21 +73,6 @@ PASS The value "-99" overflows the maximum value "-100".
PASS The value "101" overflows the maximum value "1E+2".
PASS The value "101" overflows the maximum value "100".

Type=range
PASS The value "99" doesn't overflow the maximum value "100".
PASS The value "-101" doesn't overflow the maximum value "-100".
PASS The value "99" doesn't overflow the maximum value "1E+2".
PASS The value "0.99" doesn't overflow the maximum value "1.00".
PASS The value "abc" doesn't overflow the maximum value "100".
PASS The value "" doesn't overflow the maximum value "-1".
PASS The value "0.999999999999999999999999999999999999999999" doesn't overflow the maximum value "0.999999999999999999999999999999999999999998".
PASS The value "101" doesn't overflow the maximum value "100".
PASS The value "101" overflows the maximum value "100".
PASS The value "-99" overflows the maximum value "-100".
PASS The value "101" overflows the maximum value "1E+2".
PASS The value "101" overflows the maximum value "".
PASS The value "101" overflows the maximum value "xxx".

Type=time
PASS The value "13:16" doesn't overflow the maximum value "".
PASS The value "13:16" doesn't overflow the maximum value "".
@@ -73,21 +73,6 @@ PASS The value "-101" undeflows the minimum value "-100".
PASS The value "99" undeflows the minimum value "1E+2".
PASS The value "101" undeflows the minimum value "200".

Type=range
PASS The value "101" doesn't underflow the minimum value "100".
PASS The value "-99" doesn't underflow the minimum value "-100".
PASS The value "101" doesn't underflow the minimum value "1E+2".
PASS The value "1.01" doesn't underflow the minimum value "1.00".
PASS The value "abc" doesn't underflow the minimum value "100".
PASS The value "" doesn't underflow the minimum value "1".
PASS The value "0.999999999999999999999999999999999999999998" doesn't underflow the minimum value "0.999999999999999999999999999999999999999999".
PASS The value "101" doesn't underflow the minimum value "100".
PASS The value "99" undeflows the minimum value "100".
PASS The value "-101" undeflows the minimum value "-100".
PASS The value "99" undeflows the minimum value "1E+2".
PASS The value "-1" undeflows the minimum value "".
PASS The value "-1" undeflows the minimum value "xxx".

Type=time
PASS The value "13:16" doesn't underflow the minimum value "".
PASS The value "13:16" doesn't underflow the minimum value "".
@@ -167,59 +167,74 @@ PASS input.min = "0"; stepUp("0", "0.003921568627450980", "1", 255) is "1"
PASS for (var i = 0; i < 255; i++) { input.stepDown(); }; input.value is "0"

Range type
Invalid value
PASS stepUp("", null, null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepDown("", null, null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
Non-number arguments
PASS stepUp("0", null, null, "0") is "0"
PASS stepDown("0", null, null, "0") is "0"
PASS stepUp("0", null, null, "foo") is "0"
PASS stepDown("0", null, null, "foo") is "0"
PASS stepUp("0", null, null, null) is "0"
PASS stepDown("0", null, null, null) is "0"
function arguments are (min, max, step, value, [stepCount])
Using the default values
PASS stepUpExplicitBounds(null, null, null, "") is "51"
PASS stepDownExplicitBounds(null, null, null, "") is "49"
Non-number arguments (stepCount)
PASS stepUpExplicitBounds(null, null, null, "0", "0") is "0"
PASS stepDownExplicitBounds(null, null, null, "0", "0") is "0"
PASS stepUpExplicitBounds(null, null, null, "0", "foo") is "0"
PASS stepDownExplicitBounds(null, null, null, "0", "foo") is "0"
PASS stepUpExplicitBounds(null, null, null, "0", null) is "0"
PASS stepDownExplicitBounds(null, null, null, "0", null) is "0"
Normal cases
PASS stepUp("0", null, null) is "1"
PASS stepUp("1", null, null, 2) is "3"
PASS stepUp("3", null, null, -1) is "2"
PASS stepDown("2", null, "-100") is "1"
PASS stepDown("1", null, "-100", 2) is "-1"
PASS stepDown("-1", null, "-100", -1) is "0"
PASS stepUpExplicitBounds(null, null, null, "0") is "1"
PASS stepUpExplicitBounds(null, null, null, "1", 2) is "3"
PASS stepUpExplicitBounds(null, null, null, "3", -1) is "2"
PASS stepDownExplicitBounds("-100", null, null, "2") is "1"
PASS stepDownExplicitBounds("-100", null, null, "1", 2) is "-1"
PASS stepDownExplicitBounds("-100", null, null, "-1", -1) is "0"
Extra arguments
PASS input.value = "0"; input.min = null; input.step = null; input.stepUp(1, 2); input.value is "1"
PASS input.value = "1"; input.stepDown(1, 3); input.value is "0"
PASS setInputAttributes(null, null, null, "0"); input.stepUp(1,2); input.value is "1"
PASS setInputAttributes(null, null, null, "1"); input.stepDown(1,3); input.value is "0"
Invalid step value
PASS stepUp("0", "foo", null) is "1"
PASS stepUp("1", "0", null) is "2"
PASS stepUp("2", "-1", null) is "3"
PASS stepUpExplicitBounds(null, null, "foo", "0") is "1"
PASS stepUpExplicitBounds(null, null, "0", "1") is "2"
PASS stepUpExplicitBounds(null, null, "-1", "2") is "3"
PASS stepDownExplicitBounds(null, null, "foo", "1") is "0"
PASS stepDownExplicitBounds(null, null, "0", "2") is "1"
PASS stepDownExplicitBounds(null, null, "-1", "3") is "2"
Step=any
PASS stepUp("0", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepDown("0", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepUpExplicitBounds(null, null, "any", "1") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepDownExplicitBounds(null, null, "any", "1") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
Overflow/underflow
PASS stepDown("1", "1", "0") is "0"
PASS stepDown("0", "1", "0") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepDown("1", "1", "0", 2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepUpExplicitBounds(null, "100", "1", "99") is "100"
PASS stepUpExplicitBounds(null, "100", "1", "100") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.value is "100"
PASS stepUpExplicitBounds(null, "100", "1", "99", "2") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.value is "99"
PASS stepDownExplicitBounds("0", null, "1", "1") is "0"
PASS stepDownExplicitBounds("0", null, "1", "0") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.value is "0"
PASS stepDownExplicitBounds("0", null, "1", "1", "2") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.value is "1"
PASS stepDown("1", "1.7976931348623156e+308", "", 2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.min = "-100"; stepUp("-1", "1", "0") is "0"
PASS stepUp("0", "1", "0") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.min = "-100"; stepUp("-1", "1", "0", 2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepDownExplicitBounds(null, null, "1.7976931348623156e+308", "1", "2") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepUpExplicitBounds(-100, 0, 1, -1) is "0"
PASS stepUpExplicitBounds(null, 0, 1, 0) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepUpExplicitBounds(-100, 0, 1, -1, 2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS input.value is "-1"
PASS stepUp("1", "1.7976931348623156e+308", "", 2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepUpExplicitBounds(null, null, "1.7976931348623156e+308", "1", "2") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
stepDown()/stepUp() for stepMismatch values
PASS stepUp("1", "2", "") is "4"
PASS stepUpExplicitBounds(null, null, 2, 1) is "4"
PASS input.stepDown(); input.value is "2"
PASS input.min = "0"; stepUp("9", "10", "", 9) is "100"
PASS stepDown("19", "10", "0") is "10"
PASS stepUp("89", "10", "99") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
PASS stepUpExplicitBounds(0, null, 10, 9, 9) is "100"
PASS stepDownExplicitBounds(0, null, 10, 19) is "10"
value + step is <= max, but rounded result would be > max.
PASS stepUpExplicitBounds(null, 99, 10, 89) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
Huge value and small step
PASS input.min = "0"; stepUp("1e+308", "1", "1e+308", 999999) is "1e+308"
PASS input.max = "1e+308"; input.min = "0"; input.step = "1"; input.value = "1e+308"; input.stepDown(999999); input.value is "1e+308"
PASS stepUpExplicitBounds(0, 1e308, 1, 1e308, 999999) is "1e+308"
PASS stepDownExplicitBounds(0, 1e308, 1, 1e308, 999999) is "1e+308"
Fractional numbers
PASS input.min = ""; stepUp("0", "0.33333333333333333", "", 3) is "1"
PASS stepUp("1", "0.1", "", 10) is "2"
PASS stepUpExplicitBounds(null, null, 0.33333333333333333, 0, 3) is "1"
PASS stepUpExplicitBounds(null, null, 0.1, 1) is "1.1"
PASS stepUpExplicitBounds(null, null, 0.1, 1, 8) is "1.8"
PASS stepUpExplicitBounds(null, null, 0.1, 1, 10) is "2"
PASS input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.stepUp(); input.value is "3"
PASS input.min = "0"; stepUp("0", "0.003921568627450980", "1", 255) is "1"
PASS stepUpExplicitBounds(0, 1, 0.003921568627450980, 0, 255) is "1"
PASS for (var i = 0; i < 255; i++) { input.stepDown(); }; input.value is "0"
PASS stepDownExplicitBounds(null, null, 0.1, 1, 8) is "0.2"
PASS stepDownExplicitBounds(null, null, 0.1, 1) is "0.9"

Time type
Invalid value
@@ -0,0 +1,5 @@
This page tests that setting the value of an <input type=range> element to an out-of-range value does not fire the oninput event.


PASS

@@ -0,0 +1,29 @@
<html>
<head>
<script>
var wasLog = false;
function log(msg) {
wasLog = true;
document.getElementById('log').appendChild(document.createTextNode(msg + '\n'));
}

function test() {
if (window.layoutTestController)
layoutTestController.dumpAsText();

var input = document.getElementsByTagName('input')[0]
input.value = 200;
if (!wasLog && input.value === "100")
log('PASS');
}
</script>
</head>
<body onload="test()">
<p>
This page tests that setting the value of an <tt>&lt;input type=range&gt;</tt>
element to an out-of-range value does not fire the <tt>oninput</tt> event.
</p>
<input type=range oninput="log('FAIL')" min=0 max=100 value=50>
<pre id="log"></pre>
</body>
</html>
@@ -3,11 +3,25 @@ Bug 15251: REGRESSION: <input type=range> doesn't respond to form.reset() or set
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".




Slider with explicit limits
Current value is: "30"
PASS slider.value is "80"
Resetting form
PASS slider.value is "30"

Slider with default limits, and no explicit value
Current value is: "50"
PASS slider.value is "80"
Resetting form
PASS slider.value is "50"

Slider with default limits, and a step value
Current value is: "60"
PASS slider.value is "80"
Resetting form
PASS slider.value is "60"

PASS successfullyParsed is true

TEST COMPLETE
@@ -6,6 +6,8 @@
<p id="description"></p>
<form>
<input id="slider" type="range" min="0" max="100" value="30">
<input id="defaults" type="range">
<input id="step" type="range" step="20">
</form>
<div id="console"></div>
<script>
@@ -16,17 +18,31 @@
return "\"" + n + "\"";
}

var slider = document.getElementById("slider");
var slider; // Global needed for eval in shouldBe calls.
function testSliderReset(id)
{
slider = document.getElementById(id);
var originalValue = quoteNumber(slider.value);
debug("Current value is: " + originalValue);

slider.value = 80;
shouldBe("slider.value", quoteNumber(80));

debug("Resetting form");
document.forms[0].reset();
shouldBe("slider.value", originalValue);

debug("");
}

var originalValue = quoteNumber(slider.value);
debug("Current value is: " + originalValue);
debug("Slider with explicit limits");
testSliderReset("slider");

slider.value = 80;
shouldBe("slider.value", quoteNumber(80));
debug("Slider with default limits, and no explicit value");
testSliderReset("defaults");

debug("Resetting form");
document.forms[0].reset();
shouldBe("slider.value", originalValue);
debug("Slider with default limits, and a step value");
testSliderReset("step");

var successfullyParsed = true;
</script>
@@ -142,32 +142,6 @@ checkOverflow('101', '1E+2');
input.min = '200'; // value < min && value > max
checkOverflow('101', '100');

// ----------------------------------------------------------------
debug('');
debug('Type=range');
input.type = 'range';
input.min = '';
checkNotOverflow('99', '100'); // Very normal case.
checkNotOverflow('-101', '-100');
checkNotOverflow('99', '1E+2');
checkNotOverflow('0.99', '1.00');
checkNotOverflow('abc', '100'); // Invalid value.
checkNotOverflow('', '-1'); // No value.
// The following case should be rangeOverflow==true ideally. But the "double" type doesn't have enough precision.
checkNotOverflow('0.999999999999999999999999999999999999999999', '0.999999999999999999999999999999999999999998');
input.min = '200'; // If min > max, max is reset to min.
checkNotOverflow('101', '100');
input.min = '';

// Overflow cases
checkOverflow('101', '100');
input.min = '-200';
checkOverflow('-99', '-100');
input.min = '';
checkOverflow('101', '1E+2');
checkOverflow('101', ''); // No max.
checkOverflow('101', 'xxx'); // Invalid max.

// ----------------------------------------------------------------
debug('');
debug('Type=time');
@@ -152,31 +152,6 @@ checkUnderflow('99', '1E+2');
input.max = '100'; // value < min && value > max
checkUnderflow('101', '200');

// ----------------------------------------------------------------
debug('');
debug('Type=range');
input.type = 'range';
input.max = '';
// No underflow cases
checkNotUnderflow('101', '100'); // Very normal case.
checkNotUnderflow('-99', '-100');
checkNotUnderflow('101', '1E+2');
checkNotUnderflow('1.01', '1.00');
checkNotUnderflow('abc', '100'); // Invalid value.
checkNotUnderflow('', '1'); // No value.
// The following case should be rangeUnderflow==true ideally. But the "double" type doesn't have enough precision.
checkNotUnderflow('0.999999999999999999999999999999999999999998', '0.999999999999999999999999999999999999999999');
input.max = '0'; // If min > max, max is reset to min and min is not changed.
checkNotUnderflow('101', '100');
input.max = '';

// Underflow cases
checkUnderflow('99', '100');
checkUnderflow('-101', '-100');
checkUnderflow('99', '1E+2');
checkUnderflow('-1', ''); // No min.
checkUnderflow('-1', 'xxx'); // Invalid min.

// ----------------------------------------------------------------
debug('');
debug('Type=time');

0 comments on commit 923f2ba

Please sign in to comment.