1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=561636
-->
<head>
<title>Test for Bug 561636</title>
<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 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
function runTest()
{
var formSubmitted = [ false, false ];
var invalidHandled = false;
var os = SpecialPowers.Cc['@mozilla.org/observer-service;1']
.getService(SpecialPowers.Ci.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.finish();
return;
}
// 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");
// Next test.
document.forms[4].submit();
}, 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("KEY_Enter", { code: "Enter" });
document.getElementById('s2').click();
}
</script>
</pre>
</body>
</html>
|