B2G/gecko/content/html/content/test/reflect.js
/**
 * 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
 *     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
 */
Checks that a given attribute is correctly reflected as limited to known
values enumerated attribute.


Checks that a given attribute is correctly reflected as limited to known values enumerated attribute .
function reflectLimitedEnumerated(aParameters)
{
  var element = aParameters.element;
  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 : "";
  var unsupportedValues = aParameters.unsupportedValues !== undefined
                            ? aParameters.unsupportedValues : [];
  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");
  element.removeAttribute(contentAttr);
  is(element[idlAttr], defaultValue,
     "When no attribute is set, the value should be the default value.");
  validValues.forEach(function (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(contentAttr);
    element.setAttribute(contentAttr, v.toUpperCase());
    is(element[idlAttr], v,
       "Enumerated attributes should be case-insensitive.");
    is(element.getAttribute(contentAttr), v.toUpperCase(),
       "Content attribute should not be lower-cased.");
    element.removeAttribute(contentAttr);
    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(contentAttr);
    element[idlAttr] = v.toUpperCase();
    is(element[idlAttr], v,
       "Enumerated attributes should be case-insensitive.");
    is(element.getAttribute(contentAttr), v.toUpperCase(),
       "Content attribute should not be lower-cased.");
    element.removeAttribute(contentAttr);
  });
  invalidValues.forEach(function (v) {
    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(contentAttr), v,
       "Content attribute should not have been changed.");
    element.removeAttribute(contentAttr);
    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(contentAttr), v,
       "Content attribute should not have been changed.");
    element.removeAttribute(contentAttr);
  });
  unsupportedValues.forEach(function (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(contentAttr);
    element.setAttribute(contentAttr, v.toUpperCase());
    todo_is(element[idlAttr], v,
            "Enumerated attributes should be case-insensitive.");
    is(element.getAttribute(contentAttr), v.toUpperCase(),
       "Content attribute should not be lower-cased.");
    element.removeAttribute(contentAttr);
    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(contentAttr);
    element[idlAttr] = v.toUpperCase();
    todo_is(element[idlAttr], v,
            "Enumerated attributes should be case-insensitive.");
    is(element.getAttribute(contentAttr), v.toUpperCase(),
       "Content attribute should not be lower-cased.");
    element.removeAttribute(contentAttr);
  });
}
function reflectLimitedEnumerated ( aParameters ) { var element = aParameters . element ; 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 : "" ; var unsupportedValues = aParameters . unsupportedValues !== undefined ? aParameters . unsupportedValues : [ ] ; 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" ) ; element . removeAttribute ( contentAttr ) ; is ( element [ idlAttr ] , defaultValue , "When no attribute is set, the value should be the default value." ) ; validValues . forEach ( function ( 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 ( contentAttr ) ; element . setAttribute ( contentAttr , v . toUpperCase ( ) ) ; is ( element [ idlAttr ] , v , "Enumerated attributes should be case-insensitive." ) ; is ( element . getAttribute ( contentAttr ) , v . toUpperCase ( ) , "Content attribute should not be lower-cased." ) ; element . removeAttribute ( contentAttr ) ; 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 ( contentAttr ) ; element [ idlAttr ] = v . toUpperCase ( ) ; is ( element [ idlAttr ] , v , "Enumerated attributes should be case-insensitive." ) ; is ( element . getAttribute ( contentAttr ) , v . toUpperCase ( ) , "Content attribute should not be lower-cased." ) ; element . removeAttribute ( contentAttr ) ; } ) ; invalidValues . forEach ( function ( v ) { 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 ( contentAttr ) , v , "Content attribute should not have been changed." ) ; element . removeAttribute ( contentAttr ) ; 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 ( contentAttr ) , v , "Content attribute should not have been changed." ) ; element . removeAttribute ( contentAttr ) ; } ) ; unsupportedValues . forEach ( function ( 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 ( contentAttr ) ; element . setAttribute ( contentAttr , v . toUpperCase ( ) ) ; todo_is ( element [ idlAttr ] , v , "Enumerated attributes should be case-insensitive." ) ; is ( element . getAttribute ( contentAttr ) , v . toUpperCase ( ) , "Content attribute should not be lower-cased." ) ; element . removeAttribute ( contentAttr ) ; 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 ( contentAttr ) ; element [ idlAttr ] = v . toUpperCase ( ) ; todo_is ( element [ idlAttr ] , v , "Enumerated attributes should be case-insensitive." ) ; is ( element . getAttribute ( contentAttr ) , v . toUpperCase ( ) , "Content attribute should not be lower-cased." ) ; element . removeAttribute ( contentAttr ) ; } ) ; }
Checks that a given attribute is correctly reflected as limited to known
 values enumerated attribute.
Checks that a given attribute is correctly reflected as limited to known values enumerated attribute .
// Explicitly check the default value. // Check valid values. // Check invalid values. // Check valid values we currently do not support. // Basically, it's like the checks for the valid values but with some todo's.