Bug 665866 - Use reflect.js for input.type and button.type reflection tests. r=Ms2ger
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 27 Jun 2011 15:33:16 +0200
changeset 72393 663cc0ea79ccc9df687a419060252c8be4d3e5ef
parent 72392 d7ed8936e9f8d64884467d0632472ab807d8bd5b
child 72394 53a8eddbd9a483ac943447dddab792086c344b1d
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs665866
milestone7.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 665866 - Use reflect.js for input.type and button.type reflection tests. r=Ms2ger
content/html/content/test/Makefile.in
content/html/content/test/forms/Makefile.in
content/html/content/test/forms/test_button_attributes_reflection.html
content/html/content/test/forms/test_input_attributes_reflection.html
content/html/content/test/reflect.js
content/html/content/test/test_bug551670.html
content/html/content/test/test_bug660663.html
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -176,17 +176,16 @@ include $(topsrcdir)/config/rules.mk
 		test_bug529859.html \
 		test_bug535043.html \
 		test_bug547850.html \
 		test_bug457800.html \
 		test_bug536891.html \
 		test_bug536895.html \
 		test_bug458037.xhtml \
 		test_bug556645.html \
-		test_bug551670.html \
 		test_bug555567.html \
 		test_bug557620.html \
 		test_bug456229.html \
 		test_bug546995.html \
 		test_bug377624.html \
 		test_bug551846.html \
 		test_bug564001.html \
 		test_bug566046.html \
--- a/content/html/content/test/forms/Makefile.in
+++ b/content/html/content/test/forms/Makefile.in
@@ -42,22 +42,24 @@ relativesrcdir = content/html/content/te
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES = \
 		save_restore_radio_groups.sjs \
 		test_save_restore_radio_groups.html \
 		test_mozistextfield.html \
+		test_input_attributes_reflection.html \
 		test_input_email.html \
 		test_input_url.html \
 		test_pattern_attribute.html \
 		test_required_attribute.html \
 		test_novalidate_attribute.html \
 		test_formaction_attribute.html \
 		test_formnovalidate_attribute.html \
 		test_label_control_attribute.html \
 		test_output_element.html \
+		test_button_attributes_reflection.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/forms/test_button_attributes_reflection.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=551670
+-->
+<head>
+  <title>Test for Bug 551670</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <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>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551670">Mozilla Bug 551670</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 551670 **/
+
+// .type
+reflectLimitedEnumerated(document.createElement("button"),
+                         "type",
+                         [ "submit", "reset", "button" ],
+                         [ "this-is-probably-a-wrong-type", "", "tulip" ],
+                         "submit");
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/forms/test_input_attributes_reflection.html
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=551670
+-->
+<head>
+  <title>Test for Bug 551670</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <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>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=551670">Mozilla Bug 551670</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 551670 **/
+
+// .type
+reflectLimitedEnumerated(document.createElement("input"),
+                         "type",
+                         [ "hidden", "text", "search", "tel", "url", "email",
+                           "password", "checkbox", "radio", "file", "submit",
+                           "image", "reset", "button" ],
+                         [ "this-is-probably-a-wrong-type", "", "tulip" ],
+                         "text",
+                         [ "datetime", "date", "month", "week", "time",
+                           "datetime-local", "number", "range", "color" ]);
+
+</script>
+</pre>
+</body>
+</html>
--- a/content/html/content/test/reflect.js
+++ b/content/html/content/test/reflect.js
@@ -92,48 +92,105 @@ function reflectUnsignedInt(aElement, aA
   } else {
     is(aElement[aAttr], 0, "." + aAttr + " should be equals to 0");
   }
 }
 
 /**
  * @param aElement            Element     node to test on
  * @param aAttr               String      name of the attribute
- * @param aSupportedValues    Array       values we supported
- * @param aUnsupportedValues  Array       values we don't support
+ * @param aValidValues        Array       valid values we support
+ * @param aInvalidValues      Array       invalid values
+ * @param aDefaultValue       String      default value when no valid value is set [optional]
+ * @param aUnsupportedValues  Array       valid values we do not support [optional]
  */
