From 17b50025511714c9140ce75838343c74078a4858 Mon Sep 17 00:00:00 2001 From: Jessica Jong Date: Fri, 15 Jul 2016 00:07:00 +0200 Subject: [PATCH] Bug 1283022 - Implement the min and max attribute for . r=smaug --- dom/html/HTMLInputElement.cpp | 17 +++---- dom/html/test/forms/test_max_attribute.html | 46 +++++++++++++++++-- dom/html/test/forms/test_min_attribute.html | 44 ++++++++++++++++-- .../form-validation-checkValidity.html.ini | 12 ----- ...validation-validity-rangeOverflow.html.ini | 6 --- ...alidation-validity-rangeUnderflow.html.ini | 6 --- .../form-validation-validity-valid.html.ini | 6 --- 7 files changed, 88 insertions(+), 49 deletions(-) diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 607e7db5e88e..fb44790bd0e5 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -7034,8 +7034,7 @@ HTMLInputElement::HasPatternMismatch() const bool HTMLInputElement::IsRangeOverflow() const { - // TODO: this is temporary until bug 888324 is fixed. - if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_MONTH) { + if (!DoesMinMaxApply()) { return false; } @@ -7055,8 +7054,7 @@ HTMLInputElement::IsRangeOverflow() const bool HTMLInputElement::IsRangeUnderflow() const { - // TODO: this is temporary until bug 888324 is fixed. - if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_MONTH) { + if (!DoesMinMaxApply()) { return false; } @@ -7443,8 +7441,8 @@ HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage, DebugOnly ok = maximum.toString(buf, ArrayLength(buf)); maxStr.AssignASCII(buf); MOZ_ASSERT(ok, "buf not big enough"); - } else if (mType == NS_FORM_INPUT_DATE || mType == NS_FORM_INPUT_TIME) { - msgTemplate = mType == NS_FORM_INPUT_DATE ? kDateOverTemplate : kTimeOverTemplate; + } else if (IsDateTimeInputType(mType)) { + msgTemplate = mType == NS_FORM_INPUT_TIME ? kTimeOverTemplate : kDateOverTemplate; GetAttr(kNameSpaceID_None, nsGkAtoms::max, maxStr); } else { msgTemplate = kNumberOverTemplate; @@ -7479,8 +7477,8 @@ HTMLInputElement::GetValidationMessage(nsAString& aValidationMessage, DebugOnly ok = minimum.toString(buf, ArrayLength(buf)); minStr.AssignASCII(buf); MOZ_ASSERT(ok, "buf not big enough"); - } else if (mType == NS_FORM_INPUT_DATE || mType == NS_FORM_INPUT_TIME) { - msgTemplate = mType == NS_FORM_INPUT_DATE ? kDateUnderTemplate : kTimeUnderTemplate; + } else if (IsDateTimeInputType(mType)) { + msgTemplate = mType == NS_FORM_INPUT_TIME ? kTimeUnderTemplate : kDateUnderTemplate; GetAttr(kNameSpaceID_None, nsGkAtoms::min, minStr); } else { msgTemplate = kNumberUnderTemplate; @@ -8035,8 +8033,7 @@ HTMLInputElement::UpdateHasRange() mHasRange = false; - // TODO: this is temporary until bug 888324 is fixed. - if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_MONTH) { + if (!DoesMinMaxApply()) { return; } diff --git a/dom/html/test/forms/test_max_attribute.html b/dom/html/test/forms/test_max_attribute.html index fa5dd487e04a..0a1bd1f0ed11 100644 --- a/dom/html/test/forms/test_max_attribute.html +++ b/dom/html/test/forms/test_max_attribute.html @@ -29,8 +29,7 @@ var data = [ { type: 'password', apply: false }, { type: 'datetime', apply: true, todo: true }, { type: 'date', apply: true }, - // TODO: temporary set to false until bug 888324 is fixed. - { type: 'month', apply: false }, + { type: 'month', apply: true }, { type: 'week', apply: true, todo: true }, { type: 'time', apply: true }, { type: 'datetime-local', apply: true, todo: true }, @@ -71,7 +70,8 @@ function checkValidity(aElement, aValidity, aApply, aRangeApply) is(aElement.validity.rangeOverflow, !aValidity, "element overflow status should be " + !aValidity); var overflowMsg = - (aElement.type == "date" || aElement.type == "time") ? + (aElement.type == "date" || aElement.type == "time" || + aElement.type == "month") ? ("Please select a value that is no later than " + aElement.max + ".") : ("Please select a value that is no more than " + aElement.max + "."); is(aElement.validationMessage, @@ -147,7 +147,7 @@ for (var test of data) { input.max = '10'; break; case 'month': - // TODO: this is temporary until bug 888324 is fixed. + input.max = '2016-12'; break; default: ok(false, 'please, add a case for this new type (' + input.type + ')'); @@ -342,6 +342,44 @@ for (var test of data) { input.max = 'foo'; checkValidity(input, true, apply, false); + break; + case 'month': + input.value = '2016-06'; + checkValidity(input, true, apply, apply); + + input.value = '2016-12'; + checkValidity(input, true, apply, apply); + + input.value = 'foo'; + checkValidity(input, true, apply, apply); + + input.value = '2017-01'; + checkValidity(input, false, apply, apply); + + input.max = '2017-07'; + checkValidity(input, true, apply, apply); + + input.value = '2017-12'; + checkValidity(input, false, apply, apply); + + input.value = '1000-01'; + checkValidity(input, true, apply, apply); + + input.value = '20160-01'; + checkValidity(input, false, apply, apply); + + input.max = '0050-01'; + checkValidity(input, false, apply, apply); + + input.value = '0049-12'; + checkValidity(input, true, apply, apply); + + input.max = ''; + checkValidity(input, true, apply, false); + + input.max = 'foo'; + checkValidity(input, true, apply, false); + break; } diff --git a/dom/html/test/forms/test_min_attribute.html b/dom/html/test/forms/test_min_attribute.html index 6f541d23723e..0aeabadfe6b3 100644 --- a/dom/html/test/forms/test_min_attribute.html +++ b/dom/html/test/forms/test_min_attribute.html @@ -29,8 +29,7 @@ var data = [ { type: 'password', apply: false }, { type: 'datetime', apply: true, todo: true }, { type: 'date', apply: true }, - // TODO: temporary set to false until bug 888324 is fixed. - { type: 'month', apply: false }, + { type: 'month', apply: true }, { type: 'week', apply: true, todo: true }, { type: 'time', apply: true }, { type: 'datetime-local', apply: true, todo: true }, @@ -71,7 +70,8 @@ function checkValidity(aElement, aValidity, aApply, aRangeApply) is(aElement.validity.rangeUnderflow, !aValidity, "element underflow status should be " + !aValidity); var underflowMsg = - (aElement.type == "date" || aElement.type == "time") ? + (aElement.type == "date" || aElement.type == "time" || + aElement.type == "month") ? ("Please select a value that is no earlier than " + aElement.min + ".") : ("Please select a value that is no less than " + aElement.min + "."); is(aElement.validationMessage, @@ -143,7 +143,7 @@ for (var test of data) { // suffer from overflow. break; case 'month': - // TODO: this is temporary until bug 888324 is fixed. + input.min = '2016-06'; break; default: ok(false, 'please, add a case for this new type (' + input.type + ')'); @@ -340,7 +340,41 @@ for (var test of data) { checkValidity(input, true, apply, false); break; case 'month': - // TODO: this is temporary until bug 888324 is fixed. + input.value = '2016-07'; + checkValidity(input, true, apply, apply); + + input.value = '2016-06'; + checkValidity(input, true, apply, apply); + + input.value = 'foo'; + checkValidity(input, true, apply, apply); + + input.value = '2016-05'; + checkValidity(input, false, apply, apply); + + input.min = '2016-01'; + checkValidity(input, true, apply, apply); + + input.value = '2015-12'; + checkValidity(input, false, apply, apply); + + input.value = '1000-01'; + checkValidity(input, false, apply, apply); + + input.value = '10000-01'; + checkValidity(input, true, apply, apply); + + input.min = '0010-01'; + checkValidity(input, true, apply, apply); + + input.value = '0001-01'; + checkValidity(input, false, apply, apply); + + input.min = ''; + checkValidity(input, true, apply, false); + + input.min = 'foo'; + checkValidity(input, true, apply, false); break; default: ok(false, 'write tests for ' + input.type); diff --git a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini index 3ddb66dd8049..435665fa4844 100644 --- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini +++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-checkValidity.html.ini @@ -39,18 +39,6 @@ [[INPUT in DATETIME status\] The datetime type must be supported.] expected: FAIL - [[INPUT in MONTH status\] suffering from an overflow] - expected: FAIL - - [[INPUT in MONTH status\] suffering from an overflow (in a form)] - expected: FAIL - - [[INPUT in MONTH status\] suffering from an underflow] - expected: FAIL - - [[INPUT in MONTH status\] suffering from an underflow (in a form)] - expected: FAIL - [[INPUT in MONTH status\] suffering from a step mismatch] expected: FAIL diff --git a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini index 798bed6c150d..6de3d898d8fe 100644 --- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini +++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeOverflow.html.ini @@ -3,12 +3,6 @@ [[INPUT in DATETIME status\] The datetime type must be supported.] expected: FAIL - [[INPUT in MONTH status\] The value attribute is greater than max attribute] - expected: FAIL - - [[INPUT in MONTH status\] The value attribute is greater than max attribute(Year is 10000 should be valid)] - expected: FAIL - [[INPUT in WEEK status\] The week type must be supported.] expected: FAIL diff --git a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini index 6080a6e435c1..495eda8a6f7f 100644 --- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini +++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-rangeUnderflow.html.ini @@ -3,12 +3,6 @@ [[INPUT in DATETIME status\] The datetime type must be supported.] expected: FAIL - [[INPUT in MONTH status\] The value attribute is less than min attribute] - expected: FAIL - - [[INPUT in MONTH status\] The value attribute is less than min attribute(Year is 10000 should be valid)] - expected: FAIL - [[INPUT in WEEK status\] The week type must be supported.] expected: FAIL diff --git a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini index db19bbe4cd88..123bfb413812 100644 --- a/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini +++ b/testing/web-platform/meta/html/semantics/forms/constraints/form-validation-validity-valid.html.ini @@ -21,12 +21,6 @@ [[INPUT in DATETIME status\] The datetime type must be supported.] expected: FAIL - [[INPUT in MONTH status\] validity.valid must be false if validity.rangeOverflow is true] - expected: FAIL - - [[INPUT in MONTH status\] validity.valid must be false if validity.rangeUnderflow is true] - expected: FAIL - [[INPUT in MONTH status\] validity.valid must be false if validity.stepMismatch is true] expected: FAIL