Bug 787095 - Update formMethod and formEnctype reflection to have the empty string as default value and correct invalid values. r=mounir

This commit is contained in:
Benedict Singer 2013-01-22 20:35:57 -05:00
Родитель 764b4eede1
Коммит d6d0cffa71
5 изменённых файлов: 79 добавлений и 21 удалений

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

@ -2027,15 +2027,30 @@ void
nsGenericHTMLElement::GetEnumAttr(nsIAtom* aAttr,
const char* aDefault,
nsAString& aResult) const
{
GetEnumAttr(aAttr, aDefault, aDefault, aResult);
}
void
nsGenericHTMLElement::GetEnumAttr(nsIAtom* aAttr,
const char* aDefaultMissing,
const char* aDefaultInvalid,
nsAString& aResult) const
{
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(aAttr);
aResult.Truncate();
if (attrVal && attrVal->Type() == nsAttrValue::eEnum) {
attrVal->GetEnumString(aResult, true);
} else if (aDefault) {
AppendASCIItoUTF16(nsDependentCString(aDefault), aResult);
if (!attrVal) {
if (aDefaultMissing) {
AppendASCIItoUTF16(nsDependentCString(aDefaultMissing), aResult);
}
} else {
if (attrVal->Type() == nsAttrValue::eEnum) {
attrVal->GetEnumString(aResult, true);
} else if (aDefaultInvalid) {
AppendASCIItoUTF16(nsDependentCString(aDefaultInvalid), aResult);
}
}
}

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

@ -920,6 +920,22 @@ protected:
const char* aDefault,
nsAString& aResult) const;
/**
* Helper method for NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES.
* Gets the enum value string of an attribute and using the default missing
* value if the attribute is missing or the default invalid value if the
* string is an invalid enum value.
*
* @param aType the name of the attribute.
* @param aDefaultMissing the default value if the attribute is missing.
* @param aDefaultInvalid the default value if the attribute is invalid.
* @param aResult string corresponding to the value [out].
*/
NS_HIDDEN_(void) GetEnumAttr(nsIAtom* aAttr,
const char* aDefaultMissing,
const char* aDefaultInvalid,
nsAString& aResult) const;
/**
* Locates the nsIEditor associated with this node. In general this is
* equivalent to GetEditorInternal(), but for designmode or contenteditable,
@ -1365,6 +1381,25 @@ protected:
return SetAttrHelper(nsGkAtoms::_atom, aValue); \
}
/**
* A macro to implement the getter and setter for a given content
* property that needs to set an enumerated string that has different
* default values for missing and invalid values. The method uses a
* specific GetEnumAttr and the generic SetAttrHelper methods.
*/
#define NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(_class, _method, _atom, _defaultMissing, _defaultInvalid) \
NS_IMETHODIMP \
_class::Get##_method(nsAString& aValue) \
{ \
GetEnumAttr(nsGkAtoms::_atom, _defaultMissing, _defaultInvalid, aValue); \
return NS_OK; \
} \
NS_IMETHODIMP \
_class::Set##_method(const nsAString& aValue) \
{ \
return SetAttrHelper(nsGkAtoms::_atom, aValue); \
}
/**
* QueryInterface() implementation helper macros
*/

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

@ -916,10 +916,10 @@ NS_IMPL_BOOL_ATTR(nsHTMLInputElement, Disabled, disabled)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Max, max)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, Min, min)
NS_IMPL_ACTION_ATTR(nsHTMLInputElement, FormAction, formaction)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLInputElement, FormEnctype, formenctype,
kFormDefaultEnctype->tag)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLInputElement, FormMethod, formmethod,
kFormDefaultMethod->tag)
NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(nsHTMLInputElement, FormEnctype, formenctype,
"", kFormDefaultEnctype->tag)
NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(nsHTMLInputElement, FormMethod, formmethod,
"", kFormDefaultMethod->tag)
NS_IMPL_BOOL_ATTR(nsHTMLInputElement, FormNoValidate, formnovalidate)
NS_IMPL_STRING_ATTR(nsHTMLInputElement, FormTarget, formtarget)
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(nsHTMLInputElement, Inputmode, inputmode,

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

@ -76,7 +76,7 @@ reflectLimitedEnumerated({
validValues: [ "application/x-www-form-urlencoded", "multipart/form-data",
"text/plain" ],
invalidValues: [ "", "foo", "tulip", "multipart/foo" ],
defaultValue: "application/x-www-form-urlencoded"
defaultValue: { invalid: "application/x-www-form-urlencoded", missing: "" }
});
// .formMethod
@ -85,7 +85,7 @@ reflectLimitedEnumerated({
attribute: "formMethod",
validValues: [ "get", "post" ],
invalidValues: [ "", "foo", "tulip" ],
defaultValue: "get"
defaultValue: { invalid: "get", missing: "" }
});
// .formNoValidate

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

@ -243,15 +243,17 @@ function reflectUnsignedInt(aParameters)
* Checks that a given attribute is correctly reflected as limited to known
* values enumerated attribute.
*
* @param aParameters Object object containing the parameters, which are:
* - element Element node to test on
* - attribute String name of the attribute
* @param aParameters Object object containing the parameters, which are:
* - element Element node to test on
* - attribute String name of the attribute
* OR
* attribute Object object containing two attributes, 'content' and 'idl'
* - validValues Array valid values we support
* - invalidValues Array invalid values
* - defaultValue String [optional] default value when no valid value is set
* - unsupportedValues Array [optional] valid values we do not support
* attribute Object object containing two attributes, 'content' and 'idl'
* - validValues Array valid values we support
* - invalidValues Array invalid values
* - defaultValue String [optional] default value when no valid value is set
* OR
* defaultValue Object [optional] object containing two attributes, 'invalid' and 'missing'
* - unsupportedValues Array [optional] valid values we do not support
*/
function reflectLimitedEnumerated(aParameters)
{
@ -264,6 +266,12 @@ function reflectLimitedEnumerated(aParameters)
var invalidValues = aParameters.invalidValues;
var defaultValue = aParameters.defaultValue !== undefined
? aParameters.defaultValue : "";
var defaultValueInvalid = aParameters.defaultValue === undefined
? "" : typeof aParameters.defaultValue === "string"
? aParameters.defaultValue : aParameters.defaultValue.invalid
var defaultValueMissing = aParameters.defaultValue === undefined
? "" : typeof aParameters.defaultValue === "string"
? aParameters.defaultValue : aParameters.defaultValue.missing
var unsupportedValues = aParameters.unsupportedValues !== undefined
? aParameters.unsupportedValues : [];
@ -272,7 +280,7 @@ function reflectLimitedEnumerated(aParameters)
// Explicitly check the default value.
element.removeAttribute(contentAttr);
is(element[idlAttr], defaultValue,
is(element[idlAttr], defaultValueMissing,
"When no attribute is set, the value should be the default value.");
// Check valid values.
@ -309,14 +317,14 @@ function reflectLimitedEnumerated(aParameters)
// Check invalid values.
invalidValues.forEach(function (v) {
element.setAttribute(contentAttr, v);
is(element[idlAttr], defaultValue,
is(element[idlAttr], defaultValueInvalid,
"When the content attribute is set to an invalid value, the default value should be returned.");
is(element.getAttribute(contentAttr), v,
"Content attribute should not have been changed.");
element.removeAttribute(contentAttr);
element[idlAttr] = v;
is(element[idlAttr], defaultValue,
is(element[idlAttr], defaultValueInvalid,
"When the value is set to an invalid value, the default value should be returned.");
is(element.getAttribute(contentAttr), v,
"Content attribute should not have been changed.");