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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=428135
-->
<head>
<title>Test for Bug 428135</title>
<script type="text/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=428135">Mozilla Bug 428135</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for Bug 428135 **/
var expectedCurrentTargets = new Array();
function d(el, ename) {
var e = document.createEvent("Events");
e.initEvent(ename, true, true);
el.dispatchEvent(e);
}
function testListener(e) {
e.preventDefault();
var expected = expectedCurrentTargets.shift();
ok(expected == e.currentTarget,
"Unexpected current target [" + e.currentTarget + "], event=" + e.type +
", phase=" + e.eventPhase + ", target should have been " + expected);
}
function getAndAddListeners(elname) {
var el = document;
if (elname) {
el = document.getElementById(elname);
}
el.addEventListener("submit", testListener, true);
el.addEventListener("submit", testListener, false);
el.addEventListener("reset", testListener, true);
el.addEventListener("reset", testListener, false);
el.addEventListener("fooEvent", testListener, true);
el.addEventListener("fooEvent", testListener, false);
return el;
}
function testSubmitResetEvents() {
getAndAddListeners(null);
var outerForm = getAndAddListeners("outerForm");
var outerSubmit = getAndAddListeners("outerSubmit");
var outerReset = getAndAddListeners("outerReset");
var outerSubmitDispatcher = getAndAddListeners("outerSubmitDispatcher");
var outerResetDispatcher = getAndAddListeners("outerResetDispatcher");
var outerChild = getAndAddListeners("outerChild");
var innerForm = getAndAddListeners("innerForm");
var innerSubmit = getAndAddListeners("innerSubmit");
var innerReset = getAndAddListeners("innerReset");
var innerSubmitDispatcher = getAndAddListeners("innerSubmitDispatcher");
var innerResetDispatcher = getAndAddListeners("innerResetDispatcher");
expectedCurrentTargets = new Array(document, outerForm, outerForm, document);
outerSubmit.click();
ok(expectedCurrentTargets.length == 0,
"(1) expectedCurrentTargets isn't empty!");
expectedCurrentTargets = new Array(document, outerForm, outerForm, document);
outerReset.click();
ok(expectedCurrentTargets.length == 0,
"(2) expectedCurrentTargets isn't empty!");
// Because of bug 428135, submit shouldn't propagate
// back to outerForm and document!
expectedCurrentTargets =
new Array(document, outerForm, outerSubmitDispatcher, outerSubmitDispatcher);
outerSubmitDispatcher.click();
ok(expectedCurrentTargets.length == 0,
"(3) expectedCurrentTargets isn't empty!");
// Because of bug 428135, reset shouldn't propagate
// back to outerForm and document!
expectedCurrentTargets =
new Array(document, outerForm, outerResetDispatcher, outerResetDispatcher);
outerResetDispatcher.click();
ok(expectedCurrentTargets.length == 0,
"(4) expectedCurrentTargets isn't empty!");
// Because of bug 428135, submit shouldn't propagate
// back to outerForm and document!
expectedCurrentTargets =
new Array(document, outerForm, outerChild, innerForm, innerForm, outerChild);
innerSubmit.click();
ok(expectedCurrentTargets.length == 0,
"(5) expectedCurrentTargets isn't empty!");
// Because of bug 428135, reset shouldn't propagate
// back to outerForm and document!
expectedCurrentTargets =
new Array(document, outerForm, outerChild, innerForm, innerForm, outerChild);
innerReset.click();
ok(expectedCurrentTargets.length == 0,
"(6) expectedCurrentTargets isn't empty!");
// Because of bug 428135, submit shouldn't propagate
// back to inner/outerForm or document!
expectedCurrentTargets =
new Array(document, outerForm, outerChild, innerForm, innerSubmitDispatcher,
innerSubmitDispatcher);
innerSubmitDispatcher.click();
ok(expectedCurrentTargets.length == 0,
"(7) expectedCurrentTargets isn't empty!");
// Because of bug 428135, reset shouldn't propagate
// back to inner/outerForm or document!
expectedCurrentTargets =
new Array(document, outerForm, outerChild, innerForm, innerResetDispatcher,
innerResetDispatcher);
innerResetDispatcher.click();
ok(expectedCurrentTargets.length == 0,
"(8) expectedCurrentTargets isn't empty!");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(testSubmitResetEvents);
addLoadEvent(SimpleTest.finish);
]]>
</script>
</pre>
<form id="outerForm">
<input type="submit" value="outer" id="outerSubmit"/>
<input type="reset" value="reset outer" id="outerReset"/>
<input type="button" value="dispatch submit" onclick="d(this, 'submit')"
id="outerSubmitDispatcher"/>
<input type="button" value="dispatch reset" onclick="d(this, 'reset')"
id="outerResetDispatcher"/>
<div id="outerChild">
<form id="innerForm">
<input type="submit" value="inner" id="innerSubmit"/>
<input type="reset" value="reset inner" id="innerReset"/>
<input type="button" value="dispatch submit" onclick="d(this, 'submit')"
id="innerSubmitDispatcher"/>
<input type="button" value="dispatch reset" onclick="d(this, 'reset')"
id="innerResetDispatcher"/>
</form>
</div>
</form>
</body>
</html>
|