Bug 1295403 - Implement the step attribute for <input type=week>. r=smaug

This commit is contained in:
Jessica Jong 2016-10-07 15:04:54 +08:00
Родитель a8940b87e6
Коммит 19414ca429
8 изменённых файлов: 258 добавлений и 26 удалений

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

@ -211,7 +211,9 @@ const Decimal HTMLInputElement::kStepScaleFactorDate = Decimal(86400000);
const Decimal HTMLInputElement::kStepScaleFactorNumberRange = Decimal(1);
const Decimal HTMLInputElement::kStepScaleFactorTime = Decimal(1000);
const Decimal HTMLInputElement::kStepScaleFactorMonth = Decimal(1);
const Decimal HTMLInputElement::kStepScaleFactorWeek = Decimal(7 * 86400000);
const Decimal HTMLInputElement::kDefaultStepBase = Decimal(0);
const Decimal HTMLInputElement::kDefaultStepBaseWeek = Decimal(-259200000);
const Decimal HTMLInputElement::kDefaultStep = Decimal(1);
const Decimal HTMLInputElement::kDefaultStepTime = Decimal(60);
const Decimal HTMLInputElement::kStepAny = Decimal(0);
@ -2381,6 +2383,7 @@ HTMLInputElement::GetStepBase() const
mType == NS_FORM_INPUT_DATE ||
mType == NS_FORM_INPUT_TIME ||
mType == NS_FORM_INPUT_MONTH ||
mType == NS_FORM_INPUT_WEEK ||
mType == NS_FORM_INPUT_RANGE,
"Check that kDefaultStepBase is correct for this new type");
@ -2401,6 +2404,10 @@ HTMLInputElement::GetStepBase() const
return stepBase;
}
if (mType == NS_FORM_INPUT_WEEK) {
return kDefaultStepBaseWeek;
}
return kDefaultStepBase;
}
@ -7353,7 +7360,8 @@ HTMLInputElement::GetStep() const
}
// For input type=date, we round the step value to have a rounded day.
if (mType == NS_FORM_INPUT_DATE || mType == NS_FORM_INPUT_MONTH) {
if (mType == NS_FORM_INPUT_DATE || mType == NS_FORM_INPUT_MONTH ||
mType == NS_FORM_INPUT_WEEK) {
step = std::max(step.round(), Decimal(1));
}
@ -8489,6 +8497,8 @@ HTMLInputElement::GetStepScaleFactor() const
return kStepScaleFactorTime;
case NS_FORM_INPUT_MONTH:
return kStepScaleFactorMonth;
case NS_FORM_INPUT_WEEK:
return kStepScaleFactorWeek;
default:
MOZ_ASSERT(false, "Unrecognized input type");
return Decimal::nan();
@ -8503,6 +8513,7 @@ HTMLInputElement::GetDefaultStep() const
switch (mType) {
case NS_FORM_INPUT_DATE:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_RANGE:
return kDefaultStep;

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

@ -1053,11 +1053,7 @@ protected:
/**
* Returns if the step attribute apply for the current type.
*/
bool DoesStepApply() const
{
// TODO: this is temporary until bug 888316 is fixed.
return DoesMinMaxApply() && mType != NS_FORM_INPUT_WEEK;
}
bool DoesStepApply() const { return DoesMinMaxApply(); }
/**
* Returns if stepDown and stepUp methods apply for the current type.
@ -1507,9 +1503,13 @@ protected:
static const Decimal kStepScaleFactorNumberRange;
static const Decimal kStepScaleFactorTime;
static const Decimal kStepScaleFactorMonth;
static const Decimal kStepScaleFactorWeek;
// Default step base value when a type do not have specific one.
static const Decimal kDefaultStepBase;
// Default step base value when type=week does not not have a specific one,
// which is 259200000, the start of week 1970-W01.
static const Decimal kDefaultStepBaseWeek;
// Default step used when there is no specified step.
static const Decimal kDefaultStep;

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

@ -30,8 +30,7 @@ var data = [
{ type: 'datetime', apply: true, todo: true },
{ type: 'date', apply: true },
{ type: 'month', apply: true },
// TODO: temporary set to false until bug 888316 is fixed.
{ type: 'week', apply: false },
{ type: 'week', apply: true },
{ type: 'time', apply: true },
{ type: 'datetime-local', apply: true, todo: true },
{ type: 'number', apply: true },
@ -840,7 +839,115 @@ for (var test of data) {
break;
case 'week':
// TODO: this is temporary until bug 888316 is fixed.
// When step is invalid, every week is valid
input.step = 0;
input.value = '2016-W30';
checkValidity(input, true, apply);
input.step = 'foo';
input.value = '1970-W01';
checkValidity(input, true, apply);
input.step = '-1';
input.value = '1970-W01';
checkValidity(input, true, apply);
input.removeAttribute('step');
input.value = '1500-W01';
checkValidity(input, true, apply);
input.step = 'any';
input.value = '1966-W52';
checkValidity(input, true, apply);
input.step = 'ANY';
input.value = '2013-W10';
checkValidity(input, true, apply);
// When min is set to a valid week, there is a step base.
input.min = '2000-W01';
input.step = '2';
input.value = '2000-W03';
checkValidity(input, true, apply);
input.value = '2000-W02';
checkValidity(input, false, apply, { low: "2000-W01", high: "2000-W03" });
input.min = '2012-W52';
input.value = '2013-W01';
checkValidity(input, false, apply, { low: "2012-W52", high: "2013-W02" });
input.min = '2010-W01';
input.step = '1.1';
input.value = '2010-W02';
checkValidity(input, true, apply);
input.min = '2010-W05';
input.step = '1.9';
input.value = '2010-W06';
checkValidity(input, false, apply, { low: "2010-W05", high: "2010-W07" });
// Without any step attribute the week is valid
input.removeAttribute('step');
checkValidity(input, true, apply);
input.min = '1950-W01';
input.step = '53';
input.value = '1951-W01';
checkValidity(input, false, apply, { low: "1950-W01", high: "1951-W02" });
input.min = '1951-W01';
input.step = '52';
input.value = '1952-W01';
checkValidity(input, true, apply);
input.step = '0.9';
input.value = '1951-W02';
checkValidity(input, true, apply);
input.step = '1.5';
input.value = '1951-W04';
checkValidity(input, false, apply, { low: "1951-W03", high: "1951-W05" });
input.value = '1951-W20';
checkValidity(input, false, apply, { low: "1951-W19", high: "1951-W21" });
input.step = '300';
input.min= '1968-W01';
input.value = '1968-W05';
checkValidity(input, false, apply, { low: "1968-W01", high: "1973-W40" });
input.value = '1971-W01';
checkValidity(input, false, apply, { low: "1968-W01", high: "1973-W40" });
input.value = '1975-W01';
checkValidity(input, false, apply, { low: "1973-W40", high: "1979-W27" });
input.value = '1985-W14';
checkValidity(input, true, apply);
input.step = '2.1';
input.min = '1991-W01';
input.value = '1991-W01';
checkValidity(input, true, apply);
input.value = '1991-W02';
checkValidity(input, false, apply, { low: "1991-W01", high: "1991-W03" });
input.value = '1991-W03';
checkValidity(input, true, apply);
input.step = '2.1';
input.min = '1969-W52';
input.value = '1969-W52';
checkValidity(input, true, apply);
input.value = '1970-W01';
checkValidity(input, false, apply, { low: "1969-W52", high: "1970-W02" });
input.value = '1970-W02';
checkValidity(input, true, apply);
break;
default:
ok(false, "Implement the tests for <input type='" + test.type + " >");

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

@ -51,13 +51,13 @@ function checkAvailability()
["date", true],
["time", true],
["month", true],
["week", true],
["color", false],
];
var todoList =
[
["datetime", true],
["week", true],
["datetime-local", true],
];
@ -445,6 +445,70 @@ function checkStepDown()
[ '2016-01', 'AnY', null, null, 1, null, true ],
[ '2016-01', 'aNy', null, null, 1, null, true ],
]},
{ type: 'week', data: [
// Regular case.
[ '2016-W40', null, null, null, null, '2016-W39', false ],
// Argument testing.
[ '2016-W40', null, null, null, 1, '2016-W39', false ],
[ '2016-W40', null, null, null, 5, '2016-W35', false ],
[ '2016-W40', null, null, null, -1, '2016-W41', false ],
[ '2016-W40', null, null, null, 0, '2016-W40', false ],
// Week/Year wrapping.
[ '2016-W01', null, null, null, 1, '2015-W53', false ],
[ '1969-W02', null, null, null, 4, '1968-W50', false ],
[ '1969-W01', null, null, null, -52, '1970-W01', false ],
// Float values are rounded to integer (1.1 -> 1).
[ '2016-W40', null, null, null, 1.1, '2016-W39', false ],
[ '2016-W01', null, null, null, 1.9, '2015-W53', false ],
// With step values.
[ '2016-W03', '0.5', null, null, null, '2016-W02', false ],
[ '2016-W03', '2', null, null, null, '2016-W01', false ],
[ '2016-W03', '0.25', null, null, 4, '2015-W52', false ],
[ '2016-W52', '1.1', '2016-W01', null, 1, '2016-W51', false ],
[ '2016-W52', '1.1', '2016-W01', null, 2, '2016-W50', false ],
[ '2016-W52', '1.1', '2016-W01', null, 10, '2016-W42', false ],
[ '2016-W52', '1.1', '2016-W01', null, 52, '2016-W01', false ],
[ '1968-W52', '1.1', '1968-W01', null, 8, '1968-W44', false ],
// step = 0 isn't allowed (-> step = 1).
[ '2016-W02', '0', null, null, null, '2016-W01', false ],
// step < 0 isn't allowed (-> step = 1).
[ '2016-W02', '-1', null, null, null, '2016-W01', false ],
// step = NaN isn't allowed (-> step = 1).
[ '2016-W02', 'foo', null, null, null, '2016-W01', false ],
// Min values testing.
[ '2016-W03', '1', 'foo', null, 2, '2016-W01', false ],
[ '2016-W02', '1', '2016-01', null, null, '2016-W01', false ],
[ '2016-W01', '1', '2016-W01', null, null, '2016-W01', false ],
[ '2016-W01', '1', '2016-W01', null, 1, '2016-W01', false ],
[ '2016-W05', '3', '2016-W01', null, null, '2016-W04', false ],
[ '1969-W01', '5', '1969-W01', '1969-W02', null, '1969-W01', false ],
// Max values testing.
[ '2016-W02', '1', null, 'foo', null, '2016-W01', false ],
[ '2016-W02', null, null, '2016-W05', null, '2016-W01', false ],
[ '2016-W03', null, null, '2016-W03', null, '2016-W02', false ],
[ '2016-W07', null, null, '2016-W04', 4, '2016-W03', false ],
[ '2016-W07', '2', null, '2016-W04', 3, '2016-W01', false ],
// Step mismatch.
[ '2016-W04', '2', '2016-W01', null, null, '2016-W03', false ],
[ '2016-W06', '2', '2016-W01', null, 2, '2016-W03', false ],
[ '2016-W05', '2', '2016-W04', '2016-W08', null, '2016-W04', false ],
[ '1970-W04', '2', null, null, null, '1970-W02', false ],
[ '1970-W09', '3', null, null, null, '1970-W06', false ],
// Clamping.
[ '2016-W05', null, null, '2016-W01', null, '2016-W01', false ],
[ '1970-W05', '2', '1970-W02', '1970-W05', null, '1970-W04', false ],
[ '1970-W01', '5', '1970-W02', '1970-W09', 10, '1970-W01', false ],
[ '1970-W07', '5', '1969-W52', '1970-W10', 2, '1969-W52', false ],
[ '1970-W08', '3', '1970-W01', '1970-W07', 15, '1970-W01', false ],
[ '1970-W10', '3', '1970-W01', '1970-W06', 2, '1970-W04', false ],
// value = "" (NaN).
[ '', null, null, null, null, '1970-W01', false ],
// With step = 'any'.
[ '2016-W01', 'any', null, null, 1, null, true ],
[ '2016-W01', 'ANY', null, null, 1, null, true ],
[ '2016-W01', 'AnY', null, null, 1, null, true ],
[ '2016-W01', 'aNy', null, null, 1, null, true ],
]},
];
for (var test of testData) {
@ -829,6 +893,71 @@ function checkStepUp()
[ '2016-01', 'AnY', null, null, 1, null, true ],
[ '2016-01', 'aNy', null, null, 1, null, true ],
]},
{ type: 'week', data: [
// Regular case.
[ '2016-W40', null, null, null, null, '2016-W41', false ],
// Argument testing.
[ '2016-W40', null, null, null, 1, '2016-W41', false ],
[ '2016-W40', null, null, null, 20, '2017-W08', false ],
[ '2016-W40', null, null, null, -1, '2016-W39', false ],
[ '2016-W40', null, null, null, 0, '2016-W40', false ],
// Week/Year wrapping.
[ '2015-W53', null, null, null, 1, '2016-W01', false ],
[ '1968-W52', null, null, null, 4, '1969-W04', false ],
[ '1970-W01', null, null, null, -52, '1969-W01', false ],
// Float values are rounded to integer (1.1 -> 1).
[ '2016-W01', null, null, null, 1.1, '2016-W02', false ],
[ '2016-W01', null, null, null, 1.9, '2016-W02', false ],
// With step values.
[ '2016-W01', '0.5', null, null, null, '2016-W02', false ],
[ '2016-W01', '2', null, null, null, '2016-W03', false ],
[ '2016-W01', '0.25', null, null, 4, '2016-W05', false ],
[ '2016-W01', '1.1', '2016-01', null, 1, '2016-W02', false ],
[ '2016-W01', '1.1', '2016-01', null, 2, '2016-W03', false ],
[ '2016-W01', '1.1', '2016-01', null, 10, '2016-W11', false ],
[ '2016-W01', '1.1', '2016-01', null, 20, '2016-W21', false ],
// step = 0 isn't allowed (-> step = 1).
[ '2016-W01', '0', null, null, null, '2016-W02', false ],
// step < 0 isn't allowed (-> step = 1).
[ '2016-W01', '-1', null, null, null, '2016-W02', false ],
// step = NaN isn't allowed (-> step = 1).
[ '2016-W01', 'foo', null, null, null, '2016-W02', false ],
// Min values testing.
[ '2016-W01', '1', 'foo', null, null, '2016-W02', false ],
[ '2016-W01', null, '2015-W53', null, null, '2016-W02', false ],
[ '2016-W01', null, '2016-W02', null, null, '2016-W02', false ],
[ '2016-W01', null, '2016-W01', null, null, '2016-W02', false ],
[ '2016-W01', null, '2016-W04', null, 4, '2016-W05', false ],
[ '2016-W01', '2', '2016-W04', null, 3, '2016-W06', false ],
// Max values testing.
[ '2016-W01', '1', null, 'foo', 2, '2016-W03', false ],
[ '2016-W01', '1', null, '2016-W02', 1, '2016-W02', false ],
[ '2016-W02', null, null, '2016-W01', null, '2016-W02', false ],
[ '2016-W02', null, null, '2016-W02', null, '2016-W02', false ],
[ '1969-W02', '5', '1969-W01', '1969-W02', null, '1969-W02', false ],
// Step mismatch.
[ '2016-W02', '2', '2016-W01', null, null, '2016-W03', false ],
[ '2016-W02', '2', '2016-W01', null, 2, '2016-W05', false ],
[ '2016-W05', '2', '2016-W01', '2016-W06', null, '2016-W05', false ],
[ '1970-W02', '2', null, null, null, '1970-W04', false ],
[ '1970-W05', '3', null, null, null, '1970-W08', false ],
[ '1970-W03', '3', null, null, null, '1970-W06', false ],
[ '1970-W03', '3', '1970-W02', null, null, '1970-W05', false ],
// Clamping.
[ '2016-W01', null, '2016-W52', null, null, '2016-W52', false ],
[ '1970-W02', '2', '1970-W01', '1970-W04', null, '1970-W03', false ],
[ '1970-W01', '5', '1970-W02', '1970-W09', 10, '1970-W07', false ],
[ '1969-W50', '5', '1969-W52', '1970-W06', 3, '1970-W05', false ],
[ '1970-W01', '3', '1970-W02', '1971-W07', 15, '1970-W44', false ],
[ '1970-W01', '3', '1970-W01', '1970-W06', 2, '1970-W04', false ],
// value = "" (NaN).
[ '', null, null, null, null, '1970-W02', false ],
// With step = 'any'.
[ '2016-W01', 'any', null, null, 1, null, true ],
[ '2016-W01', 'ANY', null, null, 1, null, true ],
[ '2016-W01', 'AnY', null, null, 1, null, true ],
[ '2016-W01', 'aNy', null, null, 1, null, true ],
]},
];
for (var test of testData) {

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

@ -45,9 +45,4 @@
[[INPUT in MONTH status\] suffering from a step mismatch (in a form)]
expected: FAIL
[[INPUT in WEEK status\] suffering from a step mismatch]
expected: FAIL
[[INPUT in WEEK status\] suffering from a step mismatch (in a form)]
expected: FAIL

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

@ -44,10 +44,3 @@
[[INPUT in MONTH status\] suffering from a step mismatch (in a form)]
expected: FAIL
[[INPUT in WEEK status\] suffering from a step mismatch]
expected: FAIL
[[INPUT in WEEK status\] suffering from a step mismatch (in a form)]
expected: FAIL

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

@ -6,7 +6,7 @@
[[INPUT in DATE status\] The value must match the step]
expected: FAIL
[[INPUT in WEEK status\] The value must mismatch the step]
[[INPUT in WEEK status\] The value must match the step]
expected: FAIL
[[INPUT in TIME status\] The value must match the step]

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

@ -24,6 +24,3 @@
[[INPUT in MONTH status\] validity.valid must be false if validity.stepMismatch is true]
expected: FAIL
[[INPUT in WEEK status\] validity.valid must be false if validity.stepMismatch is true]
expected: FAIL