Bug 1283022 - Implement the min and max attribute for <input type=month>. r=smaug

This commit is contained in:
Jessica Jong 2016-07-15 00:07:00 +02:00
Родитель a54b4b6946
Коммит 17b5002551
7 изменённых файлов: 88 добавлений и 49 удалений

Просмотреть файл

@ -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<bool> 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<bool> 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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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