Bug 668826 - Make reflectString able to test reflections with different IDL attribute and content attribute names. r=Ms2ger

This commit is contained in:
Mounir Lamouri 2011-07-06 14:47:41 +02:00
Родитель 7967fa907e
Коммит 37db201966
2 изменённых файлов: 40 добавлений и 26 удалений

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

@ -133,7 +133,13 @@ reflectLimitedEnumerated({
"datetime-local", "number", "range", "color" ]
});
// TODO: defaultValue (reflects @value)
// .defaultValue
reflectString({
element: document.createElement("input"),
attribute: { idl: "defaultValue", content: "value" },
otherValues: [ "foo\nbar", "foo\rbar", "foo\r\nbar" ],
});
// .value doesn't reflect a content attribute.
// TODO: valueAsDate (not implemented)
// TODO: valueAsNumber (not implemented)

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

@ -18,41 +18,48 @@
* @param aParameters Object object containing the parameters, which are:
* - element Element node to test
* - attribute String name of the attribute
* OR
* attribute Object object containing two attributes, 'content' and 'idl'
* - otherValues Array [optional] other values to test in addition of the default ones
*/
function reflectString(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 otherValues = aParameters.otherValues !== undefined
? aParameters.otherValues : [];
? aParameters.otherValues : [];
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");
// Tests when the attribute isn't set.
is(element.getAttribute(attr), null,
is(element.getAttribute(contentAttr), null,
"When not set, the content attribute should be null.");
is(element[attr], "",
is(element[idlAttr], "",
"When not set, the IDL attribute should return the empty string");
/**
* TODO: as long as null stringification doesn't follow the WebIDL
* specifications, don't add it to the loop below and keep it here.
*/
element.setAttribute(attr, null);
todo_is(element.getAttribute(attr), "null",
element.setAttribute(contentAttr, null);
todo_is(element.getAttribute(contentAttr), "null",
"null should have been stringified to 'null'");
todo_is(element[attr], "null",
todo_is(element[idlAttr], "null",
"null should have been stringified to 'null'");
element.removeAttribute(attr);
element.removeAttribute(contentAttr);
element[attr] = null;
todo_is(element.getAttribute(attr), "null",
element[idlAttr] = null;
todo_is(element.getAttribute(contentAttr), "null",
"null should have been stringified to 'null'");
todo_is(element[attr], "null",
todo_is(element[idlAttr], "null",
"null should have been stringified to 'null'");
element.removeAttribute(attr);
element.removeAttribute(contentAttr);
// Tests various strings.
var stringsToTest = [
@ -61,7 +68,8 @@ function reflectString(aParameters)
[ "null", "null" ],
[ "undefined", "undefined" ],
[ "foo", "foo" ],
[ attr, attr ],
[ contentAttr, contentAttr ],
[ idlAttr, idlAttr ],
// TODO: uncomment this when null stringification will follow the specs.
// [ null, "null" ],
[ undefined, "undefined" ],
@ -84,25 +92,25 @@ function reflectString(aParameters)
otherValues.forEach(function(v) { stringsToTest.push([v, v]) });
stringsToTest.forEach(function([v, r]) {
element.setAttribute(attr, v);
is(element[attr], r,
element.setAttribute(contentAttr, v);
is(element[idlAttr], r,
"IDL attribute should return the value it has been set to.");
is(element.getAttribute(attr), r,
is(element.getAttribute(contentAttr), r,
"Content attribute should return the value it has been set to.");
element.removeAttribute(attr);
element.removeAttribute(contentAttr);
element[attr] = v;
is(element[attr], r,
element[idlAttr] = v;
is(element[idlAttr], r,
"IDL attribute should return the value it has been set to.");
is(element.getAttribute(attr), r,
is(element.getAttribute(contentAttr), r,
"Content attribute should return the value it has been set to.");
element.removeAttribute(attr);
element.removeAttribute(contentAttr);
});
// Tests after removeAttribute() is called. Should be equivalent with not set.
is(element.getAttribute(attr), null,
is(element.getAttribute(contentAttr), null,
"When not set, the content attribute should be null.");
is(element[attr], "",
is(element[idlAttr], "",
"When not set, the IDL attribute should return the empty string");
}