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
210
211
212
213
214
215
216
217
218
219
220
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=523771
-->
<head>
<title>Test for Bug 523771</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script 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=523771">Mozilla Bug 523771</a>
<p id="display"></p>
<iframe name="target_iframe" id="target_iframe"></iframe>
<form action="form_submit_server.sjs" target="target_iframe" id="form"
method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Control type</td>
<td>Name and value</td>
<td>Name, empty value</td>
<td>Name, no value</td>
<td>Empty name, with value</td>
<td>No name, with value</td>
<td>No name or value</td>
</tr>
<tr>
<td>Submit input</td>
<td><input type=submit name="n1_1" value="v1_1"></td>
<td><input type=submit name="n1_2" value=""></td>
<td><input type=submit name="n1_3"></td>
<td><input type=submit name="" value="v1_4"></td>
<td><input type=submit value="v1_5"></td>
<td><input type=submit></td>
</tr>
<tr>
<td>Image input</td>
<td><input type=image src="file_formSubmission_img.jpg" name="n2_1" value="v2_1"></td>
<td><input type=image src="file_formSubmission_img.jpg" name="n2_2" value=""></td>
<td><input type=image src="file_formSubmission_img.jpg" name="n2_3"></td>
<td><input type=image src="file_formSubmission_img.jpg" name="" value="v2_4"></td>
<td><input type=image src="file_formSubmission_img.jpg" value="v2_5"></td>
<td><input type=image src="file_formSubmission_img.jpg"></td>
</tr>
<tr>
<td>Submit button</td>
<td><button type=submit name="n3_1" value="v3_1"></button></td>
<td><button type=submit name="n3_2" value=""></button></td>
<td><button type=submit name="n3_3"></button></td>
<td><button type=submit name="" value="v3_4"></button></td>
<td><button type=submit value="v3_5"></button></td>
<td><button type=submit ></button></td>
</tr>
<tr>
<td>Submit button with text</td>
<td><button type=submit name="n4_1" value="v4_1">text here</button></td>
<td><button type=submit name="n4_2" value="">text here</button></td>
<td><button type=submit name="n4_3">text here</button></td>
<td><button type=submit name="" value="v4_4">text here</button></td>
<td><button type=submit value="v4_5">text here</button></td>
<td><button type=submit>text here</button></td>
</tr>
</table>
</form>
<pre id="test">
<script class="testbody" type="text/javascript">
var gen = runTest();
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
gen.next();
});
var expectedSub = [
// Submit input
[{ name: "n1_1", value: "v1_1" }],
[{ name: "n1_2", value: "" }],
[{ name: "n1_3", value: "Submit Query" }],
[],
[],
[],
// Image input
[{ name: "n2_1.x", value: "10" },
{ name: "n2_1.y", value: "7" }],
[{ name: "n2_2.x", value: "10" },
{ name: "n2_2.y", value: "7" }],
[{ name: "n2_3.x", value: "10" },
{ name: "n2_3.y", value: "7" }],
[{ name: "x", value: "10" },
{ name: "y", value: "7" }],
[{ name: "x", value: "10" },
{ name: "y", value: "7" }],
[{ name: "x", value: "10" },
{ name: "y", value: "7" }],
// Submit button
[{ name: "n3_1", value: "v3_1" }],
[{ name: "n3_2", value: "" }],
[{ name: "n3_3", value: "" }],
[],
[],
[],
// Submit button with text
[{ name: "n4_1", value: "v4_1" }],
[{ name: "n4_2", value: "" }],
[{ name: "n4_3", value: "" }],
[],
[],
[],
];
function checkSubmission(sub, expected) {
function getPropCount(o) {
var x, l = 0;
for (x in o) ++l;
return l;
}
is(sub.length, expected.length,
"Correct number of items");
var i;
for (i = 0; i < expected.length; ++i) {
if (!("fileName" in expected[i])) {
is(sub[i].headers["Content-Disposition"],
"form-data; name=\"" + expected[i].name + "\"",
"Correct name");
is (getPropCount(sub[i].headers), 1,
"Wrong number of headers");
}
else {
is(sub[i].headers["Content-Disposition"],
"form-data; name=\"" + expected[i].name + "\"; filename=\"" +
expected[i].fileName + "\"",
"Correct name");
is(sub[i].headers["Content-Type"],
expected[i].contentType,
"Correct content type");
is (getPropCount(sub[i].headers), 2,
"Wrong number of headers");
}
is(sub[i].body,
expected[i].value,
"Correct value");
}
}
function clickImage(aTarget, aX, aY)
{
aTarget.style.position = "absolute";
aTarget.style.top = "0";
aTarget.style.left = "0";
aTarget.offsetTop;
var wu = SpecialPowers.getDOMWindowUtils(aTarget.ownerDocument.defaultView);
wu.sendMouseEvent('mousedown', aX, aY, 0, 1, 0);
wu.sendMouseEvent('mouseup', aX, aY, 0, 0, 0);
aTarget.style.position = "";
aTarget.style.top = "";
aTarget.style.left = "";
}
function* runTest() {
// Make normal submission
var form = $("form");
var iframe = $("target_iframe");
iframe.onload = function() { gen.next(); };
var elements = form.querySelectorAll("input, button");
is(elements.length, expectedSub.length,
"tests vs. expected out of sync");
var i;
for (i = 0; i < elements.length && i < expectedSub.length; ++i) {
elem = elements[i];
if (elem.localName != "input" || elem.type != "image") {
elem.click();
}
else {
clickImage(elem, 10, 7);
}
yield undefined;
var submission = JSON.parse(iframe.contentDocument.documentElement.textContent);
checkSubmission(submission, expectedSub[i]);
}
// Disabled controls
var i;
for (i = 0; i < elements.length && i < expectedSub.length; ++i) {
elem = elements[i];
form.onsubmit = function() {
elem.disabled = true;
}
if (elem.localName != "input" || elem.type != "image") {
elem.click();
}
else {
clickImage(elem, 10, 7);
}
yield undefined;
is(elem.disabled, true, "didn't disable");
elem.disabled = false;
form.onsubmit = undefined;
var submission = JSON.parse(iframe.contentDocument.documentElement.textContent);
checkSubmission(submission, []);
}
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>
|