Bug 551846. Tests
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 24 May 2010 09:36:49 +1200
changeset 42582 9ee12ee8bf8eef02e42acd27512b53edc4ead6ef
parent 42581 680805a771ab1b868c533f0b906046cac3ed7ab2
child 42583 474b37dfdfb734b770e07161044261cd32d92e30
push idunknown
push userunknown
push dateunknown
bugs551846
milestone1.9.3a5pre
Bug 551846. Tests
content/html/content/test/Makefile.in
content/html/content/test/test_bug551846.html
layout/reftests/forms/reftest.list
layout/reftests/forms/select-multiple-ref.html
layout/reftests/forms/select-multiple.html
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -172,12 +172,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug546995-1.html \
 		test_bug546995-2.html \
 		test_bug546995-3.html \
 		test_bug546995-4.html \
 		test_bug546995-5.html \
 		file_bug546995.html \
 		test_bug377624.html \
 		test_bug562932.html \
+		test_bug551846.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_bug551846.html
@@ -0,0 +1,159 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=551846
+-->
+<head>
+  <title>Test for Bug 551846</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=551846">Mozilla Bug 551846</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  <select id='s'>
+    <option>Tulip</option>
+    <option>Lily</option>
+    <option>Gagea</option>
+    <option>Snowflake</option>
+    <option>Ismene</option>
+  </select>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 551846 **/
+
+function checkSizeReflection(element, defaultValue)
+{
+  is(element.size, defaultValue, "Default size should be " + defaultValue);
+
+  element.setAttribute('size', -15);
+  is(element.size, defaultValue,
+    "The reflecting IDL attribute should return the default value when content attribute value is invalid");
+  is(element.getAttribute('size'), -15,
+    "The content attribute should containt the previously set value");
+
+  element.setAttribute('size', 0);
+  is(element.size, defaultValue,
+    "The reflecting IDL attribute should return the default value when content attribute value is invalid");
+
+  element.setAttribute('size', 2147483647); /* PR_INT32_MAX */
+  is(element.size, 2147483647,
+    "PR_INT32_MAX should be considered as a valid value");
+  is(element.getAttribute('size'), 2147483647,
+    "The content attribute should containt the previously set value");
+
+  element.setAttribute('size', -2147483648); /* PR_INT32_MIN */
+  is(element.size, defaultValue,
+    "The reflecting IDL attribute should return the default value when content attribute value is invalid");
+  is(element.getAttribute('size'), -2147483648,
+    "The content attribute should containt the previously set value");
+
+  element.setAttribute('size', 'non-numerical-value');
+  is(element.size, defaultValue,
+    "The reflecting IDL attribute should return the default value when content attribute value is invalid");
+  is(element.getAttribute('size'), 'non-numerical-value',
+    "The content attribute should containt the previously set value");
+
+  element.setAttribute('size', 4294967294); /* PR_INT32_MAX * 2 */
+  is(element.size, defaultValue,
+    "Value greater than PR_INT32_MAX should be considered as invalid");
+  is(element.getAttribute('size'), 4294967294,
+    "The content attribute should containt the previously set value");
+
+  element.setAttribute('size', -4294967296); /* PR_INT32_MIN * 2 */
+  is(element.size, defaultValue,
+    "The reflecting IDL attribute should return the default value when content attribute value is invalid");
+  is(element.getAttribute('size'), -4294967296,
+    "The content attribute should containt the previously set value");
+
+  element.size = defaultValue + 1;
+  element.removeAttribute('size');
+  is(element.size, defaultValue,
+    "When the attribute is removed, the size should be the default size");
+
+  element.setAttribute('size', 'foobar');
+  is(element.size, defaultValue,
+    "The reflecting IDL attribute should return the default value when content attribute value is invalid");
+  element.removeAttribute('size');
+  is(element.size, defaultValue,
+    "When the attribute is removed, the size should be the default size");
+}
+
+function checkSetSizeException(element)
+{
+  var caught = false;
+
+  try {
+    element.size = 1;
+  } catch(e) {
+    caught = true;
+  }
+  ok(!caught, "Setting a valid size shouldn't throw an exception");
+
+  caught = false;
+  try {
+    element.size = 0;
+  } catch(e) {
+    caught = true;
+  }
+  ok(caught, "Setting an invalid size from the IDL should throw an exception");
+
+  caught = false;
+  try {
+    element.size = -1;
+  } catch(e) {
+    caught = true;
+  }
+  ok(caught, "Setting an invalid size from the IDL should throw an exception");
+
+  caught = false;
+  try {
+    element.setAttribute('size', -10);
+  } catch(e) {
+    caught = true;
+  }
+  ok(!caught, "Setting an invalid size in the content attribute shouldn't throw an exception");
+
+  // reverting to defalut
+  element.removeAttribute('size');
+}
+
+function checkSizeWhenChangeMultiple(element)
+{
+  s.setAttribute('size', -1)
+  is(s.size, 1, "Size IDL attribute should be 1");
+
+  s.multiple = true;
+  is(s.size, 4, "Size IDL attribute should be 4");
+
+  is(s.getAttribute('size'), -1, "Size content attribute should be -1");
+
+  s.setAttribute('size', -2);
+  is(s.size, 4, "Size IDL attribute should be 4");
+
+  s.multiple = false;
+  is(s.size, 1, "Size IDL attribute should be 1");
+
+  is(s.getAttribute('size'), -2, "Size content attribute should be -2");
+}
+
+var s = document.getElementById('s');
+
+checkSizeReflection(s, 1);
+checkSetSizeException(s);
+
+s.setAttribute('multiple', 'true');
+checkSizeReflection(s, 4);
+checkSetSizeException(s);
+s.removeAttribute('multiple');
+
+checkSizeWhenChangeMultiple(s);
+
+</script>
+</pre>
+</body>
+</html>
--- a/layout/reftests/forms/reftest.list
+++ b/layout/reftests/forms/reftest.list
@@ -36,16 +36,18 @@ random-if(MOZ_WIDGET_TOOLKIT=="gtk2") !=
 != checkbox-checked-notref.html about:blank
 != radio-checked.html about:blank
 != 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
 
+== select-multiple.html select-multiple-ref.html
+
 # placeholder
 include placeholder/reftest.list
 
 # input
 include input/reftest.list
 
 # output element
 include output/reftest.list
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/select-multiple-ref.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <select size='4'>
+      <option>Tulip</option>
+      <option>Lily</option>
+      <option>Gagea</option>
+      <option>Snowflake</option>
+      <option>Ismene</option>
+    </select>
+  </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/select-multiple.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+  <body>
+    <select multiple>
+      <option>Tulip</option>
+      <option>Lily</option>
+      <option>Gagea</option>
+      <option>Snowflake</option>
+      <option>Ismene</option>
+    </select>
+  </body>
+</html>