2009-10-25 04:13:30 +00:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=523771
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 523771</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=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">
|
|
|
|
<input id=singleFile name=singleFile type=file>
|
|
|
|
<input id=multiFile name=multiFile type=file multiple>
|
|
|
|
</form>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
2013-02-26 02:39:21 +00:00
|
|
|
|
2009-10-25 04:13:30 +00:00
|
|
|
singleFileInput = document.getElementById('singleFile');
|
|
|
|
multiFileInput = document.getElementById('multiFile');
|
2009-11-17 06:07:49 +00:00
|
|
|
var input1File = { name: "523771_file1", type: "", body: "file1 contents"};
|
2009-10-25 04:13:30 +00:00
|
|
|
var input2Files =
|
2009-11-17 06:07:49 +00:00
|
|
|
[{ name: "523771_file2", type: "", body: "second file contents" },
|
2009-10-25 04:13:30 +00:00
|
|
|
{ name: "523771_file3.txt", type: "text/plain", body: "123456" },
|
|
|
|
{ name: "523771_file4.html", type: "text/html", body: "<html>content</html>" }
|
|
|
|
];
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
|
|
|
function setFileInputs () {
|
2015-08-20 17:30:10 +00:00
|
|
|
var f = createFileWithData(input1File.name, input1File.body, input1File.type);
|
|
|
|
SpecialPowers.wrap(singleFileInput).mozSetFileArray([f]);
|
2009-10-25 04:13:30 +00:00
|
|
|
|
|
|
|
var input2FileNames = [];
|
2012-12-21 11:47:52 +00:00
|
|
|
for (file of input2Files) {
|
2015-08-20 17:30:10 +00:00
|
|
|
f = createFileWithData(file.name, file.body, file.type);
|
|
|
|
input2FileNames.push(f);
|
2009-10-25 04:13:30 +00:00
|
|
|
}
|
2015-08-20 17:30:10 +00:00
|
|
|
SpecialPowers.wrap(multiFileInput).mozSetFileArray(input2FileNames);
|
2009-10-25 04:13:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 17:30:10 +00:00
|
|
|
function createFileWithData(fileName, fileData, fileType) {
|
|
|
|
return new File([fileData], fileName, { type: fileType });
|
2009-10-25 04:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cleanupFiles() {
|
|
|
|
singleFileInput.value = "";
|
|
|
|
multiFileInput.value = "";
|
|
|
|
}
|
|
|
|
|
2009-10-27 18:14:34 +00:00
|
|
|
is(singleFileInput.files.length, 0, "single-file .files.length"); // bug 524421
|
|
|
|
is(multiFileInput.files.length, 0, "multi-file .files.length"); // bug 524421
|
|
|
|
|
2009-10-25 04:13:30 +00:00
|
|
|
setFileInputs();
|
|
|
|
|
|
|
|
is(singleFileInput.multiple, false, "single-file input .multiple");
|
|
|
|
is(multiFileInput.multiple, true, "multi-file input .multiple");
|
|
|
|
is(singleFileInput.value, input1File.name, "single-file input .value");
|
|
|
|
is(multiFileInput.value, input2Files[0].name, "multi-file input .value");
|
|
|
|
is(singleFileInput.files[0].name, input1File.name, "single-file input .files[n].name");
|
|
|
|
is(singleFileInput.files[0].size, input1File.body.length, "single-file input .files[n].size");
|
2009-11-17 02:01:40 +00:00
|
|
|
is(singleFileInput.files[0].type, input1File.type, "single-file input .files[n].type");
|
2009-10-25 04:13:30 +00:00
|
|
|
for(i = 0; i < input2Files.length; ++i) {
|
|
|
|
is(multiFileInput.files[i].name, input2Files[i].name, "multi-file input .files[n].name");
|
|
|
|
is(multiFileInput.files[i].size, input2Files[i].body.length, "multi-file input .files[n].size");
|
2009-11-17 02:01:40 +00:00
|
|
|
is(multiFileInput.files[i].type, input2Files[i].type, "multi-file input .files[n].type");
|
2009-10-25 04:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('form').submit();
|
|
|
|
iframe = document.getElementById('target_iframe');
|
|
|
|
iframe.onload = function() {
|
|
|
|
response = JSON.parse(iframe.contentDocument.documentElement.textContent);
|
|
|
|
is(response[0].headers["Content-Disposition"],
|
|
|
|
"form-data; name=\"singleFile\"; filename=\"" + input1File.name +
|
|
|
|
"\"",
|
|
|
|
"singleFile Content-Disposition");
|
|
|
|
is(response[0].headers["Content-Type"], input1File.type || "application/octet-stream",
|
|
|
|
"singleFile Content-Type");
|
|
|
|
is(response[0].body, input1File.body, "singleFile body");
|
|
|
|
|
|
|
|
for(i = 0; i < input2Files.length; ++i) {
|
|
|
|
is(response[i + 1].headers["Content-Disposition"],
|
|
|
|
"form-data; name=\"multiFile\"; filename=\"" + input2Files[i].name +
|
|
|
|
"\"",
|
|
|
|
"multiFile Content-Disposition");
|
|
|
|
is(response[i + 1].headers["Content-Type"], input2Files[i].type || "application/octet-stream",
|
|
|
|
"multiFile Content-Type");
|
|
|
|
is(response[i + 1].body, input2Files[i].body, "multiFile body");
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanupFiles();
|
2009-10-27 18:14:34 +00:00
|
|
|
|
|
|
|
is(singleFileInput.files.length, 0, "single-file .files.length"); // bug 524421
|
|
|
|
is(multiFileInput.files.length, 0, "multi-file .files.length"); // bug 524421
|
|
|
|
|
2009-10-25 04:13:30 +00:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|