Bug 682239 - Tests all HTMLFormElement attributes reflection. r=Ms2ger
authorMounir Lamouri <mounir.lamouri@gmail.com>
Fri, 26 Aug 2011 16:30:02 +0200
changeset 75953 3faac1e63f5741c9cc0739ac1a5ca1b16c0ffae5
parent 75952 84cf502e938a46a3ce92d52c8227dd9179a184b2
child 75954 d369283b0c708b97aa549e90a31d5240849c692b
push id21075
push usermak77@bonardo.net
push dateSat, 27 Aug 2011 08:41:23 +0000
treeherdermozilla-central@6c8a909977d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs682239
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 682239 - Tests all HTMLFormElement attributes reflection. r=Ms2ger
content/html/content/test/Makefile.in
content/html/content/test/forms/test_form_attributes_reflection.html
content/html/content/test/reflect.js
content/html/content/test/test_bug557628.html
content/html/content/test/test_bug585508.html
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -208,17 +208,16 @@ include $(topsrcdir)/config/rules.mk
 		test_bug588683-2.html \
 		test_bug588683-3.html \
 		test_bug588683-4.html \
 		test_bug590353-1.html \
 		test_bug590353-2.html \
 		test_bug593689.html \
 		test_bug561636.html \
 		test_bug590363.html \
-		test_bug557628.html \
 		test_bug592802.html \
 		test_bug595429.html \
 		test_bug595447.html \
 		test_bug595449.html \
 		test_bug557087-1.html \
 		test_bug557087-2.html \
 		test_bug557087-3.html \
 		test_bug557087-4.html \
--- a/content/html/content/test/forms/test_form_attributes_reflection.html
+++ b/content/html/content/test/forms/test_form_attributes_reflection.html
@@ -10,28 +10,78 @@
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** 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({
   element: document.createElement("form"),
   attribute: "noValidate",
 });
 
-// TODO: target
+// .target
+reflectString({
+  element: document.createElement("form"),
+  attribute: "target",
+  otherValues: [ "_blank", "_self", "_parent", "_top" ],
+});
 
 </script>
 </pre>
 </body>
 </html>
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -232,118 +232,123 @@ 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
+ *     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
  */
 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);
   });
 }
 
 /**
  * Checks that a given attribute is correctly reflected as a boolean.
  *
  * @param aParameters    Object    object containing the parameters, which are:
  *  - element            Element   node to test on
deleted file mode 100644
--- a/content/html/content/test/test_bug557628.html
+++ /dev/null
@@ -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>
--- a/content/html/content/test/test_bug585508.html
+++ b/content/html/content/test/test_bug585508.html
@@ -56,20 +56,17 @@ function checkAttribute(form, attrName, 
     form.setAttribute(attrName, data[2][i]);
     is(form.getAttribute(attrName), data[2][i],
        "getAttribute should return the content attribute");
     is(form[idlName], data[0][0], "When getting, " + idlName + " IDL attribute " +
        "should return the default value if the content attribute value isn't known");
   }
 }
 
-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);
 
 </script>
 </pre>
 </body>
 </html>