mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-02 03:49:37 +00:00
Bug 682239 - Tests all HTMLFormElement attributes reflection. r=Ms2ger
This commit is contained in:
parent
f5c04e94d2
commit
69c1cf65cc
@ -213,7 +213,6 @@ _TEST_FILES = \
|
||||
test_bug593689.html \
|
||||
test_bug561636.html \
|
||||
test_bug590363.html \
|
||||
test_bug557628.html \
|
||||
test_bug592802.html \
|
||||
test_bug595429.html \
|
||||
test_bug595447.html \
|
||||
|
@ -15,13 +15,58 @@
|
||||
|
||||
/** Test for HTMLFormElement attributes reflection **/
|
||||
|
||||
// TODO: acceptCharset
|
||||
// TODO: action
|
||||
// TODO: autocomplete
|
||||
// TODO: enctype
|
||||
// TODO: encoding
|
||||
// TODO: method
|
||||
// TODO: name
|
||||
// .acceptCharset
|
||||
reflectString({
|
||||
element: document.createElement("form"),
|
||||
attribute: { idl: "acceptCharset", content: "accept-charset" },
|
||||
otherValues: [ "ISO-8859-1", "UTF-8" ],
|
||||
});
|
||||
|
||||
// TODO: action (URL)
|
||||
|
||||
// .autocomplete
|
||||
reflectLimitedEnumerated({
|
||||
element: document.createElement("form"),
|
||||
attribute: "autocomplete",
|
||||
validValues: [ "on", "off" ],
|
||||
invalidValues: [ "", "foo", "tulip", "default" ],
|
||||
defaultValue: "on",
|
||||
});
|
||||
|
||||
// .enctype
|
||||
reflectLimitedEnumerated({
|
||||
element: document.createElement("form"),
|
||||
attribute: "enctype",
|
||||
validValues: [ "application/x-www-form-urlencoded", "multipart/form-data",
|
||||
"text/plain" ],
|
||||
invalidValues: [ "", "foo", "tulip", "multipart/foo" ],
|
||||
defaultValue: "application/x-www-form-urlencoded"
|
||||
});
|
||||
|
||||
// .encoding
|
||||
reflectLimitedEnumerated({
|
||||
element: document.createElement("form"),
|
||||
attribute: { idl: "encoding", content: "enctype" },
|
||||
validValues: [ "application/x-www-form-urlencoded", "multipart/form-data",
|
||||
"text/plain" ],
|
||||
invalidValues: [ "", "foo", "tulip", "multipart/foo" ],
|
||||
defaultValue: "application/x-www-form-urlencoded"
|
||||
});
|
||||
|
||||
// .method
|
||||
reflectLimitedEnumerated({
|
||||
element: document.createElement("form"),
|
||||
attribute: "method",
|
||||
validValues: [ "get", "post" ],
|
||||
invalidValues: [ "", "foo", "tulip" ],
|
||||
defaultValue: "get"
|
||||
});
|
||||
|
||||
// .name
|
||||
reflectString({
|
||||
element: document.createElement("form"),
|
||||
attribute: "name",
|
||||
});
|
||||
|
||||
// .noValidate
|
||||
reflectBoolean({
|
||||
@ -29,7 +74,12 @@ reflectBoolean({
|
||||
attribute: "noValidate",
|
||||
});
|
||||
|
||||
// TODO: target
|
||||
// .target
|
||||
reflectString({
|
||||
element: document.createElement("form"),
|
||||
attribute: "target",
|
||||
otherValues: [ "_blank", "_self", "_parent", "_top" ],
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
|
@ -237,6 +237,8 @@ function reflectUnsignedInt(aParameters)
|
||||
* @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
|
||||
@ -245,100 +247,103 @@ function reflectUnsignedInt(aParameters)
|
||||
function reflectLimitedEnumerated(aParameters)
|
||||
{
|
||||
var element = aParameters.element;
|
||||
var attr = aParameters.attribute;
|
||||
var contentAttr = typeof aParameters.attribute === "string"
|
||||
? aParameters.attribute : aParameters.attribute.content;
|
||||
var idlAttr = typeof aParameters.attribute === "string"
|
||||
? aParameters.attribute : aParameters.attribute.idl;
|
||||
var validValues = aParameters.validValues;
|
||||
var invalidValues = aParameters.invalidValues;
|
||||
var defaultValue = aParameters.defaultValue !== undefined
|
||||
? aParameters.defaultValue : "";
|
||||
? aParameters.defaultValue : "";
|
||||
var unsupportedValues = aParameters.unsupportedValues !== undefined
|
||||
? aParameters.unsupportedValues : [];
|
||||
? aParameters.unsupportedValues : [];
|
||||
|
||||
ok(attr in element, attr + " should be an IDL attribute of this element");
|
||||
is(typeof element[attr], "string", attr + " IDL attribute should be a string");
|
||||
ok(idlAttr in element, idlAttr + " should be an IDL attribute of this element");
|
||||
is(typeof element[idlAttr], "string", idlAttr + " IDL attribute should be a string");
|
||||
|
||||
// Explicitly check the default value.
|
||||
element.removeAttribute(attr);
|
||||
is(element[attr], defaultValue,
|
||||
element.removeAttribute(contentAttr);
|
||||
is(element[idlAttr], defaultValue,
|
||||
"When no attribute is set, the value should be the default value.");
|
||||
|
||||
// Check valid values.
|
||||
validValues.forEach(function (v) {
|
||||
element.setAttribute(attr, v);
|
||||
is(element[attr], v,
|
||||
v + " should be accepted as a valid value for " + attr);
|
||||
is(element.getAttribute(attr), v,
|
||||
element.setAttribute(contentAttr, v);
|
||||
is(element[idlAttr], v,
|
||||
v + " should be accepted as a valid value for " + idlAttr);
|
||||
is(element.getAttribute(contentAttr), v,
|
||||
"Content attribute should return the value it has been set to.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element.setAttribute(attr, v.toUpperCase());
|
||||
is(element[attr], v,
|
||||
element.setAttribute(contentAttr, v.toUpperCase());
|
||||
is(element[idlAttr], v,
|
||||
"Enumerated attributes should be case-insensitive.");
|
||||
is(element.getAttribute(attr), v.toUpperCase(),
|
||||
is(element.getAttribute(contentAttr), v.toUpperCase(),
|
||||
"Content attribute should not be lower-cased.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element[attr] = v;
|
||||
is(element[attr], v,
|
||||
v + " should be accepted as a valid value for " + attr);
|
||||
is(element.getAttribute(attr), v,
|
||||
element[idlAttr] = v;
|
||||
is(element[idlAttr], v,
|
||||
v + " should be accepted as a valid value for " + idlAttr);
|
||||
is(element.getAttribute(contentAttr), v,
|
||||
"Content attribute should return the value it has been set to.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element[attr] = v.toUpperCase();
|
||||
is(element[attr], v,
|
||||
element[idlAttr] = v.toUpperCase();
|
||||
is(element[idlAttr], v,
|
||||
"Enumerated attributes should be case-insensitive.");
|
||||
is(element.getAttribute(attr), v.toUpperCase(),
|
||||
is(element.getAttribute(contentAttr), v.toUpperCase(),
|
||||
"Content attribute should not be lower-cased.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
});
|
||||
|
||||
// Check invalid values.
|
||||
invalidValues.forEach(function (v) {
|
||||
element.setAttribute(attr, v);
|
||||
is(element[attr], defaultValue,
|
||||
element.setAttribute(contentAttr, v);
|
||||
is(element[idlAttr], defaultValue,
|
||||
"When the content attribute is set to an invalid value, the default value should be returned.");
|
||||
is(element.getAttribute(attr), v,
|
||||
is(element.getAttribute(contentAttr), v,
|
||||
"Content attribute should not have been changed.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element[attr] = v;
|
||||
is(element[attr], defaultValue,
|
||||
element[idlAttr] = v;
|
||||
is(element[idlAttr], defaultValue,
|
||||
"When the value is set to an invalid value, the default value should be returned.");
|
||||
is(element.getAttribute(attr), v,
|
||||
is(element.getAttribute(contentAttr), v,
|
||||
"Content attribute should not have been changed.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
});
|
||||
|
||||
// Check valid values we currently do not support.
|
||||
// Basically, it's like the checks for the valid values but with some todo's.
|
||||
unsupportedValues.forEach(function (v) {
|
||||
element.setAttribute(attr, v);
|
||||
todo_is(element[attr], v,
|
||||
v + " should be accepted as a valid value for " + attr);
|
||||
is(element.getAttribute(attr), v,
|
||||
element.setAttribute(contentAttr, v);
|
||||
todo_is(element[idlAttr], v,
|
||||
v + " should be accepted as a valid value for " + idlAttr);
|
||||
is(element.getAttribute(contentAttr), v,
|
||||
"Content attribute should return the value it has been set to.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element.setAttribute(attr, v.toUpperCase());
|
||||
todo_is(element[attr], v,
|
||||
element.setAttribute(contentAttr, v.toUpperCase());
|
||||
todo_is(element[idlAttr], v,
|
||||
"Enumerated attributes should be case-insensitive.");
|
||||
is(element.getAttribute(attr), v.toUpperCase(),
|
||||
is(element.getAttribute(contentAttr), v.toUpperCase(),
|
||||
"Content attribute should not be lower-cased.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element[attr] = v;
|
||||
todo_is(element[attr], v,
|
||||
v + " should be accepted as a valid value for " + attr);
|
||||
is(element.getAttribute(attr), v,
|
||||
element[idlAttr] = v;
|
||||
todo_is(element[idlAttr], v,
|
||||
v + " should be accepted as a valid value for " + idlAttr);
|
||||
is(element.getAttribute(contentAttr), v,
|
||||
"Content attribute should return the value it has been set to.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
|
||||
element[attr] = v.toUpperCase();
|
||||
todo_is(element[attr], v,
|
||||
element[idlAttr] = v.toUpperCase();
|
||||
todo_is(element[idlAttr], v,
|
||||
"Enumerated attributes should be case-insensitive.");
|
||||
is(element.getAttribute(attr), v.toUpperCase(),
|
||||
is(element.getAttribute(contentAttr), v.toUpperCase(),
|
||||
"Content attribute should not be lower-cased.");
|
||||
element.removeAttribute(attr);
|
||||
element.removeAttribute(contentAttr);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,71 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=557628
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 557628</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=557628">Mozilla Bug 557628</a>
|
||||
<p id="display"></p>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 557628 **/
|
||||
|
||||
var formAutocompleteTestData = [
|
||||
// Default value.
|
||||
[ "on" ],
|
||||
// Valid values.
|
||||
[ "on", "off" ],
|
||||
// Invalid values.
|
||||
[ "", " ", "foo", "default" ]
|
||||
];
|
||||
|
||||
function checkAttribute(element, name, data)
|
||||
{
|
||||
is(element.getAttribute(name), undefined,
|
||||
"By default " + name + " content attribute should be undefined");
|
||||
is(element[name], data[0][0],
|
||||
"By default " + name + " IDL attribute should be equal to " +
|
||||
data[0][0]);
|
||||
|
||||
// Valid values.
|
||||
for (i in data[1]) {
|
||||
element.setAttribute(name, data[1][i]);
|
||||
is(element.getAttribute(name), data[1][i],
|
||||
"getAttribute should return the content attribute");
|
||||
is(element[name], data[1][i], "When getting, " + name + " IDL attribute " +
|
||||
"should be equal to the content attribute if the value is known");
|
||||
}
|
||||
|
||||
// Invalid values.
|
||||
for (i in data[2]) {
|
||||
element.setAttribute(name, data[2][i]);
|
||||
is(element.getAttribute(name), data[2][i],
|
||||
"getAttribute should return the content attribute");
|
||||
is(element[name], data[0][0], "When getting, " + name + " IDL attribute " +
|
||||
"should return the default value if the content attribute value isn't known");
|
||||
}
|
||||
|
||||
// TODO values.
|
||||
for (i in data[3]) {
|
||||
element.setAttribute(name, data[3][i]);
|
||||
is(element.getAttribute(name), data[3][i],
|
||||
"getAttribute should return the content attribute");
|
||||
todo_is(element[name], data[3][i], "When getting, " + name + " IDL attribute " +
|
||||
"should be equal to the content attribute if the value is known");
|
||||
}
|
||||
}
|
||||
|
||||
var form = document.createElement('form');
|
||||
|
||||
checkAttribute(form, 'autocomplete', formAutocompleteTestData);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -61,11 +61,8 @@ function checkAttribute(form, attrName, idlName, data)
|
||||
}
|
||||
}
|
||||
|
||||
var form = document.createElement('form');
|
||||
var button = document.createElement('button');
|
||||
|
||||
checkAttribute(form, 'enctype', 'enctype', enctypeTestData);
|
||||
checkAttribute(form, 'method', 'method', methodTestData);
|
||||
checkAttribute(button, 'formenctype', 'formEnctype', enctypeTestData);
|
||||
checkAttribute(button, 'formmethod', 'formMethod', methodTestData);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user