Bug 561636 (1/4) - Tests for form submission/validation. r=smaug a2.0=test-only
authorMounir Lamouri <mounir.lamouri@gmail.com>
Sat, 11 Sep 2010 06:06:57 +0200
changeset 52444 92ea14236f4689fe1cbec8829acd97d4a4ace77e
parent 52443 ef74d58e4e48f17cb5b199be922aa6ddcba65147
child 52445 c8685734392d330014eab550db9af25bc8d93cc6
push id15645
push usermlamouri@mozilla.com
push dateSat, 11 Sep 2010 04:22:15 +0000
treeherdermozilla-central@2779c55431a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs561636
milestone2.0b6pre
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 561636 (1/4) - Tests for form submission/validation. r=smaug a2.0=test-only
content/html/content/test/Makefile.in
content/html/content/test/test_bug561636.html
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -213,12 +213,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug590353-2.html \
 		test_bug593689.html \
 		test_bug583288-1.html \
 		test_bug583288-2.html \
 		test_bug583288-3.html \
 		583288_submit_server.sjs \
 		583288_redirect_server.sjs \
 		test_bug555840.html \
+		test_bug561636.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_bug561636.html
@@ -0,0 +1,111 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=561636
+-->
+<head>
+  <title>Test for Bug 561636</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="/tests/SimpleTest/EventUtils.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=561636">Mozilla Bug 561636</a>
+<p id="display"></p>
+<iframe style='width:50px; height: 50px;' name='t'></iframe>
+<iframe style='width:50px; height: 50px;' name='t2' id='i'></iframe>
+<div id="content">
+  <form target='t' action='data:text/html,'>
+    <input required>
+    <input id='a' type='submit'>
+  </form>
+  <form target='t' action='data:text/html,'>
+    <input type='checkbox' required>
+    <button id='b' type='submit'></button>
+  </form>
+  <form target='t' action='data:text/html,'>
+    <input id='c' required>
+  </form>
+  <form target='t' action='data:text/html,'>
+    <input>
+    <input id='s2' type='submit'>
+  </form>
+  <form target='t2' action='data:text/html,'>
+    <input required>
+  </form>
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 561636 **/
+
+var formSubmitted = [ false, false ];
+var invalidHandled = false;
+
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+var os = Components.classes['@mozilla.org/observer-service;1']
+                   .getService(Components.interfaces.nsIObserverService);
+var observers = os.enumerateObservers("invalidformsubmit");
+
+// The following test should not be done if there is no observer for
+// "invalidformsubmit" because the form submission will not be canceled in that
+// case.
+if (observers.hasMoreElements()) {
+  SimpleTest.waitForExplicitFinish();
+
+  // Initialize
+  document.forms[0].addEventListener('submit', function(aEvent) {
+    aEvent.target.removeEventListener('submit', arguments.callee, false);
+    formSubmitted[0] = true;
+  }, false);
+
+  document.forms[1].addEventListener('submit', function(aEvent) {
+    aEvent.target.removeEventListener('submit', arguments.callee, false);
+    formSubmitted[1] = true;
+  }, false);
+
+  document.forms[2].addEventListener('submit', function(aEvent) {
+    aEvent.target.removeEventListener('submit', arguments.callee, false);
+    formSubmitted[2] = true;
+  }, false);
+
+  document.forms[3].addEventListener('submit', function(aEvent) {
+    aEvent.target.removeEventListener('submit', arguments.callee, false);
+    formSubmitted[3] = true;
+
+    ok(!formSubmitted[0], "Form 1 should not have been submitted because invalid");
+    ok(!formSubmitted[1], "Form 2 should not have been submitted because invalid");
+    ok(!formSubmitted[2], "Form 3 should not have been submitted because invalid");
+    ok(formSubmitted[3], "Form 4 should have been submitted because valid");
+  }, false);
+
+  document.forms[4].elements[0].addEventListener('invalid', function(aEvent) {
+    aEvent.target.removeEventListener('invalid', arguments.callee, false);
+    invalidHandled = true;
+  }, false);
+
+  document.getElementById('i').addEventListener('load', function(aEvent) {
+    aEvent.target.removeEventListener('load', arguments.callee, false);
+
+    SimpleTest.executeSoon(function () {
+      ok(true, "Form 5 should have been submitted because submit() has been used even if invalid");
+      ok(!invalidHandled, "Invalid event should not have been sent");
+
+      SimpleTest.finish();
+    });
+  }, false);
+
+  document.getElementById('a').click();
+  document.getElementById('b').click();
+  var c = document.getElementById('c');
+  c.focus(); synthesizeKey("VK_RETURN", {type: "keypress"});
+  document.getElementById('s2').click();
+
+  document.forms[3].submit();
+}
+
+</script>
+</pre>
+</body>
+</html>