Bug 346485 - "Implement output element -- Test" [r=smaug]
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 22 Apr 2010 07:03:00 -0400
changeset 41439 9e373d1c6707fd49efb997fe052486667f06b972
parent 41438 5c4ecf53b751423ce46dd22bee9ca47047d189e9
child 41440 4f2c2898fabe8905d6505ceed50b450169bf6ed3
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs346485
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 346485 - "Implement output element -- Test" [r=smaug]
content/base/test/Makefile.in
content/base/test/test_bug346485.html
content/html/content/test/Makefile.in
content/html/content/test/test_bug346485.html
layout/reftests/forms/output/output-1.html
layout/reftests/forms/output/output-2.html
layout/reftests/forms/output/output-3.html
layout/reftests/forms/output/output-4.html
layout/reftests/forms/output/output-5.html
layout/reftests/forms/output/output-6.html
layout/reftests/forms/output/output-7.html
layout/reftests/forms/output/output-ref-2.html
layout/reftests/forms/output/output-ref-3.html
layout/reftests/forms/output/output-ref.html
layout/reftests/forms/output/reftest.list
layout/reftests/forms/reftest.list
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -373,16 +373,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug558726.html \
 		test_bug557892.html \
 		file_bug557892.html \
 		test_bug559526.html \
 		test_csp_redirects.html \
 		file_csp_redirects_page.sjs \
 		file_csp_redirects_main.html \
 		file_csp_redirects_resource.sjs \
+        test_bug346485.html \
 		$(NULL)
 
 # This test fails on the Mac for some reason
 ifneq (,$(filter gtk2 windows,$(MOZ_WIDGET_TOOLKIT)))
 _TEST_FILES += 	test_copyimage.html \
 		$(NULL)
 endif
 
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug346485.html
@@ -0,0 +1,77 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=346485
+-->
+<head>
+  <title>Test for Bug 346485</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=346485">Mozilla Bug 346485</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <input id='a'>
+  <input id='b'>
+  <output id='o' for='a b'></output>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 346485 **/
+
+/**
+ * This test is testing DOMSettableTokenList used by the output element.
+ */
+
+var o = document.getElementById('o');
+
+is(o.htmlFor, 'a b',
+  "htmlFor IDL attribute should reflect for content attribute");
+
+is(o.htmlFor.value, 'a b',
+  "value should return the underlying string");
+
+is(o.htmlFor.length, 2, "Size should be '2'");
+
+ok(o.htmlFor.contains('a'), "It should contain 'a' token'");
+ok(!o.htmlFor.contains('c'), "It should not contain 'c' token");
+
+is(o.htmlFor.item(0), 'a', "First item is 'a' token'");
+is(o.htmlFor.item(42), null, "Out-of-range should return null");
+
+o.htmlFor.add('c');
+is(o.htmlFor, 'a b c', "'c' token should have been added");
+is(o.htmlFor.length, 3, "Size should be '3'");
+
+o.htmlFor.add('a');
+is(o.htmlFor, 'a b c', "Nothing should have changed");
+is(o.htmlFor.length, 3, "Size should be '3'");
+
+o.htmlFor.remove('a');
+is(o.htmlFor, 'b c', "'a' token should have been removed");
+is(o.htmlFor.length, 2, "Size should be '2'");
+
+o.htmlFor.remove('d');
+is(o.htmlFor, 'b c', "Nothing should have been removed");
+is(o.htmlFor.length, 2, "Size should be '2'");
+
+o.htmlFor.toggle('a');
+is(o.htmlFor, 'b c a', "'a' token should have been added");
+is(o.htmlFor.length, 3, "Size should be '3'");
+
+o.htmlFor.toggle('b');
+is(o.htmlFor, 'c a', "Nothing should have changed");
+is(o.htmlFor.length, 2, "Size should be '2'");
+
+o.htmlFor.value = "foo bar";
+is(o.htmlFor, 'foo bar', "The underlying string should have changed");
+is(o.htmlFor.length, 2, "Size should be '2'");
+ok(o.htmlFor.contains('foo'), "It should contain 'foo'");
+
+</script>
+</pre>
+</body>
+</html>
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -155,12 +155,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug535043.html \
 		test_bug547850.html \
 		test_bug457800.html \
 		test_bug536891.html \
 		test_bug536895.html \
 		test_bug458037.xhtml \
 		test_bug559284.html \
         test_bug551670.html \