-function reflectLimitedEnumerated(aElement, aAttr, aSupportedValues,
-                                  aUnsupportedValues)
+function reflectLimitedEnumerated(aElement, aAttr, aValidValues, aInvalidValues,
+                                  aDefaultValue, aUnsupportedValues)
 {
-  aSupportedValues.forEach(function (v) {
+  var defaultValue = aDefaultValue !== undefined ? aDefaultValue : "";
+  var unsupportedValues = aUnsupportedValues !== undefined ? aUnsupportedValues
+                                                           : [];
+  // Explicitly check the default value.
+  aElement.removeAttribute(aAttr);
+  is(aElement[aAttr], defaultValue,
+     "When no attribute is set, the value should be the default value.");
+
+  // Check valid values.
+  aValidValues.forEach(function (v) {
     aElement.setAttribute(aAttr, v);
-    is(aElement[aAttr], v);
-    is(aElement.getAttribute(aAttr), v);
+    is(aElement[aAttr], v,
+       v + " should be accepted as a valid value for " + aAttr);
+    is(aElement.getAttribute(aAttr), v,
+       "Content attribute should return the value it has been set to.");
     aElement.removeAttribute(aAttr);
 
     aElement.setAttribute(aAttr, v.toUpperCase());
-    is(aElement[aAttr], v);
-    is(aElement.getAttribute(aAttr), v.toUpperCase());
+    is(aElement[aAttr], v,
+       "Enumerated attributes should be case-insensitive.");
+    is(aElement.getAttribute(aAttr), v.toUpperCase(),
+       "Content attribute should be upper-cased.");
     aElement.removeAttribute(aAttr);
 
     aElement[aAttr] = v;
-    is(aElement[aAttr], v);
-    is(aElement.getAttribute(aAttr), v);
+    is(aElement[aAttr], v,
+       v + " should be accepted as a valid value for " + aAttr);
+    is(aElement.getAttribute(aAttr), v,
+       "Content attribute should return the value it has been set to.");
     aElement.removeAttribute(aAttr);
 
     aElement[aAttr] = v.toUpperCase();
-    is(aElement[aAttr], v);
-    is(aElement.getAttribute(aAttr), v.toUpperCase());
+    is(aElement[aAttr], v,
+       "Enumerated attributes should be case-insensitive.");
+    is(aElement.getAttribute(aAttr), v.toUpperCase(),
+       "Content attribute should be upper-cased.");
     aElement.removeAttribute(aAttr);
   });
-  ["cheesecake"].concat(aUnsupportedValues).forEach(function (v) {
+
+  // Check invalid values.
+  aInvalidValues.forEach(function (v) {
     aElement.setAttribute(aAttr, v);
-    is(aElement[aAttr], "");
-    is(aElement.getAttribute(aAttr), v);
+    is(aElement[aAttr], defaultValue,
+       "When the content attribute is set to an invalid value, the default value should be returned.");
+    is(aElement.getAttribute(aAttr), v,
+       "Content attribute should not have been changed.");
     aElement.removeAttribute(aAttr);
 
     aElement[aAttr] = v;
-    is(aElement[aAttr], "");
-    is(aElement.getAttribute(aAttr), v);
+    is(aElement[aAttr], defaultValue,
+       "When the value is set to an invalid value, the default value should be returned.");
+    is(aElement.getAttribute(aAttr), v,
+       "Content attribute should not have been changed.");
+    aElement.removeAttribute(aAttr);
+  });
+
+  // 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) {
+    aElement.setAttribute(aAttr, v);
+    todo_is(aElement[aAttr], v,
+            v + " should be accepted as a valid value for " + aAttr);
+    is(aElement.getAttribute(aAttr), v,
+       "Content attribute should return the value it has been set to.");
+    aElement.removeAttribute(aAttr);
+
+    aElement.setAttribute(aAttr, v.toUpperCase());
+    todo_is(aElement[aAttr], v,
+            "Enumerated attributes should be case-insensitive.");
+    is(aElement.getAttribute(aAttr), v.toUpperCase(),
+       "Content attribute should be upper-cased.");
+    aElement.removeAttribute(aAttr);
+
+    aElement[aAttr] = v;
+    todo_is(aElement[aAttr], v,
+            v + " should be accepted as a valid value for " + aAttr);
+    is(aElement.getAttribute(aAttr), v,
+       "Content attribute should return the value it has been set to.");
+    aElement.removeAttribute(aAttr);
+
+    aElement[aAttr] = v.toUpperCase();
+    todo_is(aElement[aAttr], v,
+            "Enumerated attributes should be case-insensitive.");
+    is(aElement.getAttribute(aAttr), v.toUpperCase(),
+       "Content attribute should be upper-cased.");
     aElement.removeAttribute(aAttr);
   });
 }
 
deleted file mode 100644
--- a/content/html/content/test/test_bug551670.html
+++ /dev/null
@@ -1,102 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=551670
--->
-<head>
-  <title>Test for Bug 551670</title>
-  <script type="application/javascript" src="/MochiKit/packed.js"></script>
-  <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=551670">Mozilla Bug 551670</a>
-<p id="display"></p>
-<div id="content" style="display: none">
-  <button type='badtype' id='b1'></button>
-  <button id='b2'></button>
-  <input type='badtype' id='i1'>
-  <input id='i2'>
-</div>
-<pre id="test">
-<script type="application/javascript">
-
-/** Test for Bug 551670 **/
-
-function checkType(e1, e2, defaultType, otherType, wrongType)
-{
-  // When accessing to the type attribute from the IDL,
-  // it should reflect the state of the button.
-
-  defaultType = defaultType.toLowerCase();
-  otherType = otherType.toLowerCase();
-
-  is(e1.type, defaultType,
-    "When the initial type attribute value is not valid, the state should be '" +
-    defaultType + "'");
-  is(e2.type, defaultType,
-    "When the type attribute is not set, the state should be '" +
-    defaultType + "'");
-
-  e1.type = otherType;
-  e1.setAttribute('type', '');
-  is(e1.type, defaultType,
-    "When type attribute is set to an empty string, the state should be '" +
-    defaultType + "'");
-
-  e1.type = otherType;
-  e1.type = '';
-  is(e1.type, defaultType,
-    "When type attribute is set to an empty string, the state should be '" +
-    defaultType + "'");
-
-  e1.type = otherType;
-  e1.setAttribute('type', wrongType);
-  is(e1.type, defaultType,
-    "When type attribute is set to an invalid value, the state should be '" +
-    defaultType + "'");
-  is(e1.getAttribute('type'), wrongType,
-    "Type attribute content should not be changed");
-
-  e1.type = otherType;
-  e1.type = wrongType;
-  is(e1.type, defaultType,
-    "When type attribute is set to an invalid value, the state should be '" +
-    defaultType + "'");
-  is(e1.getAttribute('type'), wrongType,
-    "Type attribute content should not be changed");
-
-  e1.type = otherType.toUpperCase();
-  is(e1.type, otherType, "Type attribute should be case insensitive");
-
-  e1.removeAttribute('type');
-  is(e1.type, defaultType,
-    "When type attribute is set to an empty string, the state should be '" +
-    defaultType + "'");
-}
-
-var wrongType = 'this-is-probably-a-wrong-type';
-
-// button types
-checkType(document.getElementById('b1'), document.getElementById('b2'), 'submit', 'button', wrongType);
-checkType(document.getElementById('b1'), document.getElementById('b2'), 'submit', 'reset', wrongType);
-
-// input types
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'button', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'checkbox', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'email', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'file', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'hidden', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'reset', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'image', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'password', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'radio', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'submit', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'tel', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'search', wrongType);
-checkType(document.getElementById('i1'), document.getElementById('i2'), 'text', 'url', wrongType);
-
-</script>
-</pre>
-</body>
-</html>
--- a/content/html/content/test/test_bug660663.html
+++ b/content/html/content/test/test_bug660663.html
@@ -17,13 +17,15 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 /** Test for Bug 660663 **/
 reflectLimitedEnumerated(document.createElement("div"),
                          "dir",
                          ["ltr", "rtl"],
+                         ["cheesecake", ""],
+                         undefined, // There is no default value.
                          ["auto"]);
 </script>
 </pre>
 </body>
 </html>