2010-02-11 Kent Tamura <tkent@chromium.org>
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Feb 2010 08:34:10 +0000 (08:34 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Feb 2010 08:34:10 +0000 (08:34 +0000)
        Reviewed by Darin Adler.

        Step attribute support for date&time types.
        https://bugs.webkit.org/show_bug.cgi?id=30847

        Add tests for ValidityState.stepMismatch, stepUp() and stepDown()
        for date, datetime, datetime-local, month, time, week types.
        Update valueAsDate and valueAsNumber tests for a string representation
        change.

        * fast/forms/ValidityState-stepMismatch-expected.txt: Added.
        * fast/forms/ValidityState-stepMismatch.html: Added.
        * fast/forms/input-stepup-stepdown-expected.txt: Added.
        * fast/forms/input-stepup-stepdown.html: Added.
        * fast/forms/input-valueasdate-datetime-expected.txt:
        * fast/forms/input-valueasdate-time-expected.txt:
        * fast/forms/input-valueasnumber-datetime-expected.txt:
        * fast/forms/input-valueasnumber-datetimelocal-expected.txt:
        * fast/forms/input-valueasnumber-time-expected.txt:
        * fast/forms/script-tests/ValidityState-stepMismatch.js: Added.
        * fast/forms/script-tests/input-stepup-stepdown.js: Added.
        * fast/forms/script-tests/input-valueasdate-datetime.js:
        * fast/forms/script-tests/input-valueasnumber-datetime.js:

2010-02-11  Kent Tamura  <tkent@chromium.org>

        Reviewed by Darin Adler.

        Step attribute support for date&time types.
        https://bugs.webkit.org/show_bug.cgi?id=30847

        - Add implementation for ValidityState.stepMismatch, stepUp() and
          stepDown() for date, datetime, datetime-local, month, time, week types.
        - Fix string representation of DateComponents.

        Tests: fast/forms/ValidityState-stepMismatch.html
               fast/forms/input-stepup-stepdown.html

        * html/HTMLInputElement.cpp:
          - Change monthDefaultMaximum so that DateComponents::m_year doesn't overflow.
        (WebCore::HTMLInputElement::stepBase):
        (WebCore::HTMLInputElement::stepMismatch):
        (WebCore::HTMLInputElement::getStepParameters):
        (WebCore::HTMLInputElement::getAllowedValueStep):
        (WebCore::HTMLInputElement::applyStep):
          Renamed from applyStepForNumberOrRange(), and add support for other types.
        (WebCore::HTMLInputElement::stepUp): Rename applyStepForNumberOrRange().
        (WebCore::HTMLInputElement::stepDown): Rename applyStepForNumberOrRange().
        (WebCore::HTMLInputElement::setValueAsDate): Use setDateValue().
        (WebCore::HTMLInputElement::setDateValue):
          A helper function to make the best representation of DateComponents.
        (WebCore::HTMLInputElement::setValueAsNumber):  Use setDateValue().
        * html/HTMLInputElement.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@54647 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/ValidityState-stepMismatch-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/ValidityState-stepMismatch.html [new file with mode: 0644]
LayoutTests/fast/forms/input-stepup-stepdown-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/input-stepup-stepdown.html [new file with mode: 0644]
LayoutTests/fast/forms/input-valueasdate-datetime-expected.txt
LayoutTests/fast/forms/input-valueasdate-time-expected.txt
LayoutTests/fast/forms/input-valueasnumber-datetime-expected.txt
LayoutTests/fast/forms/input-valueasnumber-datetimelocal-expected.txt
LayoutTests/fast/forms/input-valueasnumber-time-expected.txt
LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch.js [new file with mode: 0644]
LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js [new file with mode: 0644]
LayoutTests/fast/forms/script-tests/input-valueasdate-datetime.js
LayoutTests/fast/forms/script-tests/input-valueasnumber-datetime.js
WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp
WebCore/html/HTMLInputElement.h

index 7c4668a..f966ec4 100644 (file)
@@ -1,3 +1,29 @@
+2010-02-11  Kent Tamura  <tkent@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Step attribute support for date&time types.
+        https://bugs.webkit.org/show_bug.cgi?id=30847
+
+        Add tests for ValidityState.stepMismatch, stepUp() and stepDown()
+        for date, datetime, datetime-local, month, time, week types.
+        Update valueAsDate and valueAsNumber tests for a string representation
+        change.
+
+        * fast/forms/ValidityState-stepMismatch-expected.txt: Added.
+        * fast/forms/ValidityState-stepMismatch.html: Added.
+        * fast/forms/input-stepup-stepdown-expected.txt: Added.
+        * fast/forms/input-stepup-stepdown.html: Added.
+        * fast/forms/input-valueasdate-datetime-expected.txt:
+        * fast/forms/input-valueasdate-time-expected.txt:
+        * fast/forms/input-valueasnumber-datetime-expected.txt:
+        * fast/forms/input-valueasnumber-datetimelocal-expected.txt:
+        * fast/forms/input-valueasnumber-time-expected.txt:
+        * fast/forms/script-tests/ValidityState-stepMismatch.js: Added.
+        * fast/forms/script-tests/input-stepup-stepdown.js: Added.
+        * fast/forms/script-tests/input-valueasdate-datetime.js:
+        * fast/forms/script-tests/input-valueasnumber-datetime.js:
+
 2010-02-10  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Gavin Barraclough.
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch-expected.txt b/LayoutTests/fast/forms/ValidityState-stepMismatch-expected.txt
new file mode 100644 (file)
index 0000000..93ac014
--- /dev/null
@@ -0,0 +1,175 @@
+Check stepMismatch results for type=date, datetime, datetime-local, month, time, week.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Date type
+Empty values
+PASS stepMismatchFor("", null, null) is false
+PASS stepMismatchFor("", "2", "1969-12-31") is false
+Normal step values
+PASS stepMismatchFor("2010-02-10", "2", "2010-02-09") is true
+PASS stepMismatchFor("2010-02-09", "2", "2010-02-09") is false
+PASS stepMismatchFor("2010-02-11", "2", "2010-02-09") is false
+PASS stepMismatchFor("1800-11-11", "3", "1800-11-09") is true
+PASS stepMismatchFor("1800-11-09", "3", "1800-11-09") is false
+PASS stepMismatchFor("1800-11-12", "3", "1800-11-09") is false
+PASS stepMismatchFor("275760-09-13", "3", "275760-09-11") is true
+PASS stepMismatchFor("275760-09-13", "2", "275760-09-11") is false
+Implicit step base
+PASS stepMismatchFor("1970-01-02", "2", null) is true
+PASS stepMismatchFor("1970-01-03", "2", null) is false
+Fractional step values
+PASS stepMismatchFor("2010-02-10", "0.1", "2010-02-09") is false
+PASS stepMismatchFor("2010-02-10", "1.1", "2010-02-09") is false
+PASS stepMismatchFor("2010-02-10", "1.9", "2010-02-09") is true
+Invalid or no step values
+PASS stepMismatchFor("2010-02-10", null, "2010-02-09") is false
+PASS stepMismatchFor("2010-02-10", "-1", "2010-02-09") is false
+PASS stepMismatchFor("2010-02-10", "foo", "2010-02-09") is false
+Special step value
+PASS stepMismatchFor("2010-02-10", "any", "2010-02-09") is false
+
+Datetime type
+Empty values
+PASS stepMismatchFor("", null, null) is false
+PASS stepMismatchFor("", "2", "1969-12-31T12:34:56Z") is false
+Normal step values
+PASS stepMismatchFor("2010-02-09T12:34:55Z", "1", "2010-02-09T12:34:56Z") is false
+PASS stepMismatchFor("2010-02-09T12:34:55.001Z", "1", "2010-02-09T12:34:56Z") is true
+PASS stepMismatchFor("2010-02-09T12:34:56.001Z", "0.001", "2010-02-09T12:34:56Z") is false
+PASS stepMismatchFor("2010-02-09T12:34:55Z", "0.333", "2010-02-09T12:34:56Z") is true
+PASS stepMismatchFor("2010-02-09T12:34:55.001Z", "0.333", "2010-02-09T12:34:56Z") is false
+PASS stepMismatchFor("2010-02-09T12:34Z", "86400", "2010-02-08T12:34Z") is false
+PASS stepMismatchFor("2010-02-09T12:34:56Z", "86400", "2010-02-08T12:34Z") is true
+PASS stepMismatchFor("275760-09-13T00:00Z", "3", "275760-09-13T23:50:50Z") is true
+PASS stepMismatchFor("275760-09-13T00:00Z", "2", "275760-09-13T23:50:50Z") is false
+Implicit step base
+PASS stepMismatchFor("1970-01-01T12:34Z", "120", null) is false
+PASS stepMismatchFor("1970-01-01T12:35Z", "120", null) is true
+Small step values
+PASS stepMismatchFor("2010-02-10T12:34:56.000Z", "0.0003", "2010-02-10T12:34.55.000Z") is false
+PASS stepMismatchFor("2010-02-10T12:34:55.001Z", "0.0019", "2010-02-10T12:34.55.000Z") is true
+Invalid or no step values
+PASS stepMismatchFor("2010-02-10T12:34Z", null, "2010-02-09T12:34Z") is false
+PASS stepMismatchFor("2010-02-10T12:34:56Z", null, "2010-02-09T12:34Z") is true
+PASS stepMismatchFor("2010-02-10T12:34Z", "-1", "2010-02-09T12:34Z") is false
+PASS stepMismatchFor("2010-02-10T12:34Z", "foo", "2010-02-09T12:34Z") is false
+Special step value
+PASS stepMismatchFor("2010-02-09T12:34Z", "any", "2010-02-09T12:34Z") is false
+
+Datetime-local type
+Empty values
+PASS stepMismatchFor("", null, null) is false
+PASS stepMismatchFor("", "2", "1969-12-31T12:34:56") is false
+Normal step values
+PASS stepMismatchFor("2010-02-09T12:34:55", "1", "2010-02-09T12:34:56") is false
+PASS stepMismatchFor("2010-02-09T12:34:55.001", "1", "2010-02-09T12:34:56") is true
+PASS stepMismatchFor("2010-02-09T12:34:56.001", "0.001", "2010-02-09T12:34:56") is false
+PASS stepMismatchFor("2010-02-09T12:34:55", "0.333", "2010-02-09T12:34:56") is true
+PASS stepMismatchFor("2010-02-09T12:34:55.001", "0.333", "2010-02-09T12:34:56") is false
+PASS stepMismatchFor("2010-02-09T12:34", "86400", "2010-02-08T12:34") is false
+PASS stepMismatchFor("2010-02-09T12:34:56", "86400", "2010-02-08T12:34") is true
+PASS stepMismatchFor("275760-09-13T00:00", "3", "275760-09-13T23:50:50") is true
+PASS stepMismatchFor("275760-09-13T00:00", "2", "275760-09-13T23:50:50") is false
+Implicit step base
+PASS stepMismatchFor("1970-01-01T12:34", "120", null) is false
+PASS stepMismatchFor("1970-01-01T12:35", "120", null) is true
+Small step values
+PASS stepMismatchFor("2010-02-10T12:34:56.000", "0.0003", "2010-02-10T12:34.55.000") is false
+PASS stepMismatchFor("2010-02-10T12:34:55.001", "0.0019", "2010-02-10T12:34.55.000") is true
+Invalid or no step values
+PASS stepMismatchFor("2010-02-10T12:34", null, "2010-02-09T12:34") is false
+PASS stepMismatchFor("2010-02-10T12:34:56", null, "2010-02-09T12:34") is true
+PASS stepMismatchFor("2010-02-10T12:34", "-1", "2010-02-09T12:34") is false
+PASS stepMismatchFor("2010-02-10T12:34", "foo", "2010-02-09T12:34") is false
+Special step value
+PASS stepMismatchFor("2010-02-09T12:34", "any", "2010-02-09T12:34") is false
+
+Month type
+Empty values
+PASS stepMismatchFor("", null, null) is false
+PASS stepMismatchFor("", "2", "1969-12") is false
+Normal step values
+PASS stepMismatchFor("2010-03", "2", "2010-02") is true
+PASS stepMismatchFor("2010-02", "2", "2010-02") is false
+PASS stepMismatchFor("2010-04", "2", "2010-02") is false
+PASS stepMismatchFor("1800-11", "3", "1800-09") is true
+PASS stepMismatchFor("1800-09", "3", "1800-09") is false
+PASS stepMismatchFor("1800-12", "3", "1800-09") is false
+PASS stepMismatchFor("275760-09", "3", "275760-08") is true
+PASS stepMismatchFor("275760-09", "2", "275760-09") is false
+Implicit step base
+PASS stepMismatchFor("1970-02", "2", null) is true
+PASS stepMismatchFor("1970-03", "2", null) is false
+Fractional step values
+PASS stepMismatchFor("2010-03", "0.1", "2010-02") is false
+PASS stepMismatchFor("2010-03", "1.1", "2010-02") is false
+PASS stepMismatchFor("2010-03", "1.9", "2010-02") is true
+Invalid or no step values
+PASS stepMismatchFor("2010-03", null, "2010-02") is false
+PASS stepMismatchFor("2010-03", "-1", "2010-02") is false
+PASS stepMismatchFor("2010-03", "foo", "2010-02") is false
+Special step value
+PASS stepMismatchFor("2010-03", "any", "2010-02") is false
+
+Time type
+Empty values
+PASS stepMismatchFor("", null, null) is false
+PASS stepMismatchFor("", "2", "12:34:56") is false
+Normal step values
+PASS stepMismatchFor("12:34:55", "1", "12:34:56") is false
+PASS stepMismatchFor("12:34:55.001", "1", "12:34:56") is true
+PASS stepMismatchFor("12:34:56.001", "0.001", "12:34:56") is false
+PASS stepMismatchFor("12:34:55", "0.333", "12:34:56") is true
+PASS stepMismatchFor("12:34:55.001", "0.333", "12:34:56") is false
+PASS stepMismatchFor("12:34", "86400", "12:34") is false
+PASS stepMismatchFor("23:59:59.998", "86399.999", "00:00") is true
+PASS stepMismatchFor("23:59:59.999", "86399.999", "00:00") is false
+Implicit step base
+PASS stepMismatchFor("12:34", "120", null) is false
+PASS stepMismatchFor("12:35", "120", null) is true
+Small step values
+PASS stepMismatchFor("12:34:55.001", "0.0003", "12:34.55.000") is false
+PASS stepMismatchFor("12:34:55.001", "0.0019", "12:34.55.000") is true
+PASS stepMismatchFor("12:34:55.004", "0.0019", "12:34.55.000") is false
+Invalid or no step values
+PASS stepMismatchFor("12:34", null, "12:34") is false
+PASS stepMismatchFor("12:34:56", null, "12:34") is true
+PASS stepMismatchFor("12:34", "-1", "12:34") is false
+PASS stepMismatchFor("12:34", "foo", "12:34") is false
+Special step value
+PASS stepMismatchFor("12:35", "any", "12:34") is false
+
+Week type
+Empty values
+PASS stepMismatchFor("", null, null) is false
+PASS stepMismatchFor("", "2", "1970-W02") is false
+Normal step values
+PASS stepMismatchFor("2010-W03", "2", "2010-W02") is true
+PASS stepMismatchFor("2010-W02", "2", "2010-W02") is false
+PASS stepMismatchFor("2010-W04", "2", "2010-W02") is false
+PASS stepMismatchFor("1800-W11", "3", "1800-W09") is true
+PASS stepMismatchFor("1800-W09", "3", "1800-W09") is false
+PASS stepMismatchFor("1800-W12", "3", "1800-W09") is false
+PASS stepMismatchFor("275760-W35", "3", "275760-W33") is true
+PASS stepMismatchFor("275760-W35", "2", "275760-W33") is false
+Implicit step base
+PASS stepMismatchFor("1970-W01", "2", null) is false
+PASS stepMismatchFor("1970-W02", "2", null) is true
+PASS stepMismatchFor("1970-W03", "2", null) is false
+PASS stepMismatchFor("1970-W04", "2", null) is true
+Fractional step values
+PASS stepMismatchFor("2010-W03", "0.1", "2010-W02") is false
+PASS stepMismatchFor("2010-W03", "1.1", "2010-W02") is false
+PASS stepMismatchFor("2010-W03", "1.9", "2010-W02") is true
+Invalid or no step values
+PASS stepMismatchFor("2010-W03", null, "2010-W02") is false
+PASS stepMismatchFor("2010-W03", "-1", "2010-W02") is false
+PASS stepMismatchFor("2010-W03", "foo", "2010-W02") is false
+Special step value
+PASS stepMismatchFor("2010-W03", "any", "2010-W02") is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/ValidityState-stepMismatch.html b/LayoutTests/fast/forms/ValidityState-stepMismatch.html
new file mode 100644 (file)
index 0000000..e5074b0
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/ValidityState-stepMismatch.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/forms/input-stepup-stepdown-expected.txt b/LayoutTests/fast/forms/input-stepup-stepdown-expected.txt
new file mode 100644 (file)
index 0000000..735749d
--- /dev/null
@@ -0,0 +1,172 @@
+Check stepUp() and stepDown() bahevior for type=date, datetime, datetime-local, month, time, week.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Date 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("2010-02-10", null, null, "0") is "2010-02-10"
+PASS stepDown("2010-02-10", null, null, "0") is "2010-02-10"
+PASS stepUp("2010-02-10", null, null, "foo") is "2010-02-10"
+PASS stepDown("2010-02-10", null, null, "foo") is "2010-02-10"
+PASS stepUp("2010-02-10", null, null, null) is "2010-02-10"
+PASS stepDown("2010-02-10", null, null, null) is "2010-02-10"
+Normal cases
+PASS stepUp("2010-02-10", null, null) is "2010-02-11"
+PASS stepDown("2010-02-10", null, null) is "2010-02-09"
+PASS stepUp("2010-02-10", null, null, 10) is "2010-02-20"
+PASS stepDown("2010-02-10", null, null, 11) is "2010-01-30"
+PASS stepUp("1970-01-01", "4", null, 2) is "1970-01-09"
+PASS stepDown("1970-01-01", "4", null, 3) is "1969-12-20"
+Step=any
+PASS stepUp("2010-02-10", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Overflow/underflow
+PASS stepUp("2010-02-10", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("2010-02-10", "1", "2010-02-10") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10", "1", "2010-02-10") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+
+Datetime 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("2010-02-10T20:13Z", null, null, "0") is "2010-02-10T20:13Z"
+PASS stepDown("2010-02-10T20:13Z", null, null, "0") is "2010-02-10T20:13Z"
+PASS stepUp("2010-02-10T20:13Z", null, null, "foo") is "2010-02-10T20:13Z"
+PASS stepDown("2010-02-10T20:13Z", null, null, "foo") is "2010-02-10T20:13Z"
+PASS stepUp("2010-02-10T20:13Z", null, null, null) is "2010-02-10T20:13Z"
+PASS stepDown("2010-02-10T20:13Z", null, null, null) is "2010-02-10T20:13Z"
+Normal cases
+PASS stepUp("2010-02-10T20:13Z", null, null) is "2010-02-10T20:14Z"
+PASS stepDown("2010-02-10T20:13Z", null, null) is "2010-02-10T20:12Z"
+PASS stepUp("2010-02-10T20:13Z", null, null, 10) is "2010-02-10T20:23Z"
+PASS stepDown("2010-02-10T20:13Z", null, null, 11) is "2010-02-10T20:02Z"
+PASS stepUp("1970-01-01T20:13Z", "4", null, 2) is "1970-01-01T20:13:08Z"
+PASS stepDown("1970-01-01T20:13Z", "4", null, 3) is "1970-01-01T20:12:48Z"
+Step=any
+PASS stepUp("2010-02-10T20:13Z", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10T20:13Z", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Overflow/underflow
+PASS stepUp("2010-02-10T20:13Z", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10T20:13Z", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("2010-02-10T20:13Z", "1", "2010-02-10T20:13Z") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10T20:13Z", "1", "2010-02-10T20:13Z") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+
+Datetime-local 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("2010-02-10T20:13", null, null, "0") is "2010-02-10T20:13"
+PASS stepDown("2010-02-10T20:13", null, null, "0") is "2010-02-10T20:13"
+PASS stepUp("2010-02-10T20:13", null, null, "foo") is "2010-02-10T20:13"
+PASS stepDown("2010-02-10T20:13", null, null, "foo") is "2010-02-10T20:13"
+PASS stepUp("2010-02-10T20:13", null, null, null) is "2010-02-10T20:13"
+PASS stepDown("2010-02-10T20:13", null, null, null) is "2010-02-10T20:13"
+Normal cases
+PASS stepUp("2010-02-10T20:13", null, null) is "2010-02-10T20:14"
+PASS stepDown("2010-02-10T20:13", null, null) is "2010-02-10T20:12"
+PASS stepUp("2010-02-10T20:13", null, null, 10) is "2010-02-10T20:23"
+PASS stepDown("2010-02-10T20:13", null, null, 11) is "2010-02-10T20:02"
+PASS stepUp("1970-01-01T20:13", "4", null, 2) is "1970-01-01T20:13:08"
+PASS stepDown("1970-01-01T20:13", "4", null, 3) is "1970-01-01T20:12:48"
+Step=any
+PASS stepUp("2010-02-10T20:13", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10T20:13", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Overflow/underflow
+PASS stepUp("2010-02-10T20:13", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10T20:13", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("2010-02-10T20:13", "1", "2010-02-10T20:13") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02-10T20:13", "1", "2010-02-10T20:13") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+
+Month 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("2010-02", null, null, "0") is "2010-02"
+PASS stepDown("2010-02", null, null, "0") is "2010-02"
+PASS stepUp("2010-02", null, null, "foo") is "2010-02"
+PASS stepDown("2010-02", null, null, "foo") is "2010-02"
+PASS stepUp("2010-02", null, null, null) is "2010-02"
+PASS stepDown("2010-02", null, null, null) is "2010-02"
+Normal cases
+PASS stepUp("2010-02", null, null) is "2010-03"
+PASS stepDown("2010-02", null, null) is "2010-01"
+PASS stepUp("2010-02", null, null, 10) is "2010-12"
+PASS stepDown("2010-02", null, null, 11) is "2009-03"
+PASS stepUp("1970-01", "4", null, 2) is "1970-09"
+PASS stepDown("1970-01", "4", null, 3) is "1969-01"
+Step=any
+PASS stepUp("2010-02", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Overflow/underflow
+PASS stepUp("2010-02", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("2010-02", "1", "2010-02") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-02", "1", "2010-02") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+
+Time 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("20:13", null, null, "0") is "20:13"
+PASS stepDown("20:13", null, null, "0") is "20:13"
+PASS stepUp("20:13", null, null, "foo") is "20:13"
+PASS stepDown("20:13", null, null, "foo") is "20:13"
+PASS stepUp("20:13", null, null, null) is "20:13"
+PASS stepDown("20:13", null, null, null) is "20:13"
+Normal cases
+PASS stepUp("20:13", null, null) is "20:14"
+PASS stepDown("20:13", null, null) is "20:12"
+PASS stepUp("20:13", null, null, 10) is "20:23"
+PASS stepDown("20:13", null, null, 11) is "20:02"
+PASS stepUp("20:13", "4", null, 2) is "20:13:08"
+PASS stepDown("20:13", "4", null, 3) is "20:12:48"
+Step=any
+PASS stepUp("20:13", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("20:13", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Overflow/underflow
+PASS stepUp("20:13", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("20:13", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("20:13", "1", "20:13") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("20:13", "1", "20:13") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("23:59", null, null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("00:00", null, null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+
+Week 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("2010-W02", null, null, "0") is "2010-W02"
+PASS stepDown("2010-W02", null, null, "0") is "2010-W02"
+PASS stepUp("2010-W02", null, null, "foo") is "2010-W02"
+PASS stepDown("2010-W02", null, null, "foo") is "2010-W02"
+PASS stepUp("2010-W02", null, null, null) is "2010-W02"
+PASS stepDown("2010-W02", null, null, null) is "2010-W02"
+Normal cases
+PASS stepUp("2010-W02", null, null) is "2010-W03"
+PASS stepDown("2010-W02", null, null) is "2010-W01"
+PASS stepUp("2010-W02", null, null, 10) is "2010-W12"
+PASS stepDown("2010-W02", null, null, 11) is "2009-W44"
+PASS stepUp("1970-W01", "4", null, 2) is "1970-W09"
+PASS stepDown("1970-W01", "4", null, 3) is "1969-W41"
+Step=any
+PASS stepUp("2010-W02", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-W02", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+Overflow/underflow
+PASS stepUp("2010-W02", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-W02", "1.7976931348623156e+308", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepUp("2010-W02", "1", "2010-W02") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS stepDown("2010-W02", "1", "2010-W02") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/input-stepup-stepdown.html b/LayoutTests/fast/forms/input-stepup-stepdown.html
new file mode 100644 (file)
index 0000000..043b987
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/input-stepup-stepdown.js"></script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index b872c1f..033412c 100644 (file)
@@ -20,8 +20,8 @@ Invalid objects:
 PASS input.value = "2010-01-01T00:00Z"; input.valueAsDate = document; input.value is ""
 PASS input.value = "2010-01-01T00:00Z"; input.valueAsDate = null; input.value is ""
 Step attribute value and string representation:
-FAIL input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00. Was 2010-01-21T00:00Z.
-FAIL input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00.000. Was 2010-01-21T00:00Z.
+PASS input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00Z"
+PASS input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00.000Z"
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 9d02aaf..c970b1c 100644 (file)
@@ -22,8 +22,8 @@ Invalid objects:
 PASS input.value = "00:00"; input.valueAsDate = document; input.value is ""
 PASS input.value = "00:00"; input.valueAsDate = null; input.value is ""
 Step attribute value and string representation:
-FAIL input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00. Was 00:00.
-FAIL input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0) should be 00:00:00.000. Was 00:00.
+PASS input.step = "1"; setValueAsDateAndGetValue(0, 0, 0, 0) is "00:00:00"
+PASS input.step = "0.001"; setValueAsDateAndGetValue(0, 0, 0, 0) is "00:00:00.000"
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 02828fb..81e4b1f 100644 (file)
@@ -25,8 +25,8 @@ PASS input.valueAsNumber = Infinity threw exception Error: NOT_SUPPORTED_ERR: DO
 PASS input.valueAsNumber = Number.POSITIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 PASS input.valueAsNumber = Number.NEGATIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 Step attribute value and string representation:
-FAIL input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00. Was 2010-01-21T00:00Z.
-FAIL input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00.000. Was 2010-01-21T00:00Z.
+PASS input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00Z"
+PASS input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00.000Z"
 PASS successfullyParsed is true
 
 TEST COMPLETE
index 6fab9d0..c154d49 100644 (file)
@@ -24,8 +24,8 @@ PASS input.valueAsNumber = Infinity threw exception Error: NOT_SUPPORTED_ERR: DO
 PASS input.valueAsNumber = Number.POSITIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 PASS input.valueAsNumber = Number.NEGATIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 Step attribute value and string representation:
-FAIL input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00. Was 2010-01-21T00:00.
-FAIL input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) should be 2010-01-21T00:00:00.000. Was 2010-01-21T00:00.
+PASS input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00"
+PASS input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0) is "2010-01-21T00:00:00.000"
 PASS successfullyParsed is true
 
 TEST COMPLETE
index e3c94dd..bf90f36 100644 (file)
@@ -25,8 +25,8 @@ PASS input.valueAsNumber = Infinity threw exception Error: NOT_SUPPORTED_ERR: DO
 PASS input.valueAsNumber = Number.POSITIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 PASS input.valueAsNumber = Number.NEGATIVE_INFINITY threw exception Error: NOT_SUPPORTED_ERR: DOM Exception 9.
 Step attribute value and string representation:
-FAIL input.step = "1"; setValueAsNumberAndGetValue(0, 0, 0, 0) should be 00:00:00. Was 00:00.
-FAIL input.step = "0.001"; setValueAsNumberAndGetValue(0, 0, 0, 0) should be 00:00:00.000. Was 00:00.
+PASS input.step = "1"; setValueAsNumberAndGetValue(0, 0, 0, 0) is "00:00:00"
+PASS input.step = "0.001"; setValueAsNumberAndGetValue(0, 0, 0, 0) is "00:00:00.000"
 PASS successfullyParsed is true
 
 TEST COMPLETE
diff --git a/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch.js b/LayoutTests/fast/forms/script-tests/ValidityState-stepMismatch.js
new file mode 100644 (file)
index 0000000..440751d
--- /dev/null
@@ -0,0 +1,191 @@
+description('Check stepMismatch results for type=date, datetime, datetime-local, month, time, week.');
+// FIXME: Merge other ValidityState-stepMismatch-* into this.
+
+var input = document.createElement('input');
+
+function stepMismatchFor(value, step, min) {
+    input.value = value;
+    input.step = step;
+    input.min = min;
+    return input.validity.stepMismatch;
+}
+
+debug('Date type');
+input.type = 'date';
+debug('Empty values');
+shouldBeFalse('stepMismatchFor("", null, null)');
+shouldBeFalse('stepMismatchFor("", "2", "1969-12-31")');
+debug('Normal step values');
+shouldBeTrue('stepMismatchFor("2010-02-10", "2", "2010-02-09")');
+shouldBeFalse('stepMismatchFor("2010-02-09", "2", "2010-02-09")');
+shouldBeFalse('stepMismatchFor("2010-02-11", "2", "2010-02-09")');
+shouldBeTrue('stepMismatchFor("1800-11-11", "3", "1800-11-09")');
+shouldBeFalse('stepMismatchFor("1800-11-09", "3", "1800-11-09")');
+shouldBeFalse('stepMismatchFor("1800-11-12", "3", "1800-11-09")');
+shouldBeTrue('stepMismatchFor("275760-09-13", "3", "275760-09-11")');
+shouldBeFalse('stepMismatchFor("275760-09-13", "2", "275760-09-11")');
+debug('Implicit step base');
+shouldBeTrue('stepMismatchFor("1970-01-02", "2", null)');
+shouldBeFalse('stepMismatchFor("1970-01-03", "2", null)');
+debug('Fractional step values');
+shouldBeFalse('stepMismatchFor("2010-02-10", "0.1", "2010-02-09")');
+shouldBeFalse('stepMismatchFor("2010-02-10", "1.1", "2010-02-09")');
+shouldBeTrue('stepMismatchFor("2010-02-10", "1.9", "2010-02-09")');
+debug('Invalid or no step values');
+shouldBeFalse('stepMismatchFor("2010-02-10", null, "2010-02-09")');
+shouldBeFalse('stepMismatchFor("2010-02-10", "-1", "2010-02-09")');
+shouldBeFalse('stepMismatchFor("2010-02-10", "foo", "2010-02-09")');
+debug('Special step value');
+shouldBeFalse('stepMismatchFor("2010-02-10", "any", "2010-02-09")');
+
+debug('');
+debug('Datetime type');
+input.type = 'datetime';
+debug('Empty values');
+shouldBeFalse('stepMismatchFor("", null, null)');
+shouldBeFalse('stepMismatchFor("", "2", "1969-12-31T12:34:56Z")');
+debug('Normal step values');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55Z", "1", "2010-02-09T12:34:56Z")');
+shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55.001Z", "1", "2010-02-09T12:34:56Z")');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34:56.001Z", "0.001", "2010-02-09T12:34:56Z")');
+shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55Z", "0.333", "2010-02-09T12:34:56Z")');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55.001Z", "0.333", "2010-02-09T12:34:56Z")');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34Z", "86400", "2010-02-08T12:34Z")');
+shouldBeTrue('stepMismatchFor("2010-02-09T12:34:56Z", "86400", "2010-02-08T12:34Z")');
+shouldBeTrue('stepMismatchFor("275760-09-13T00:00Z", "3", "275760-09-13T23:50:50Z")');
+shouldBeFalse('stepMismatchFor("275760-09-13T00:00Z", "2", "275760-09-13T23:50:50Z")');
+debug('Implicit step base');
+shouldBeFalse('stepMismatchFor("1970-01-01T12:34Z", "120", null)');
+shouldBeTrue('stepMismatchFor("1970-01-01T12:35Z", "120", null)');
+debug('Small step values');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34:56.000Z", "0.0003", "2010-02-10T12:34.55.000Z")');
+shouldBeTrue('stepMismatchFor("2010-02-10T12:34:55.001Z", "0.0019", "2010-02-10T12:34.55.000Z")');
+debug('Invalid or no step values');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34Z", null, "2010-02-09T12:34Z")');
+shouldBeTrue('stepMismatchFor("2010-02-10T12:34:56Z", null, "2010-02-09T12:34Z")');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34Z", "-1", "2010-02-09T12:34Z")');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34Z", "foo", "2010-02-09T12:34Z")');
+debug('Special step value');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34Z", "any", "2010-02-09T12:34Z")');
+
+debug('');
+debug('Datetime-local type');
+input.type = 'datetime-local';
+debug('Empty values');
+shouldBeFalse('stepMismatchFor("", null, null)');
+shouldBeFalse('stepMismatchFor("", "2", "1969-12-31T12:34:56")');
+debug('Normal step values');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55", "1", "2010-02-09T12:34:56")');
+shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55.001", "1", "2010-02-09T12:34:56")');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34:56.001", "0.001", "2010-02-09T12:34:56")');
+shouldBeTrue('stepMismatchFor("2010-02-09T12:34:55", "0.333", "2010-02-09T12:34:56")');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34:55.001", "0.333", "2010-02-09T12:34:56")');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34", "86400", "2010-02-08T12:34")');
+shouldBeTrue('stepMismatchFor("2010-02-09T12:34:56", "86400", "2010-02-08T12:34")');
+shouldBeTrue('stepMismatchFor("275760-09-13T00:00", "3", "275760-09-13T23:50:50")');
+shouldBeFalse('stepMismatchFor("275760-09-13T00:00", "2", "275760-09-13T23:50:50")');
+debug('Implicit step base');
+shouldBeFalse('stepMismatchFor("1970-01-01T12:34", "120", null)');
+shouldBeTrue('stepMismatchFor("1970-01-01T12:35", "120", null)');
+debug('Small step values');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34:56.000", "0.0003", "2010-02-10T12:34.55.000")');
+shouldBeTrue('stepMismatchFor("2010-02-10T12:34:55.001", "0.0019", "2010-02-10T12:34.55.000")');
+debug('Invalid or no step values');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34", null, "2010-02-09T12:34")');
+shouldBeTrue('stepMismatchFor("2010-02-10T12:34:56", null, "2010-02-09T12:34")');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34", "-1", "2010-02-09T12:34")');
+shouldBeFalse('stepMismatchFor("2010-02-10T12:34", "foo", "2010-02-09T12:34")');
+debug('Special step value');
+shouldBeFalse('stepMismatchFor("2010-02-09T12:34", "any", "2010-02-09T12:34")');
+
+debug('');
+debug('Month type');
+input.type = 'month';
+debug('Empty values');
+shouldBeFalse('stepMismatchFor("", null, null)');
+shouldBeFalse('stepMismatchFor("", "2", "1969-12")');
+debug('Normal step values');
+shouldBeTrue('stepMismatchFor("2010-03", "2", "2010-02")');
+shouldBeFalse('stepMismatchFor("2010-02", "2", "2010-02")');
+shouldBeFalse('stepMismatchFor("2010-04", "2", "2010-02")');
+shouldBeTrue('stepMismatchFor("1800-11", "3", "1800-09")');
+shouldBeFalse('stepMismatchFor("1800-09", "3", "1800-09")');
+shouldBeFalse('stepMismatchFor("1800-12", "3", "1800-09")');
+shouldBeTrue('stepMismatchFor("275760-09", "3", "275760-08")');
+shouldBeFalse('stepMismatchFor("275760-09", "2", "275760-09")');
+debug('Implicit step base');
+shouldBeTrue('stepMismatchFor("1970-02", "2", null)');
+shouldBeFalse('stepMismatchFor("1970-03", "2", null)');
+debug('Fractional step values');
+shouldBeFalse('stepMismatchFor("2010-03", "0.1", "2010-02")');
+shouldBeFalse('stepMismatchFor("2010-03", "1.1", "2010-02")');
+shouldBeTrue('stepMismatchFor("2010-03", "1.9", "2010-02")');
+debug('Invalid or no step values');
+shouldBeFalse('stepMismatchFor("2010-03", null, "2010-02")');
+shouldBeFalse('stepMismatchFor("2010-03", "-1", "2010-02")');
+shouldBeFalse('stepMismatchFor("2010-03", "foo", "2010-02")');
+debug('Special step value');
+shouldBeFalse('stepMismatchFor("2010-03", "any", "2010-02")');
+
+debug('');
+debug('Time type');
+input.type = 'time';
+debug('Empty values');
+shouldBeFalse('stepMismatchFor("", null, null)');
+shouldBeFalse('stepMismatchFor("", "2", "12:34:56")');
+debug('Normal step values');
+shouldBeFalse('stepMismatchFor("12:34:55", "1", "12:34:56")');
+shouldBeTrue('stepMismatchFor("12:34:55.001", "1", "12:34:56")');
+shouldBeFalse('stepMismatchFor("12:34:56.001", "0.001", "12:34:56")');
+shouldBeTrue('stepMismatchFor("12:34:55", "0.333", "12:34:56")');
+shouldBeFalse('stepMismatchFor("12:34:55.001", "0.333", "12:34:56")');
+shouldBeFalse('stepMismatchFor("12:34", "86400", "12:34")');
+shouldBeTrue('stepMismatchFor("23:59:59.998", "86399.999", "00:00")');
+shouldBeFalse('stepMismatchFor("23:59:59.999", "86399.999", "00:00")');
+debug('Implicit step base');
+shouldBeFalse('stepMismatchFor("12:34", "120", null)');
+shouldBeTrue('stepMismatchFor("12:35", "120", null)');
+debug('Small step values');
+shouldBeFalse('stepMismatchFor("12:34:55.001", "0.0003", "12:34.55.000")');
+shouldBeTrue('stepMismatchFor("12:34:55.001", "0.0019", "12:34.55.000")');
+shouldBeFalse('stepMismatchFor("12:34:55.004", "0.0019", "12:34.55.000")');
+debug('Invalid or no step values');
+shouldBeFalse('stepMismatchFor("12:34", null, "12:34")');
+shouldBeTrue('stepMismatchFor("12:34:56", null, "12:34")');
+shouldBeFalse('stepMismatchFor("12:34", "-1", "12:34")');
+shouldBeFalse('stepMismatchFor("12:34", "foo", "12:34")');
+debug('Special step value');
+shouldBeFalse('stepMismatchFor("12:35", "any", "12:34")');
+
+debug('');
+debug('Week type');
+input.type = 'week';
+debug('Empty values');
+shouldBeFalse('stepMismatchFor("", null, null)');
+shouldBeFalse('stepMismatchFor("", "2", "1970-W02")');
+debug('Normal step values');
+shouldBeTrue('stepMismatchFor("2010-W03", "2", "2010-W02")');
+shouldBeFalse('stepMismatchFor("2010-W02", "2", "2010-W02")');
+shouldBeFalse('stepMismatchFor("2010-W04", "2", "2010-W02")');
+shouldBeTrue('stepMismatchFor("1800-W11", "3", "1800-W09")');
+shouldBeFalse('stepMismatchFor("1800-W09", "3", "1800-W09")');
+shouldBeFalse('stepMismatchFor("1800-W12", "3", "1800-W09")');
+shouldBeTrue('stepMismatchFor("275760-W35", "3", "275760-W33")');
+shouldBeFalse('stepMismatchFor("275760-W35", "2", "275760-W33")');
+debug('Implicit step base');
+shouldBeFalse('stepMismatchFor("1970-W01", "2", null)');
+shouldBeTrue('stepMismatchFor("1970-W02", "2", null)');
+shouldBeFalse('stepMismatchFor("1970-W03", "2", null)');
+shouldBeTrue('stepMismatchFor("1970-W04", "2", null)');
+debug('Fractional step values');
+shouldBeFalse('stepMismatchFor("2010-W03", "0.1", "2010-W02")');
+shouldBeFalse('stepMismatchFor("2010-W03", "1.1", "2010-W02")');
+shouldBeTrue('stepMismatchFor("2010-W03", "1.9", "2010-W02")');
+debug('Invalid or no step values');
+shouldBeFalse('stepMismatchFor("2010-W03", null, "2010-W02")');
+shouldBeFalse('stepMismatchFor("2010-W03", "-1", "2010-W02")');
+shouldBeFalse('stepMismatchFor("2010-W03", "foo", "2010-W02")');
+debug('Special step value');
+shouldBeFalse('stepMismatchFor("2010-W03", "any", "2010-W02")');
+
+var successfullyParsed = true;
diff --git a/LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js b/LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js
new file mode 100644 (file)
index 0000000..16207b7
--- /dev/null
@@ -0,0 +1,206 @@
+description('Check stepUp() and stepDown() bahevior for type=date, datetime, datetime-local, month, time, week.');
+// FIXME: Merge input-step-* into this.
+
+var input = document.createElement('input');
+var invalidStateErr = '"Error: INVALID_STATE_ERR: DOM Exception 11"';
+
+function stepUp(value, step, max, optionalStepCount) {
+    input.value = value;
+    input.step = step;
+    input.min = null;
+    input.max = max;
+    if (typeof optionalStepCount != "undefined")
+        input.stepUp(optionalStepCount);
+    else
+        input.stepUp();
+    return input.value;
+}
+
+function stepDown(value, step, min, optionalStepCount) {
+    input.value = value;
+    input.step = step;
+    input.min = min;
+    input.max = null;
+    if (typeof optionalStepCount != "undefined")
+        input.stepDown(optionalStepCount);
+    else
+        input.stepDown();
+    return input.value;
+}
+
+debug('Date type');
+input.type = 'date';
+debug('Invalid value');
+shouldThrow('stepUp("", null, null)', invalidStateErr);
+shouldThrow('stepDown("", null, null)', invalidStateErr);
+debug('Non-number arguments');
+shouldBe('stepUp("2010-02-10", null, null, "0")', '"2010-02-10"');
+shouldBe('stepDown("2010-02-10", null, null, "0")', '"2010-02-10"');
+shouldBe('stepUp("2010-02-10", null, null, "foo")', '"2010-02-10"');
+shouldBe('stepDown("2010-02-10", null, null, "foo")', '"2010-02-10"');
+shouldBe('stepUp("2010-02-10", null, null, null)', '"2010-02-10"');
+shouldBe('stepDown("2010-02-10", null, null, null)', '"2010-02-10"');
+debug('Normal cases');
+shouldBe('stepUp("2010-02-10", null, null)', '"2010-02-11"');
+shouldBe('stepDown("2010-02-10", null, null)', '"2010-02-09"');
+shouldBe('stepUp("2010-02-10", null, null, 10)', '"2010-02-20"');
+shouldBe('stepDown("2010-02-10", null, null, 11)', '"2010-01-30"');
+shouldBe('stepUp("1970-01-01", "4", null, 2)', '"1970-01-09"');
+shouldBe('stepDown("1970-01-01", "4", null, 3)', '"1969-12-20"');
+debug('Step=any');
+shouldThrow('stepUp("2010-02-10", "any", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02-10", "any", null)', invalidStateErr);
+debug('Overflow/underflow');
+shouldThrow('stepUp("2010-02-10", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02-10", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepUp("2010-02-10", "1", "2010-02-10")', invalidStateErr);
+shouldThrow('stepDown("2010-02-10", "1", "2010-02-10")', invalidStateErr);
+
+debug('');
+debug('Datetime type');
+input.type = 'datetime';
+debug('Invalid value');
+shouldThrow('stepUp("", null, null)', invalidStateErr);
+shouldThrow('stepDown("", null, null)', invalidStateErr);
+debug('Non-number arguments');
+shouldBe('stepUp("2010-02-10T20:13Z", null, null, "0")', '"2010-02-10T20:13Z"');
+shouldBe('stepDown("2010-02-10T20:13Z", null, null, "0")', '"2010-02-10T20:13Z"');
+shouldBe('stepUp("2010-02-10T20:13Z", null, null, "foo")', '"2010-02-10T20:13Z"');
+shouldBe('stepDown("2010-02-10T20:13Z", null, null, "foo")', '"2010-02-10T20:13Z"');
+shouldBe('stepUp("2010-02-10T20:13Z", null, null, null)', '"2010-02-10T20:13Z"');
+shouldBe('stepDown("2010-02-10T20:13Z", null, null, null)', '"2010-02-10T20:13Z"');
+debug('Normal cases');
+shouldBe('stepUp("2010-02-10T20:13Z", null, null)', '"2010-02-10T20:14Z"');
+shouldBe('stepDown("2010-02-10T20:13Z", null, null)', '"2010-02-10T20:12Z"');
+shouldBe('stepUp("2010-02-10T20:13Z", null, null, 10)', '"2010-02-10T20:23Z"');
+shouldBe('stepDown("2010-02-10T20:13Z", null, null, 11)', '"2010-02-10T20:02Z"');
+shouldBe('stepUp("1970-01-01T20:13Z", "4", null, 2)', '"1970-01-01T20:13:08Z"');
+shouldBe('stepDown("1970-01-01T20:13Z", "4", null, 3)', '"1970-01-01T20:12:48Z"');
+debug('Step=any');
+shouldThrow('stepUp("2010-02-10T20:13Z", "any", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02-10T20:13Z", "any", null)', invalidStateErr);
+debug('Overflow/underflow');
+shouldThrow('stepUp("2010-02-10T20:13Z", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02-10T20:13Z", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepUp("2010-02-10T20:13Z", "1", "2010-02-10T20:13Z")', invalidStateErr);
+shouldThrow('stepDown("2010-02-10T20:13Z", "1", "2010-02-10T20:13Z")', invalidStateErr);
+
+debug('');
+debug('Datetime-local type');
+input.type = 'datetime-local';
+debug('Invalid value');
+shouldThrow('stepUp("", null, null)', invalidStateErr);
+shouldThrow('stepDown("", null, null)', invalidStateErr);
+debug('Non-number arguments');
+shouldBe('stepUp("2010-02-10T20:13", null, null, "0")', '"2010-02-10T20:13"');
+shouldBe('stepDown("2010-02-10T20:13", null, null, "0")', '"2010-02-10T20:13"');
+shouldBe('stepUp("2010-02-10T20:13", null, null, "foo")', '"2010-02-10T20:13"');
+shouldBe('stepDown("2010-02-10T20:13", null, null, "foo")', '"2010-02-10T20:13"');
+shouldBe('stepUp("2010-02-10T20:13", null, null, null)', '"2010-02-10T20:13"');
+shouldBe('stepDown("2010-02-10T20:13", null, null, null)', '"2010-02-10T20:13"');
+debug('Normal cases');
+shouldBe('stepUp("2010-02-10T20:13", null, null)', '"2010-02-10T20:14"');
+shouldBe('stepDown("2010-02-10T20:13", null, null)', '"2010-02-10T20:12"');
+shouldBe('stepUp("2010-02-10T20:13", null, null, 10)', '"2010-02-10T20:23"');
+shouldBe('stepDown("2010-02-10T20:13", null, null, 11)', '"2010-02-10T20:02"');
+shouldBe('stepUp("1970-01-01T20:13", "4", null, 2)', '"1970-01-01T20:13:08"');
+shouldBe('stepDown("1970-01-01T20:13", "4", null, 3)', '"1970-01-01T20:12:48"');
+debug('Step=any');
+shouldThrow('stepUp("2010-02-10T20:13", "any", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02-10T20:13", "any", null)', invalidStateErr);
+debug('Overflow/underflow');
+shouldThrow('stepUp("2010-02-10T20:13", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02-10T20:13", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepUp("2010-02-10T20:13", "1", "2010-02-10T20:13")', invalidStateErr);
+shouldThrow('stepDown("2010-02-10T20:13", "1", "2010-02-10T20:13")', invalidStateErr);
+
+debug('');
+debug('Month type');
+input.type = 'month';
+debug('Invalid value');
+shouldThrow('stepUp("", null, null)', invalidStateErr);
+shouldThrow('stepDown("", null, null)', invalidStateErr);
+debug('Non-number arguments');
+shouldBe('stepUp("2010-02", null, null, "0")', '"2010-02"');
+shouldBe('stepDown("2010-02", null, null, "0")', '"2010-02"');
+shouldBe('stepUp("2010-02", null, null, "foo")', '"2010-02"');
+shouldBe('stepDown("2010-02", null, null, "foo")', '"2010-02"');
+shouldBe('stepUp("2010-02", null, null, null)', '"2010-02"');
+shouldBe('stepDown("2010-02", null, null, null)', '"2010-02"');
+debug('Normal cases');
+shouldBe('stepUp("2010-02", null, null)', '"2010-03"');
+shouldBe('stepDown("2010-02", null, null)', '"2010-01"');
+shouldBe('stepUp("2010-02", null, null, 10)', '"2010-12"');
+shouldBe('stepDown("2010-02", null, null, 11)', '"2009-03"');
+shouldBe('stepUp("1970-01", "4", null, 2)', '"1970-09"');
+shouldBe('stepDown("1970-01", "4", null, 3)', '"1969-01"');
+debug('Step=any');
+shouldThrow('stepUp("2010-02", "any", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02", "any", null)', invalidStateErr);
+debug('Overflow/underflow');
+shouldThrow('stepUp("2010-02", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepDown("2010-02", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepUp("2010-02", "1", "2010-02")', invalidStateErr);
+shouldThrow('stepDown("2010-02", "1", "2010-02")', invalidStateErr);
+
+debug('');
+debug('Time type');
+input.type = 'time';
+debug('Invalid value');
+shouldThrow('stepUp("", null, null)', invalidStateErr);
+shouldThrow('stepDown("", null, null)', invalidStateErr);
+debug('Non-number arguments');
+shouldBe('stepUp("20:13", null, null, "0")', '"20:13"');
+shouldBe('stepDown("20:13", null, null, "0")', '"20:13"');
+shouldBe('stepUp("20:13", null, null, "foo")', '"20:13"');
+shouldBe('stepDown("20:13", null, null, "foo")', '"20:13"');
+shouldBe('stepUp("20:13", null, null, null)', '"20:13"');
+shouldBe('stepDown("20:13", null, null, null)', '"20:13"');
+debug('Normal cases');
+shouldBe('stepUp("20:13", null, null)', '"20:14"');
+shouldBe('stepDown("20:13", null, null)', '"20:12"');
+shouldBe('stepUp("20:13", null, null, 10)', '"20:23"');
+shouldBe('stepDown("20:13", null, null, 11)', '"20:02"');
+shouldBe('stepUp("20:13", "4", null, 2)', '"20:13:08"');
+shouldBe('stepDown("20:13", "4", null, 3)', '"20:12:48"');
+debug('Step=any');
+shouldThrow('stepUp("20:13", "any", null)', invalidStateErr);
+shouldThrow('stepDown("20:13", "any", null)', invalidStateErr);
+debug('Overflow/underflow');
+shouldThrow('stepUp("20:13", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepDown("20:13", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepUp("20:13", "1", "20:13")', invalidStateErr);
+shouldThrow('stepDown("20:13", "1", "20:13")', invalidStateErr);
+shouldThrow('stepUp("23:59", null, null)', invalidStateErr);
+shouldThrow('stepDown("00:00", null, null)', invalidStateErr);
+
+debug('');
+debug('Week type');
+input.type = 'week';
+debug('Invalid value');
+shouldThrow('stepUp("", null, null)', invalidStateErr);
+shouldThrow('stepDown("", null, null)', invalidStateErr);
+debug('Non-number arguments');
+shouldBe('stepUp("2010-W02", null, null, "0")', '"2010-W02"');
+shouldBe('stepDown("2010-W02", null, null, "0")', '"2010-W02"');
+shouldBe('stepUp("2010-W02", null, null, "foo")', '"2010-W02"');
+shouldBe('stepDown("2010-W02", null, null, "foo")', '"2010-W02"');
+shouldBe('stepUp("2010-W02", null, null, null)', '"2010-W02"');
+shouldBe('stepDown("2010-W02", null, null, null)', '"2010-W02"');
+debug('Normal cases');
+shouldBe('stepUp("2010-W02", null, null)', '"2010-W03"');
+shouldBe('stepDown("2010-W02", null, null)', '"2010-W01"');
+shouldBe('stepUp("2010-W02", null, null, 10)', '"2010-W12"');
+shouldBe('stepDown("2010-W02", null, null, 11)', '"2009-W44"');
+shouldBe('stepUp("1970-W01", "4", null, 2)', '"1970-W09"');
+shouldBe('stepDown("1970-W01", "4", null, 3)', '"1969-W41"');
+debug('Step=any');
+shouldThrow('stepUp("2010-W02", "any", null)', invalidStateErr);
+shouldThrow('stepDown("2010-W02", "any", null)', invalidStateErr);
+debug('Overflow/underflow');
+shouldThrow('stepUp("2010-W02", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepDown("2010-W02", "1.7976931348623156e+308", null)', invalidStateErr);
+shouldThrow('stepUp("2010-W02", "1", "2010-W02")', invalidStateErr);
+shouldThrow('stepDown("2010-W02", "1", "2010-W02")', invalidStateErr);
+
+var successfullyParsed = true;
index cb0f9e1..2771f85 100644 (file)
@@ -37,8 +37,8 @@ shouldBe('input.value = "2010-01-01T00:00Z"; input.valueAsDate = null; input.val
 
 debug('Step attribute value and string representation:');
 // If the step attribute value is 1 second and the second part is 0, we should show the second part.
-shouldBe('input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00"');
+shouldBe('input.step = "1"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00Z"');
 // If the step attribute value is 0.001 second and the millisecond part is 0, we should show the millisecond part.
-shouldBe('input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000"');
+shouldBe('input.step = "0.001"; setValueAsDateAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000Z"');
 
 var successfullyParsed = true;
index 325d0ea..0b94a88 100644 (file)
@@ -42,8 +42,8 @@ shouldThrow('input.valueAsNumber = Number.NEGATIVE_INFINITY', '"Error: NOT_SUPPO
 
 debug('Step attribute value and string representation:');
 // If the step attribute value is 1 second and the second part is 0, we should show the second part.
-shouldBe('input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00"');
+shouldBe('input.step = "1"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00Z"');
 // If the step attribute value is 0.001 second and the millisecond part is 0, we should show the millisecond part.
-shouldBe('input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000"');
+shouldBe('input.step = "0.001"; setValueAsNumberAndGetValue(2010, 0, 21, 0, 0, 0, 0)', '"2010-01-21T00:00:00.000Z"');
 
 var successfullyParsed = true;
index 396efe8..8b10309 100644 (file)
@@ -1,3 +1,33 @@
+2010-02-11  Kent Tamura  <tkent@chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Step attribute support for date&time types.
+        https://bugs.webkit.org/show_bug.cgi?id=30847
+
+        - Add implementation for ValidityState.stepMismatch, stepUp() and
+          stepDown() for date, datetime, datetime-local, month, time, week types.
+        - Fix string representation of DateComponents.
+
+        Tests: fast/forms/ValidityState-stepMismatch.html
+               fast/forms/input-stepup-stepdown.html
+
+        * html/HTMLInputElement.cpp:
+          - Change monthDefaultMaximum so that DateComponents::m_year doesn't overflow.
+        (WebCore::HTMLInputElement::stepBase):
+        (WebCore::HTMLInputElement::stepMismatch):
+        (WebCore::HTMLInputElement::getStepParameters):
+        (WebCore::HTMLInputElement::getAllowedValueStep):
+        (WebCore::HTMLInputElement::applyStep):
+          Renamed from applyStepForNumberOrRange(), and add support for other types.
+        (WebCore::HTMLInputElement::stepUp): Rename applyStepForNumberOrRange().
+        (WebCore::HTMLInputElement::stepDown): Rename applyStepForNumberOrRange().
+        (WebCore::HTMLInputElement::setValueAsDate): Use setDateValue().
+        (WebCore::HTMLInputElement::setDateValue):
+          A helper function to make the best representation of DateComponents.
+        (WebCore::HTMLInputElement::setValueAsNumber):  Use setDateValue().
+        * html/HTMLInputElement.h:
+
 2010-02-10  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Gavin Barraclough.
index 1cdea12..a1ad0c1 100644 (file)
@@ -76,8 +76,19 @@ using namespace HTMLNames;
 const int maxSavedResults = 256;
 
 // Constant values for getAllowedValueStep().
+static const double dateDefaultStep = 1.0;
+static const double dateStepScaleFactor = 86400000.0;
+static const double dateTimeDefaultStep = 60.0;
+static const double dateTimeStepScaleFactor = 1000.0;
+static const double monthDefaultStep = 1.0;
+static const double monthStepScaleFactor = 1.0;
 static const double numberDefaultStep = 1.0;
 static const double numberStepScaleFactor = 1.0;
+static const double timeDefaultStep = 60.0;
+static const double timeStepScaleFactor = 1000.0;
+static const double weekDefaultStep = 1.0;
+static const double weekStepScaleFactor = 604800000.0;
+
 // Constant values for minimum().
 static const double dateDefaultMinimum = -12219292800000.0; // This means 1582-10-15T00:00Z.
 static const double dateTimeDefaultMinimum = -12219292800000.0; // ditto.
@@ -86,15 +97,23 @@ static const double numberDefaultMinimum = -DBL_MAX;
 static const double rangeDefaultMinimum = 0.0;
 static const double timeDefaultMinimum = 0.0; // 00:00:00.000
 static const double weekDefaultMinimum = -12212380800000.0; // 1583-01-03, the first Monday of 1583.
+
 // Constant values for maximum().
 static const double dateDefaultMaximum = DBL_MAX;
 static const double dateTimeDefaultMaximum = DBL_MAX;
-static const double monthDefaultMaximum = DBL_MAX;
+// DateComponents::m_year can't represent a year greater than INT_MAX.
+static const double monthDefaultMaximum = (INT_MAX - 1970) * 12.0 + 12 - 1;
 static const double numberDefaultMaximum = DBL_MAX;
 static const double rangeDefaultMaximum = 100.0;
 static const double timeDefaultMaximum = 86399999.0; // 23:59:59.999
 static const double weekDefaultMaximum = DBL_MAX;
 
+static const double defaultStepBase = 0.0;
+static const double weekDefaultStepBase = -259200000.0; // The first day of 1970-W01.
+
+static const double msecPerMinute = 60 * 1000;
+static const double msecPerSecond = 1000;
+
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f)
     : HTMLTextFormControlElement(tagName, doc, f)
     , m_xPos(0)
@@ -435,13 +454,35 @@ double HTMLInputElement::maximum() const
 
 double HTMLInputElement::stepBase() const
 {
-    if (inputType() == RANGE)
+    switch (inputType()) {
+    case RANGE:
         return minimum();
-    if (inputType() == NUMBER) {
-        static const double defaultStepBase = 0.0;
-        double min = defaultStepBase;
-        formStringToDouble(getAttribute(minAttr), &min);
-        return min;
+    case DATE:
+    case DATETIME:
+    case DATETIMELOCAL:
+    case MONTH:
+    case NUMBER:
+    case TIME:
+        return parseToDouble(getAttribute(minAttr), defaultStepBase);
+    case WEEK:
+        return parseToDouble(getAttribute(minAttr), weekDefaultStepBase);
+    case BUTTON:
+    case CHECKBOX:
+    case COLOR:
+    case EMAIL:
+    case FILE:
+    case HIDDEN:
+    case IMAGE:
+    case ISINDEX:
+    case PASSWORD:
+    case RADIO:
+    case RESET:
+    case SEARCH:
+    case SUBMIT:
+    case TELEPHONE:
+    case TEXT:
+    case URL:
+        break;
     }
     ASSERT_NOT_REACHED();
     return 0.0;
@@ -452,7 +493,12 @@ bool HTMLInputElement::stepMismatch() const
     double step;
     if (!getAllowedValueStep(&step))
         return false;
-    if (inputType() == NUMBER) {
+    switch (inputType()) {
+    case RANGE:
+        // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the
+        // value matches to step.
+        return false;
+    case NUMBER: {
         double doubleValue;
         if (!formStringToDouble(value(), &doubleValue))
             return false;
@@ -469,10 +515,41 @@ bool HTMLInputElement::stepMismatch() const
         double acceptableError = step / pow(2.0, DBL_MANT_DIG - 7);
         return acceptableError < remainder && remainder < (step - acceptableError);
     }
-    // Non-RANGE types should be rejected by getAllowedValueStep().
-    ASSERT(inputType() == RANGE);
-    // stepMismatch doesn't occur for RANGE. RenderSlider guarantees the
-    // value matches to step.
+    case DATE:
+    case DATETIME:
+    case DATETIMELOCAL:
+    case MONTH:
+    case TIME:
+    case WEEK: {
+        const double nan = numeric_limits<double>::quiet_NaN();
+        double doubleValue = parseToDouble(value(), nan);
+        doubleValue = fabs(doubleValue - stepBase());
+        if (!isfinite(doubleValue))
+            return false;
+        ASSERT(round(doubleValue) == doubleValue);
+        ASSERT(round(step) == step);
+        return fmod(doubleValue, step);
+    }
+    case BUTTON:
+    case CHECKBOX:
+    case COLOR:
+    case EMAIL:
+    case FILE:
+    case HIDDEN:
+    case IMAGE:
+    case ISINDEX:
+    case PASSWORD:
+    case RADIO:
+    case RESET:
+    case SEARCH:
+    case SUBMIT:
+    case TELEPHONE:
+    case TEXT:
+    case URL:
+        break;
+    }
+    // Non-supported types should be rejected by getAllowedValueStep().
+    ASSERT_NOT_REACHED();
     return false;
 }
 
@@ -487,13 +564,26 @@ bool HTMLInputElement::getStepParameters(double* defaultStep, double* stepScaleF
         *stepScaleFactor = numberStepScaleFactor;
         return true;
     case DATE:
+        *defaultStep = dateDefaultStep;
+        *stepScaleFactor = dateStepScaleFactor;
+        return true;
     case DATETIME:
     case DATETIMELOCAL:
+        *defaultStep = dateTimeDefaultStep;
+        *stepScaleFactor = dateTimeStepScaleFactor;
+        return true;
     case MONTH:
+        *defaultStep = monthDefaultStep;
+        *stepScaleFactor = monthStepScaleFactor;
+        return true;
     case TIME:
+        *defaultStep = timeDefaultStep;
+        *stepScaleFactor = timeStepScaleFactor;
+        return true;
     case WEEK:
-        // FIXME: Implement for these types.
-        return false;
+        *defaultStep = weekDefaultStep;
+        *stepScaleFactor = weekStepScaleFactor;
+        return true;
     case BUTTON:
     case CHECKBOX:
     case COLOR:
@@ -535,21 +625,28 @@ bool HTMLInputElement::getAllowedValueStep(double* step) const
         *step = defaultStep * stepScaleFactor;
         return true;
     }
-    *step = parsed * stepScaleFactor;
-    ASSERT(*step > 0);
+    // For DATE, MONTH, WEEK, the parsed value should be an integer.
+    if (inputType() == DATE || inputType() == MONTH || inputType() == WEEK)
+        parsed = max(round(parsed), 1.0);
+    double result = parsed * stepScaleFactor;
+    // For DATETIME, DATETIMELOCAL, TIME, the result should be an integer.
+    if (inputType() == DATETIME || inputType() == DATETIMELOCAL || inputType() == TIME)
+        result = max(round(result), 1.0);
+    ASSERT(result > 0);
+    *step = result;
     return true;
 }
 
-void HTMLInputElement::applyStepForNumberOrRange(double count, ExceptionCode& ec)
+void HTMLInputElement::applyStep(double count, ExceptionCode& ec)
 {
-    ASSERT(inputType() == NUMBER || inputType() == RANGE);
     double step;
     if (!getAllowedValueStep(&step)) {
         ec = INVALID_STATE_ERR;
         return;
     }
-    double current;
-    if (!formStringToDouble(value(), &current)) {
+    const double nan = numeric_limits<double>::quiet_NaN();
+    double current = parseToDouble(value(), nan);
+    if (!isfinite(current)) {
         ec = INVALID_STATE_ERR;
         return;
     }
@@ -568,25 +665,17 @@ void HTMLInputElement::applyStepForNumberOrRange(double count, ExceptionCode& ec
         ec = INVALID_STATE_ERR;
         return;
     }
-    setValue(formStringFromDouble(newValue));
+    setValueAsNumber(newValue, ec);
 }
 
 void HTMLInputElement::stepUp(int n, ExceptionCode& ec)
 {
-    if (inputType() != NUMBER && inputType() != RANGE) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-    applyStepForNumberOrRange(n, ec);
+    applyStep(n, ec);
 }
 
 void HTMLInputElement::stepDown(int n, ExceptionCode& ec)
 {
-    if (inputType() != NUMBER && inputType() != RANGE) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-    applyStepForNumberOrRange(-n, ec);
+    applyStep(-n, ec);
 }
 
 static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
@@ -1654,10 +1743,25 @@ void HTMLInputElement::setValueAsDate(double value, ExceptionCode& ec)
         setValue(String());
         return;
     }
-    // FIXME: We should specify SecondFormat.
-    // e.g. If the step value is 60, use SecondFormat::None.
-    //      If the step value is 1, use SecondFormat::Second.
-    setValue(date.toString());
+    setDateValue(date);
+}
+
+void HTMLInputElement::setDateValue(const DateComponents& date)
+{
+    double step;
+    if (!getAllowedValueStep(&step)) {
+        setValue(date.toString());
+        return;
+    }
+    if (!fmod(step, msecPerMinute)) {
+        setValue(date.toString(DateComponents::None));
+        return;
+    }
+    if (!fmod(step, msecPerSecond)) {
+        setValue(date.toString(DateComponents::Second));
+        return;
+    }
+    setValue(date.toString(DateComponents::Millisecond));
 }
 
 double HTMLInputElement::valueAsNumber() const
@@ -1724,10 +1828,7 @@ void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec)
             setValue(String());
             return;
         }
-        // FIXME: We should specify SecondFormat.
-        // e.g. If the step value is 60, use SecondFormat::None.
-        //      If the step value is 1, use SecondFormat::Second.
-        setValue(date.toString());
+        setDateValue(date);
         return;
     }
     case NUMBER:
index f35a1b1..4665437 100644 (file)
@@ -295,8 +295,8 @@ private:
     PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
     // Helper for getAllowedValueStep();
     bool getStepParameters(double* defaultStep, double* stepScaleFactor) const;
-    // Helper for stepUp()/stepDown().  Adds step value * count to the current number/range value.
-    void applyStepForNumberOrRange(double count, ExceptionCode&);
+    // Helper for stepUp()/stepDown().  Adds step value * count to the current value.
+    void applyStep(double count, ExceptionCode&);
     // Helper for applyStepForNumberOrRange().
     double stepBase() const;
 
@@ -306,6 +306,11 @@ private:
     // return NaN or Infinity only if defaultValue is NaN or Infinity.
     double parseToDouble(const String&, double defaultValue) const;
 
+    // Generates a suitable string for the specified DateComponents and the
+    // step value, and calls setValue() with it.
+    void setDateValue(const DateComponents&);
+
+
 #if ENABLE(DATALIST)
     HTMLDataListElement* dataList() const;
 #endif