Bug 843627 part 4. Add IDL attribute reflection tests for <embed>, <applet>, <object>. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Sun, 17 Mar 2013 10:42:07 -0400
changeset 125122 ca91f19a36dbf32b52d3f42a91a194ce442f451f
parent 125121 4f79d9d9d818b6639987a190fe10f567d1d63b39
child 125123 946419184f9983a5ccd945cee78f0bbcaa6749d8
push id24770
push userbzbarsky@mozilla.com
push dateSun, 17 Mar 2013 14:45:36 +0000
treeherdermozilla-inbound@dd888bc71adc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs843627
milestone22.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 843627 part 4. Add IDL attribute reflection tests for <embed>, <applet>, <object>. r=peterv
content/html/content/test/Makefile.in
content/html/content/test/reflect.js
content/html/content/test/test_applet_attributes_reflection.html
content/html/content/test/test_embed_attributes_reflection.html
content/html/content/test/test_object_attributes_reflection.html
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -242,16 +242,19 @@ MOCHITEST_FILES = \
 		file_fullscreen-esc-exit.html \
 		file_fullscreen-esc-exit-inner.html \
 		file_fullscreen-rollback.html \
 		file_fullscreen-svg-element.html \
 		file_fullscreen-multiple.html \
 		file_fullscreen-multiple-inner.html \
 		test_li_attributes_reflection.html \
 		test_link_attributes_reflection.html \
+		test_object_attributes_reflection.html \
+		test_embed_attributes_reflection.html \
+		test_applet_attributes_reflection.html \
 		test_ol_attributes_reflection.html \
 		test_dl_attributes_reflection.html \
 		test_ul_attributes_reflection.html \
 		test_param_attributes_reflection.html \
 		test_base_attributes_reflection.html \
 		test_dir_attributes_reflection.html \
 		test_q_attributes_reflection.html \
 		test_html_attributes_reflection.html \
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -16,65 +16,76 @@
  * Checks that a given attribute is correctly reflected as a string.
  *
  * @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
+ *  - extendedAttributes Object   object which can have 'TreatNullAs': "EmptyString"
  */
 function reflectString(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 otherValues = aParameters.otherValues !== undefined
                       ? aParameters.otherValues : [];
+  var treatNullAs = aParameters.extendedAttributes ?
+        aParameters.extendedAttributes.TreatNullAs : null;
 
   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");
+     "'" + idlAttr + "' IDL attribute should be a string");
 
   // Tests when the attribute isn't set.
   is(element.getAttribute(contentAttr), null,
      "When not set, the content attribute should be null.");
   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(contentAttr, null);
   is(element.getAttribute(contentAttr), "null",
-     "null should have been stringified to 'null'");
+     "null should have been stringified to 'null' for '" + contentAttr + "'");
   is(element[idlAttr], "null",
-     "null should have been stringified to 'null'");
+      "null should have been stringified to 'null' for '" + idlAttr + "'");
   element.removeAttribute(contentAttr);
 
   element[idlAttr] = null;
   // TODO: remove this ugly hack when null stringification will work as expected.
   var todoAttrs = {
     form: [ "acceptCharset", "name", "target" ],
     input: [ "accept", "alt", "formTarget", "max", "min", "name", "pattern", "placeholder", "step", "defaultValue" ]
   };
   if (!(element.localName in todoAttrs) || todoAttrs[element.localName].indexOf(idlAttr) == -1) {
-    is(element.getAttribute(contentAttr), "null",
-       "null should have been stringified to 'null'");
-    is(element[idlAttr], "null", "null should have been stringified to 'null'");
+    if (treatNullAs == "EmptyString") {
+      is(element.getAttribute(contentAttr), "",
+         "null should have been stringified to '' for '" + contentAttr + "'");
+      is(element[idlAttr], "",
+         "null should have been stringified to '' for '" + idlAttr + "'");
+    } else {
+      is(element.getAttribute(contentAttr), "null",
+         "null should have been stringified to 'null' for '" + contentAttr + "'");
+      is(element[idlAttr], "null",
+         "null should have been stringified to 'null' for '" + contentAttr + "'");
+    }
     element.removeAttribute(contentAttr);
   } else {
     todo_is(element.getAttribute(contentAttr), "null",
-       "null should have been stringified to 'null'");
+       "null should have been stringified to 'null' for '" + contentAttr + "'");
     todo_is(element[idlAttr], "null",
-       "null should have been stringified to 'null'");
+       "null should have been stringified to 'null' for '" + contentAttr + "'");
     element.removeAttribute(contentAttr);
   }
 
   // Tests various strings.
   var stringsToTest = [
     // [ test value, expected result ]
     [ "", "" ],
     [ "null", "null" ],
@@ -101,26 +112,26 @@ function reflectString(aParameters)
       "bar" ]
   ];
 
   otherValues.forEach(function(v) { stringsToTest.push([v, v]) });
 
   stringsToTest.forEach(function([v, r]) {
     element.setAttribute(contentAttr, v);
     is(element[idlAttr], r,
-       "IDL attribute should return the value it has been set to.");
+       "IDL attribute '" + idlAttr + "' should return the value it has been set to.");
     is(element.getAttribute(contentAttr), r,
-       "Content attribute should return the value it has been set to.");
+       "Content attribute '" + contentAttr + "'should return the value it has been set to.");
     element.removeAttribute(contentAttr);
 
     element[idlAttr] = v;
     is(element[idlAttr], r,
-       "IDL attribute should return the value it has been set to.");
+       "IDL attribute '" + idlAttr + "' should return the value it has been set to.");
     is(element.getAttribute(contentAttr), r,
-       "Content attribute should return the value it has been set to.");
+       "Content attribute '" + contentAttr + "' should return the value it has been set to.");
     element.removeAttribute(contentAttr);
   });
 
   // Tests after removeAttribute() is called. Should be equivalent with not set.
   is(element.getAttribute(contentAttr), null,
      "When not set, the content attribute should be null.");
   is(element[idlAttr], "",
      "When not set, the IDL attribute should return the empty string");
