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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=566160
-->
<head>
<title>Test for Bug 566160</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=566160">Mozilla Bug 566160</a>
<p id="display"></p>
<style>
iframe { width: 130px; height: 100px;}
</style>
<iframe name='frame1' id='frame1'></iframe>
<iframe name='frame2' id='frame2'></iframe>
<iframe name='frame3' id='frame3'></iframe>
<iframe name='frame3bis' id='frame3bis'></iframe>
<iframe name='frame4' id='frame4'></iframe>
<iframe name='frame5' id='frame5'></iframe>
<iframe name='frame6' id='frame6'></iframe>
<iframe name='frame7' id='frame7'></iframe>
<iframe name='frame8' id='frame8'></iframe>
<iframe name='frame9' id='frame9'></iframe>
<div id="content">
<!-- submit controls with formaction that are validated with a CLICK -->
<form target="frame1" action="form_submit_server.sjs" method="POST">
<input name='foo' value='foo'>
<input type='submit' id='is' formenctype='multipart/form-data'>
</form>
<form target="frame2" action="form_submit_server.sjs" method="POST">
<input name='bar' value='bar'>
<input type='image' id='ii' formenctype='multipart/form-data'>
</form>
<form target="frame3" action="form_submit_server.sjs" method="POST">
<input name='tulip' value='tulip'>
<button type='submit' id='bs' formenctype="multipart/form-data">submit</button>
</form>
<form target="frame3bis" action="form_submit_server.sjs" method="POST">
<input name='tulipbis' value='tulipbis'>
<button type='submit' id='bsbis' formenctype="multipart/form-data">submit</button>
</form>
<!-- submit controls with formaction that are validated with ENTER -->
<form target="frame4" action="form_submit_server.sjs" method="POST">
<input name='footulip' value='footulip'>
<input type='submit' id='is2' formenctype="multipart/form-data">
</form>
<form target="frame5" action="form_submit_server.sjs" method="POST">
<input name='foobar' value='foobar'>
<input type='image' id='ii2' formenctype="multipart/form-data">
</form>
<form target="frame6" action="form_submit_server.sjs" method="POST">
<input name='tulip2' value='tulip2'>
<button type='submit' id='bs2' formenctype="multipart/form-data">submit</button>
</form>
<!-- check that when submitting a from from an element
which is not a submit control, @formaction isn't used -->
<form target='frame7' action="form_submit_server.sjs" method="POST">
<input id='enter' name='input' value='enter' formenctype="multipart/form-data">
</form>
<!-- If formenctype isn't set, it's default value shouldn't be used -->
<form target="frame8" action="form_submit_server.sjs" method="POST" enctype="multipart/form-data">
<input name='tulip8' value='tulip8'>
<input type='submit' id='i8'>
</form>
<!-- If formenctype is set but has an invalid value, the default value should
be used. -->
<form target="frame9" action="form_submit_server.sjs" method="POST" enctype="multipart/form-data">
<input name='tulip9' value='tulip9'>
<input type='submit' id='i9' formenctype="">
</form>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 566160 **/
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
setTimeout(runTests, 0);
});
var gTestResults = {
frame1: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"foo\\\"\"},\"body\":\"foo\"}]',
frame2: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"bar\\\"\"},\"body\":\"bar\"},{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"x\\\"\"},\"body\":\"0\"},{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"y\\\"\"},\"body\":\"0\"}]',
frame3: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"tulip\\\"\"},\"body\":\"tulip\"}]',
frame3bis: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"tulipbis\\\"\"},\"body\":\"tulipbis\"}]',
frame4: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"footulip\\\"\"},\"body\":\"footulip\"}]',
frame5: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"foobar\\\"\"},\"body\":\"foobar\"},{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"x\\\"\"},\"body\":\"0\"},{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"y\\\"\"},\"body\":\"0\"}]',
frame6: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"tulip2\\\"\"},\"body\":\"tulip2\"}]',
frame7: '[]',
frame8: '[{\"headers\":{\"Content-Disposition\":\"form-data; name=\\\"tulip8\\\"\"},\"body\":\"tulip8\"}]',
frame9: '[]',
};
var gPendingLoad = 0; // Has to be set after depending on the frames number.
function runTests()
{
// We add a load event for the frames which will be called when the forms
// will be submitted.
var frames = [ document.getElementById('frame1'),
document.getElementById('frame2'),
document.getElementById('frame3'),
document.getElementById('frame3bis'),
document.getElementById('frame4'),
document.getElementById('frame5'),
document.getElementById('frame6'),
document.getElementById('frame7'),
document.getElementById('frame8'),
document.getElementById('frame9'),
];
gPendingLoad = frames.length;
for (var i=0; i<frames.length; i++) {
frames[i].setAttribute('onload', "frameLoaded(this);");
}
/**
* We are going to focus each element before interacting with either for
* simulating the ENTER key (synthesizeKey) or a click (synthesizeMouse) or
* using .click(). This because it may be needed (ENTER) and because we want
* to have the element visible in the iframe.
*
* Focusing the first element (id='is') is launching the tests.
*/
document.getElementById('is').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeMouse(document.getElementById('is'), 5, 5, {});
document.getElementById('ii').focus();
}, false);
document.getElementById('ii').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeMouse(document.getElementById('ii'), 5, 5, {});
document.getElementById('bs').focus();
}, false);
document.getElementById('bs').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeMouse(document.getElementById('bs'), 5, 5, {});
document.getElementById('bsbis').focus();
}, false);
document.getElementById('bsbis').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
document.getElementById('bsbis').click();
document.getElementById('is2').focus();
}, false);
document.getElementById('is2').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeKey("VK_RETURN", {});
document.getElementById('ii2').focus();
}, false);
document.getElementById('ii2').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeKey("VK_RETURN", {});
document.getElementById('bs2').focus();
}, false);
document.getElementById('bs2').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeKey("VK_RETURN", {});
document.getElementById('enter').focus();
}, false);
document.getElementById('enter').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeKey("VK_RETURN", {});
document.getElementById('i8').focus();
}, false);
document.getElementById('i8').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeKey("VK_RETURN", {});
document.getElementById('i9').focus();
}, false);
document.getElementById('i9').addEventListener('focus', function(aEvent) {
aEvent.target.removeEventListener('focus', arguments.callee, false);
synthesizeKey("VK_RETURN", {});
}, false);
document.getElementById('is').focus();
}
function frameLoaded(aFrame) {
// Check if formaction/action has the correct behavior.
is(aFrame.contentDocument.documentElement.textContent, gTestResults[aFrame.name],
"the enctype/formenctype attribute doesn't have the correct behavior");
if (--gPendingLoad == 0) {
SimpleTest.finish();
}
}
</script>
</pre>
</body>
</html>
|