+        test_bug346485.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/test_bug346485.html
@@ -0,0 +1,179 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=346485
+-->
+<head>
+  <title>Test for Bug 346485</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=346485">Mozilla Bug 346485</a>
+<p id="display"></p>
+<iframe name="submit_frame" onload="checkFormSubmission();" style="visibility: hidden;"></iframe>
+<div id="content" style="display: none">
+  <form id='f' method='get' target='submit_frame' action='foo'>
+    <input name='a' id='a'>
+    <input name='b' id='b'>
+    <output id='o' for='a b' name='output-name'>tulip</output>
+  </form>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 346485 **/
+
+function checkNameAttribute(element)
+{
+  function nameAttributeEquals(element, expectedValue)
+  {
+    is(element.name, expectedValue, "Output name IDL attribute is not correct");
+    is(element.getAttribute('name'), expectedValue,
+      "Output name content attribute is not correct");
+  }
+
+  nameAttributeEquals(element, "output-name");
+
+  element.name = "new-name";
+  nameAttributeEquals(element, "new-name");
+
+  element.setAttribute('name', 'new-name-2');
+  nameAttributeEquals(element, "new-name-2");
+}
+
+function checkValueAndDefaultValueIDLAttribute(element)
+{
+  is(element.value, element.textContent,
+    "The value IDL attribute should act like the textContent IDL attribute");
+
+  element.value = "foo";
+  is(element.value, "foo", "Value should be 'foo'");
+
+  is(element.defaultValue, "", "Default defaultValue is ''");
+
+  element.defaultValue = "bar";
+  is(element.defaultValue, "bar", "defaultValue should be 'bar'");
+
+  // More complex situation.
+  element.textContent = 'foo';
+  var b = document.createElement('b');
+  b.textContent = 'bar'
+  element.appendChild(b);
+  is(element.value, element.textContent,
+    "The value IDL attribute should act like the textContent IDL attribute");
+}
+
+function checkValueModeFlag(element)
+{
+  /**
+   * The value mode flag is the flag used to know if value should represent the
+   * textContent or the default value.
+   */
+  // value mode flag should be 'value'
+  isnot(element.defaultValue, element.value,
+    "When value is set, defaultValue keeps its value");
+
+  var f = document.getElementById('f');
+  f.reset();
+  // value mode flag should be 'default'
+  is(element.defaultValue, element.value, "When reset, defaultValue=value");
+  is(element.textContent, element.defaultValue,
+    "textContent should contain the defaultValue");
+}
+
+function checkDescendantChanged(element)
+{
+  /**
+   * Whenever a descendant is changed if the value mode flag is value,
+   * the default value should be the textContent value.
+   */
+  element.defaultValue = 'tulip';
+  element.value = 'foo';
+
+  // set value mode flag to 'default'
+  var f = document.getElementById('f');
+  f.reset();
+
+  is(element.textContent, element.defaultValue,
+    "textContent should contain the defaultValue");
+  element.textContent = "bar";
+  is(element.textContent, element.defaultValue,
+    "textContent should contain the defaultValue");
+}
+
+function checkFormIDLAttribute(element)
+{
+  is(element.form, document.getElementById('f'),
+    "form IDL attribute is invalid");
+}
+
+function checkHtmlForIDLAttribute(element)
+{
+  is(element.htmlFor, 'a b',
+    "htmlFor IDL attribute should reflect the for content attribute");
+
+  // DOMSettableTokenList is tested in another bug so we just test assignation
+  element.htmlFor.value = 'a b c';
+  is(element.htmlFor, 'a b c', "htmlFor shoud have changed");
+}
+
+function submitForm()
+{
+  // Setting the values for the submit.
+  document.getElementById('o').value = 'foo';
+  document.getElementById('a').value = 'afield';
+  document.getElementById('b').value = 'bfield';
+
+  // This will call checkFormSubmission() which is going to call ST.finish().
+  document.getElementById('f').submit();
+}
+
+function checkFormSubmission()
+{
+  /**
+   * All elements values have been set just before the submission.
+   * The input elements values should be in the submit url but the ouput
+   * element value should not appear.
+   */
+
+  is(frames['submit_frame'].location.href,
+    'http://mochi.test:8888/tests/content/html/content/test/foo?a=afield&b=bfield',
+     "The output element value should not be submitted");
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+
+var o = document.getElementsByTagName('output');
+is(o.length, 1, "There should be one output element");
+
+o = o[0];
+ok(o instanceof HTMLOutputElement,
+  "The output should be instance of HTMLOutputElement");
+
+o = document.getElementById('o');
+ok(o instanceof HTMLOutputElement,
+  "The output should be instance of HTMLOutputElement");
+
+is(o.type, "output", "Output type IDL attribute should be 'output'");
+
+checkNameAttribute(o);
+
+checkValueAndDefaultValueIDLAttribute(o);
+
+checkValueModeFlag(o);
+
+checkDescendantChanged(o);
+
+checkFormIDLAttribute(o);
+
+checkHtmlForIDLAttribute(o);
+
+submitForm();
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-1.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <!-- Test: the output shouldn't show anything when there is no content -->
+  <body>
+    <output></output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-2.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <!-- Test: the output should show the textContent -->
+  <body>
+    <output>foo</output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-3.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <!-- Test: the output should show its content -->
+  <body>
+    <output>foo<b>bar</b></output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-4.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html>
+  <!-- Test: the output should show its content -->
+  <body>
+    <output>foo<input></output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+  <!-- Test: the output element should show its default value -->
+  <script type="text/javascript">
+    function setDefaultValue()
+    {
+      document.getElementById('o').defaultValue = "foo";
+    }
+    function disableReftestWait()
+    {
+      document.documentElement.className = '';
+    }
+  </script>
+
+  <body onload="setDefaultValue(); disableReftestWait();">
+    <output id="o"></output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+  <!-- Test: the output element should show its value -->
+  <script type="text/javascript">
+    function setValue()
+    {
+      document.getElementById('o').value = "foo";
+    }
+    function disableReftestWait()
+    {
+      document.documentElement.className = '';
+    }
+  </script>
+
+  <body onload="setValue(); disableReftestWait();">
+    <output id="o"></output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-7.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+  <!-- Test: the output element should show its value -->
+  <script type="text/javascript">
+    function setDefaultValue()
+    {
+      document.getElementById('o').value = "bar";
+    }
+    function setValue()
+    {
+      document.getElementById('o').value = "foo";
+    }
+    function disableReftestWait()
+    {
+      document.documentElement.className = '';
+    }
+  </script>
+
+  <body onload="setDefaultValue(); setValue(); disableReftestWait();">
+    <output id="o"></output>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-ref-2.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    foo<b>bar</b>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-ref-3.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    foo<input>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/output-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    foo
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/output/reftest.list
@@ -0,0 +1,7 @@
+== output-1.html about:blank
+== output-2.html output-ref.html
+== output-3.html output-ref-2.html
+== output-4.html output-ref-3.html
+== output-5.html output-ref.html
+== output-6.html output-ref.html
+== output-7.html output-ref.html
--- a/layout/reftests/forms/reftest.list
+++ b/layout/reftests/forms/reftest.list
@@ -38,8 +38,11 @@ random-if(MOZ_WIDGET_TOOLKIT=="gtk2") !=
 != radio-checked-notref.html about:blank
 != checkbox-checked-native.html about:blank
 != checkbox-checked-native-notref.html about:blank
 != radio-checked-native.html about:blank
 != radio-checked-native-notref.html about:blank
 
 # placeholder
 include placeholder/reftest.list
+
+# output element
+include output/reftest.list