@@ -265,17 +276,17 @@ function reflectLimitedEnumerated(aParam
                                    ? 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 : [];
 
   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");
+  is(typeof element[idlAttr], "string", "'" + idlAttr + "' IDL attribute should be a string");
 
   // Explicitly check the default value.
   element.removeAttribute(contentAttr);
   is(element[idlAttr], defaultValueMissing,
      "When no attribute is set, the value should be the default value.");
 
   // Check valid values.
   validValues.forEach(function (v) {
@@ -593,15 +604,15 @@ function reflectInt(aParameters)
  *  - attribute         String    name of the attribute
  *     OR
  *    attribute         Object    object containing two attributes, 'content' and 'idl'
  */
 function reflectURL(aParameters)
 {
   var element = aParameters.element;
   var contentAttr = typeof aParameters.attribute === "string"
-	              ? aParameters.attribute : aParameters.attribute.content;
+                      ? aParameters.attribute : aParameters.attribute.content;
   var idlAttr = typeof aParameters.attribute === "string"
                   ? aParameters.attribute : aParameters.attribute.idl;
 
   element[idlAttr] = "";
   is(element[idlAttr], document.URL, "Empty string should resolve to document URL");
 }
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_applet_attributes_reflection.html
@@ -0,0 +1,86 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for HTMLAppletElement attributes reflection</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="reflect.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for HTMLAppletElement attributes reflection **/
+
+// .align (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "align",
+});
+
+// .alt (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "alt",
+});
+
+// .archive (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "archive",
+});
+
+// .code (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "code",
+});
+
+// .codeBase (URL)
+reflectURL({
+  element: document.createElement("applet"),
+  attribute: "codeBase",
+});
+
+// .height (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "height",
+});
+
+// .hspace (unsigned int)
+reflectUnsignedInt({
+  element: document.createElement("applet"),
+  attribute: "hspace",
+});
+
+// .name (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "name",
+});
+
+// .object (URL)
+reflectURL({
+  element: document.createElement("applet"),
+  attribute: "object",
+});
+
+// .vspace (unsigned int)
+reflectUnsignedInt({
+  element: document.createElement("applet"),
+  attribute: "vspace",
+});
+
+// .width (String)
+reflectString({
+  element: document.createElement("applet"),
+  attribute: "width",
+});
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_embed_attributes_reflection.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for HTMLEmbedElement attributes reflection</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="reflect.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for HTMLEmbedElement attributes reflection **/
+
+// .src (URL)
+reflectURL({
+  element: document.createElement("embed"),
+  attribute: "src",
+});
+
+// .type (String)
+reflectString({
+  element: document.createElement("embed"),
+  attribute: "type",
+});
+
+// .width (String)
+reflectString({
+  element: document.createElement("embed"),
+  attribute: "width",
+});
+
+// .height (String)
+reflectString({
+  element: document.createElement("embed"),
+  attribute: "height",
+});
+
+// .align (String)
+reflectString({
+  element: document.createElement("embed"),
+  attribute: "align",
+});
+
+// .name (String)
+reflectString({
+  element: document.createElement("embed"),
+  attribute: "name",
+});
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_object_attributes_reflection.html
@@ -0,0 +1,117 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for HTMLObjectElement attributes reflection</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="reflect.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for HTMLObjectElement attributes reflection **/
+
+// .data (URL)
+reflectURL({
+  element: document.createElement("object"),
+  attribute: "data",
+});
+
+// .type (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "type",
+});
+
+// .name (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "name",
+});
+
+// .useMap (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "useMap",
+});
+
+// .width (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "width",
+});
+
+// .height (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "height",
+});
+
+// .align (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "align",
+});
+
+// .archive (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "archive",
+});
+
+// .code (URL)
+reflectURL({
+  element: document.createElement("object"),
+  attribute: "code",
+});
+
+// .declare (String)
+reflectBoolean({
+  element: document.createElement("object"),
+  attribute: "declare",
+});
+
+// .hspace (unsigned int)
+reflectUnsignedInt({
+  element: document.createElement("object"),
+  attribute: "hspace",
+});
+
+// .standby (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "standby",
+});
+
+// .vspace (unsigned int)
+reflectUnsignedInt({
+  element: document.createElement("object"),
+  attribute: "vspace",
+});
+
+// .codeBase (URL)
+reflectURL({
+  element: document.createElement("object"),
+  attribute: "codeBase",
+});
+
+// .codeType (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "codeType",
+});
+
+// .border (String)
+reflectString({
+  element: document.createElement("object"),
+  attribute: "border",
+  extendedAttributes: { TreatNullAs: "EmptyString" },
+});
+</script>
+</pre>
+</body>
+</html>