Bug 1278738 - Add 'week' to the list of valid types attributes for <input>. r=smaug

This commit is contained in:
Jessica Jong 2016-08-15 23:15:00 -04:00
Родитель 18475abfbc
Коммит 5a9b39d967
32 изменённых файлов: 187 добавлений и 65 удалений

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

@ -179,8 +179,9 @@ add_task(function* test_tel_email_url_number_input() {
}
});
add_task(function* test_date_time_color_range_input() {
for (let selector of ["#input_date", "#input_time", "#input_color", "#input_range"]) {
add_task(function* test_date_time_color_range_month_week_input() {
for (let selector of ["#input_date", "#input_time", "#input_color",
"#input_range", "#input_month"]) {
yield test_contextmenu(selector,
["context-navigation", null,
["context-back", false,
@ -219,8 +220,8 @@ add_task(function* test_search_input() {
);
});
add_task(function* test_datetime_month_week_datetimelocal_input_todos() {
for (let type of ["datetime", "week", "datetime-local"]) {
add_task(function* test_datetime_datetimelocal_input_todos() {
for (let type of ["datetime", "datetime-local"]) {
let returnedType = yield ContentTask.spawn(gBrowser.selectedBrowser, type, function*(type) {
let doc = content.document;
let input = doc.getElementById("input_" + type);

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

@ -47,11 +47,12 @@ HTMLFormControlsCollection::ShouldBeInElements(nsIFormControl* aFormControl)
case NS_FORM_INPUT_TEXT :
case NS_FORM_INPUT_TEL :
case NS_FORM_INPUT_URL :
case NS_FORM_INPUT_MONTH :
case NS_FORM_INPUT_NUMBER :
case NS_FORM_INPUT_RANGE :
case NS_FORM_INPUT_DATE :
case NS_FORM_INPUT_TIME :
case NS_FORM_INPUT_MONTH :
case NS_FORM_INPUT_WEEK :
case NS_FORM_SELECT :
case NS_FORM_TEXTAREA :
case NS_FORM_FIELDSET :

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

@ -177,6 +177,7 @@ static const nsAttrValue::EnumTable kInputTypeTable[] = {
{ "text", NS_FORM_INPUT_TEXT },
{ "time", NS_FORM_INPUT_TIME },
{ "url", NS_FORM_INPUT_URL },
{ "week", NS_FORM_INPUT_WEEK },
{ 0 }
};
@ -2122,7 +2123,8 @@ HTMLInputElement::ConvertNumberToString(Decimal aValue,
Nullable<Date>
HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
{
if (!IsDateTimeInputType(mType)) {
// TODO: this is temporary until bug 888316 is fixed.
if (!IsDateTimeInputType(mType) || mType == NS_FORM_INPUT_WEEK) {
return Nullable<Date>();
}
@ -2176,7 +2178,8 @@ HTMLInputElement::GetValueAsDate(ErrorResult& aRv)
void
HTMLInputElement::SetValueAsDate(Nullable<Date> aDate, ErrorResult& aRv)
{
if (!IsDateTimeInputType(mType)) {
// TODO: this is temporary until bug 888316 is fixed.
if (!IsDateTimeInputType(mType) || mType == NS_FORM_INPUT_WEEK) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
@ -2424,9 +2427,10 @@ HTMLInputElement::IsExperimentalMobileType(uint8_t aType)
bool
HTMLInputElement::IsDateTimeInputType(uint8_t aType)
{
return aType == NS_FORM_INPUT_DATE || aType == NS_FORM_INPUT_TIME ||
aType == NS_FORM_INPUT_MONTH;
return aType == NS_FORM_INPUT_DATE ||
aType == NS_FORM_INPUT_TIME ||
aType == NS_FORM_INPUT_MONTH ||
aType == NS_FORM_INPUT_WEEK;
}
NS_IMETHODIMP
@ -5258,7 +5262,8 @@ IsDateTimeEnabled(int32_t aNewType)
(aNewType == NS_FORM_INPUT_TIME &&
(Preferences::GetBool("dom.forms.datetime", false) ||
Preferences::GetBool("dom.experimental_forms", false))) ||
(aNewType == NS_FORM_INPUT_MONTH &&
((aNewType == NS_FORM_INPUT_MONTH ||
aNewType == NS_FORM_INPUT_WEEK) &&
Preferences::GetBool("dom.forms.datetime", false));
}
@ -6744,6 +6749,7 @@ HTMLInputElement::GetValueMode() const
case NS_FORM_INPUT_TIME:
case NS_FORM_INPUT_COLOR:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
return VALUE_MODE_VALUE;
default:
NS_NOTYETIMPLEMENTED("Unexpected input type in GetValueMode()");
@ -6790,6 +6796,7 @@ HTMLInputElement::DoesReadOnlyApply() const
case NS_FORM_INPUT_DATE:
case NS_FORM_INPUT_TIME:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
return true;
default:
NS_NOTYETIMPLEMENTED("Unexpected input type in DoesReadOnlyApply()");
@ -6828,6 +6835,7 @@ HTMLInputElement::DoesRequiredApply() const
case NS_FORM_INPUT_DATE:
case NS_FORM_INPUT_TIME:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
return true;
default:
NS_NOTYETIMPLEMENTED("Unexpected input type in DoesRequiredApply()");
@ -6870,6 +6878,7 @@ HTMLInputElement::DoesMinMaxApply() const
case NS_FORM_INPUT_TIME:
case NS_FORM_INPUT_RANGE:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
// TODO:
// All date/time types.
return true;
@ -6918,6 +6927,7 @@ HTMLInputElement::DoesAutocompleteApply() const
case NS_FORM_INPUT_RANGE:
case NS_FORM_INPUT_COLOR:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
return true;
#ifdef DEBUG
case NS_FORM_INPUT_RESET:
@ -7101,7 +7111,8 @@ HTMLInputElement::HasPatternMismatch() const
bool
HTMLInputElement::IsRangeOverflow() const
{
if (!DoesMinMaxApply()) {
// TODO: this is temporary until bug 888316 is fixed.
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_WEEK) {
return false;
}
@ -7121,7 +7132,8 @@ HTMLInputElement::IsRangeOverflow() const
bool
HTMLInputElement::IsRangeUnderflow() const
{
if (!DoesMinMaxApply()) {
// TODO: this is temporary until bug 888316 is fixed.
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_WEEK) {
return false;
}
@ -8092,7 +8104,8 @@ HTMLInputElement::UpdateHasRange()
mHasRange = false;
if (!DoesMinMaxApply()) {
// TODO: this is temporary until bug 888316 is fixed.
if (!DoesMinMaxApply() || mType == NS_FORM_INPUT_WEEK) {
return;
}

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

@ -1023,7 +1023,11 @@ protected:
/**
* Returns if the step attribute apply for the current type.
*/
bool DoesStepApply() const { return DoesMinMaxApply(); }
bool DoesStepApply() const
{
// TODO: this is temporary until bug 888316 is fixed.
return DoesMinMaxApply() && mType != NS_FORM_INPUT_WEEK;
}
/**
* Returns if stepDown and stepUp methods apply for the current type.
@ -1033,7 +1037,11 @@ protected:
/**
* Returns if valueAsNumber attribute applies for the current type.
*/
bool DoesValueAsNumberApply() const { return DoesMinMaxApply(); }
bool DoesValueAsNumberApply() const
{
// TODO: this is temporary until bug 888316 is fixed.
return DoesMinMaxApply() && mType != NS_FORM_INPUT_WEEK;
}
/**
* Returns if autocomplete attribute applies for the current type.

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

@ -66,6 +66,7 @@ enum InputElementTypes {
NS_FORM_INPUT_TIME,
NS_FORM_INPUT_URL,
NS_FORM_INPUT_RANGE,
NS_FORM_INPUT_WEEK,
eInputElementTypesMax
};
@ -268,6 +269,7 @@ nsIFormControl::IsSingleLineTextControl(bool aExcludePassword, uint32_t aType)
aType == NS_FORM_INPUT_DATE ||
aType == NS_FORM_INPUT_TIME ||
aType == NS_FORM_INPUT_MONTH ||
aType == NS_FORM_INPUT_WEEK ||
(!aExcludePassword && aType == NS_FORM_INPUT_PASSWORD);
}

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

@ -234,10 +234,11 @@ reflectLimitedEnumerated({
attribute: "type",
validValues: [ "hidden", "text", "search", "tel", "url", "email", "password",
"checkbox", "radio", "file", "submit", "image", "reset",
"button", "date", "time", "number", "range", "color", "month" ],
"button", "date", "time", "number", "range", "color", "month",
"week" ],
invalidValues: [ "this-is-probably-a-wrong-type", "", "tulip" ],
defaultValue: "text",
unsupportedValues: [ "datetime", "week", "datetime-local" ]
unsupportedValues: [ "datetime", "datetime-local" ]
});
// .defaultValue

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

@ -79,7 +79,7 @@ var inputTypes =
var todoTypes =
[
"week", "datetime", "datetime-local",
"datetime", "datetime-local",
];
var valueModeValue =

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

@ -64,6 +64,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=764481
prefs: [["dom.forms.datetime", true]],
inputType: "month",
expectedType: "month"
}, {
prefs: [["dom.forms.datetime", false]],
inputType: "week",
expectedType: "text"
}, {
prefs: [["dom.forms.datetime", true]],
inputType: "week",
expectedType: "week"
}
];

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

@ -198,7 +198,6 @@ function runTest()
'2012-1',
]
},
{ type: 'week', todo: true },
{ type: 'datetime', todo: true },
{ type: 'datetime-local', todo: true },
];

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

@ -30,7 +30,8 @@ var data = [
{ type: 'datetime', apply: true, todo: true },
{ type: 'date', apply: true },
{ type: 'month', apply: true },
{ type: 'week', apply: true, todo: true },
// TODO: temporary set to false until bug 888316 is fixed.
{ type: 'week', apply: false },
{ type: 'time', apply: true },
{ type: 'datetime-local', apply: true, todo: true },
{ type: 'number', apply: true },
@ -149,6 +150,9 @@ for (var test of data) {
case 'month':
input.max = '2016-12';
break;
case 'week':
// TODO: this is temporary until bug 888316 is fixed.
break;
default:
ok(false, 'please, add a case for this new type (' + input.type + ')');
}
@ -379,7 +383,8 @@ for (var test of data) {
input.max = 'foo';
checkValidity(input, true, apply, false);
case 'week':
// TODO: this is temporary until bug 888316 is fixed.
break;
}

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

@ -30,7 +30,8 @@ var data = [
{ type: 'datetime', apply: true, todo: true },
{ type: 'date', apply: true },
{ type: 'month', apply: true },
{ type: 'week', apply: true, todo: true },
// TODO: temporary set to false until bug 888316 is fixed.
{ type: 'week', apply: false },
{ type: 'time', apply: true },
{ type: 'datetime-local', apply: true, todo: true },
{ type: 'number', apply: true },
@ -145,6 +146,9 @@ for (var test of data) {
case 'month':
input.min = '2016-06';
break;
case 'week':
// TODO: this is temporary until bug 888316 is fixed.
break;
default:
ok(false, 'please, add a case for this new type (' + input.type + ')');
}
@ -376,6 +380,9 @@ for (var test of data) {
input.min = 'foo';
checkValidity(input, true, apply, false);
break;
case 'week':
// TODO: this is temporary until bug 888316 is fixed.
break;
default:
ok(false, 'write tests for ' + input.type);
}

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

@ -53,6 +53,7 @@ var gInputTestData = [
['time', false],
['color', false],
['month', false],
['week', false],
];
/**
@ -62,7 +63,6 @@ var gInputTestData = [
var gInputTodoData = [
/* type expected result */
['datetime', false],
['week', false],
['datetime-local', false],
];

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

@ -298,8 +298,9 @@ var input = document.getElementById('i');
// and |invalidTypes| are the ones which do not accept it.
var validTypes = Array('text', 'password', 'search', 'tel', 'email', 'url');
var barredTypes = Array('hidden', 'reset', 'button');
var invalidTypes = Array('checkbox', 'radio', 'file', 'number', 'range', 'date', 'time', 'color', 'submit', 'image', 'month');
// TODO: 'datetime', 'week', and 'datetime-local'
var invalidTypes = Array('checkbox', 'radio', 'file', 'number', 'range', 'date',
'time', 'color', 'submit', 'image', 'month', 'week');
// TODO: 'datetime' and 'datetime-local'
// do not accept the @pattern too but are not implemented yet.
for (type of validTypes) {

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

@ -364,10 +364,10 @@ for (type of typeRequireNotApply) {
}
// Now, checking for all types which accept the required attribute.
// TODO: check 'datetime', 'week' and 'datetime-local'
// TODO: check 'datetime' and 'datetime-local'
// when they will be implemented.
var typeRequireApply = ["text", "password", "search", "tel", "email", "url",
"number", "date", "time", "month"];
"number", "date", "time", "month", "week"];
for (type of typeRequireApply) {
checkInputRequiredValidity(type);

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

@ -30,7 +30,8 @@ var data = [
{ type: 'datetime', apply: true, todo: true },
{ type: 'date', apply: true },
{ type: 'month', apply: true },
{ type: 'week', apply: true, todo: true },
// TODO: temporary set to false until bug 888316 is fixed.
{ type: 'week', apply: false },
{ type: 'time', apply: true },
{ type: 'datetime-local', apply: true, todo: true },
{ type: 'number', apply: true },
@ -837,6 +838,9 @@ for (var test of data) {
input.value = '1970-02';
checkValidity(input, true, apply);
break;
case 'week':
// TODO: this is temporary until bug 888316 is fixed.
break;
default:
ok(false, "Implement the tests for <input type='" + test.type + " >");

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

@ -46,12 +46,13 @@ var validTypes =
["time", true],
["color", false],
["month", true],
// TODO: temporary set to false until bug 888316 is fixed.
["week", false],
];
var todoTypes =
[
["datetime", true],
["week", true],
["datetime-local", true],
];

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

@ -45,12 +45,13 @@ function checkAvailability()
["time", true],
["color", false],
["month", true],
// TODO: temporary set to false until bug 888316 is fixed.
["week", false],
];
var todoList =
[
["datetime", true],
["week", true],
["datetime-local", true],
];

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

@ -39,12 +39,13 @@ var testData = [
[ "time", true ],
[ "range", true ],
[ "color", true ],
[ 'month', true ]
[ 'month', true ],
[ 'week', true ]
// 'file' is treated separatly.
];
var todoTypes = [
"datetime", "week", "datetime-local"
"datetime", "datetime-local"
];
var nonTrivialSanitizing = [ 'number', 'date', 'time', 'color', 'month' ];

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

@ -38,9 +38,9 @@ var types = [
[ "text", "email", "password", "url", "search", "tel" ],
// These types can't be too long.
[ "radio", "checkbox", "submit", "button", "reset", "image", "hidden",
'number', 'range', 'date', 'time', 'color', 'month' ],
'number', 'range', 'date', 'time', 'color', 'month', 'week' ],
// These types can't be too long but are not implemented yet.
[ "datetime", "week", 'datetime-local' ]
[ "datetime", 'datetime-local' ]
];
var input = document.createElement("input");

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

@ -3698,6 +3698,8 @@ nsCSSFrameConstructor::FindInputData(Element* aElement,
SIMPLE_INT_CREATE(NS_FORM_INPUT_TIME, NS_NewTextControlFrame),
// TODO: this is temporary until a frame is written: bug 888320
SIMPLE_INT_CREATE(NS_FORM_INPUT_MONTH, NS_NewTextControlFrame),
// TODO: this is temporary until a frame is written: bug 888320
SIMPLE_INT_CREATE(NS_FORM_INPUT_WEEK, NS_NewTextControlFrame),
{ NS_FORM_INPUT_SUBMIT,
FCDATA_WITH_WRAPPING_BLOCK(0, NS_NewGfxButtonControlFrame,
nsCSSAnonBoxes::buttonContent) },

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

@ -1143,6 +1143,10 @@ pref("dom.forms.number", true);
// platforms which don't have a color picker implemented yet.
pref("dom.forms.color", true);
// Support for input type=date, time, month, week and datetime-local. By
// default, disabled.
pref("dom.forms.datetime", false);
// Support for new @autocomplete values
pref("dom.forms.autocomplete.experimental", false);

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

@ -589,12 +589,6 @@
[input.type: setAttribute() to "DATETIME" followed by IDL get]
expected: FAIL
[input.type: setAttribute() to "week" followed by IDL get]
expected: FAIL
[input.type: setAttribute() to "WEEK" followed by IDL get]
expected: FAIL
[input.type: setAttribute() to "datetime-local" followed by IDL get]
expected: FAIL
@ -607,12 +601,6 @@
[input.type: IDL set to "DATETIME" followed by IDL get]
expected: FAIL
[input.type: IDL set to "week" followed by IDL get]
expected: FAIL
[input.type: IDL set to "WEEK" followed by IDL get]
expected: FAIL
[input.type: IDL set to "datetime-local" followed by IDL get]
expected: FAIL

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

@ -45,6 +45,20 @@
[[INPUT in MONTH status\] suffering from a step mismatch (in a form)]
expected: FAIL
[[INPUT in WEEK status\] The week type must be supported.]
[[INPUT in WEEK status\] suffering from an overflow]
expected: FAIL
[[INPUT in WEEK status\] suffering from an overflow (in a form)]
expected: FAIL
[[INPUT in WEEK status\] suffering from an underflow]
expected: FAIL
[[INPUT in WEEK status\] suffering from an underflow (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

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

@ -45,6 +45,20 @@
[[INPUT in MONTH status\] suffering from a step mismatch (in a form)]
expected: FAIL
[[INPUT in WEEK status\] The week type must be supported.]
[[INPUT in WEEK status\] suffering from an overflow]
expected: FAIL
[[INPUT in WEEK status\] suffering from an overflow (in a form)]
expected: FAIL
[[INPUT in WEEK status\] suffering from an underflow]
expected: FAIL
[[INPUT in WEEK status\] suffering from an underflow (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

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

@ -3,6 +3,10 @@
[[INPUT in DATETIME status\] The datetime type must be supported.]
expected: FAIL
[[INPUT in WEEK status\] The week type must be supported.]
[[INPUT in WEEK status\] The value attribute is greater than max attribute]
expected: FAIL
[[INPUT in WEEK status\] The value attribute is greater than max attribute(Year is 10000 should be valid)]
expected: FAIL

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

@ -3,6 +3,9 @@
[[INPUT in DATETIME status\] The datetime type must be supported.]
expected: FAIL
[[INPUT in WEEK status\] The week type must be supported.]
[[INPUT in WEEK status\] The value attribute is less than min attribute]
expected: FAIL
[[INPUT in WEEK status\] The value attribute is less than min attribute(Year is 10000 should be valid)]
expected: FAIL

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

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

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

@ -24,6 +24,12 @@
[[INPUT in MONTH status\] validity.valid must be false if validity.stepMismatch is true]
expected: FAIL
[[INPUT in WEEK status\] The week type must be supported.]
[[INPUT in WEEK status\] validity.valid must be false if validity.rangeOverflow is true]
expected: FAIL
[[INPUT in WEEK status\] validity.valid must be false if validity.rangeUnderflow is true]
expected: FAIL
[[INPUT in WEEK status\] validity.valid must be false if validity.stepMismatch is true]
expected: FAIL

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

@ -3,6 +3,18 @@
[[INPUT in DATETIME status\] The datetime type must be supported.]
expected: FAIL
[[INPUT in WEEK status\] The week type must be supported.]
[[INPUT in WEEK status\] The value attribute is a number(1234567)]
expected: FAIL
[[INPUT in WEEK status\] The value attribute is a Date object]
expected: FAIL
[[INPUT in WEEK status\] Invalid week string(2000-W99)]
expected: FAIL
[[INPUT in WEEK status\] invalid week string(2000-W00)]
expected: FAIL
[[INPUT in WEEK status\] invalid week string(2000-w01)]
expected: FAIL

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

@ -3,6 +3,3 @@
[datetime type support on input element]
expected: FAIL
[week type support on input element]
expected: FAIL

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

@ -1,8 +1,5 @@
[selection.html]
type: testharness
[input type week should support the select() method]
expected: FAIL
[input type datetime-local should support the select() method]
expected: FAIL
@ -30,9 +27,6 @@
[input type button should not support the select() method]
expected: FAIL
[input type week should not support variable-length selections]
expected: FAIL
[input type datetime-local should not support variable-length selections]
expected: FAIL

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

@ -123,6 +123,11 @@ Form History test: form field autocomplete
<button type="submit">Submit</button>
</form>
<!-- form with input type='week' -->
<form id="form19" onsubmit="return false;">
<input type="week" name="field16">
<button type="submit">Submit</button>
</form>
</div>
@ -165,12 +170,14 @@ function setupFormHistory(aCallback) {
{ op : "add", fieldname : "field12", value : "21:21" },
{ op : "add", fieldname : "field13", value : "32" }, // not used, since type=range doesn't have a drop down menu
{ op : "add", fieldname : "field14", value : "#ffffff" }, // not used, since type=color doesn't have autocomplete currently
{ op : "add", fieldname : "field15", value : "2016-08" },
{ op : "add", fieldname : "field16", value : "2016-W32" },
{ op : "add", fieldname : "searchbar-history", value : "blacklist test" },
], aCallback);
}
// All these non-implemeted types might need autocomplete tests in the future.
var todoTypes = [ "datetime", "week", "datetime-local" ];
var todoTypes = [ "datetime", "datetime-local" ];
var todoInput = document.createElement("input");
for (var type of todoTypes) {
todoInput.type = type;
@ -937,10 +944,34 @@ function runTest() {
checkMenuEntries([]); // type=color does not have a drop down menu
checkForm("#000000"); // default color value
addEntry("field1", "value1");
input = $_(18, "field15");
restoreForm();
expectPopup();
doKey("down");
break;
case 409:
checkMenuEntries(["2016-08"]);
doKey("down");
doKey("return");
checkForm("2016-08");
input = $_(19, "field16");
restoreForm();
expectPopup();
doKey("down");
break;
case 410:
checkMenuEntries(["2016-W32"]);
doKey("down");
doKey("return");
checkForm("2016-W32");
addEntry("field1", "value1");
break;
case 411:
input = $_(1, "field1");
// Go to test 500.
testNum = 499;