FormData should allow setting filename to empty
[WebKit-https.git] / LayoutTests / http / tests / local / formdata / send-form-data-with-empty-file-filename.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script src="resources/send-form-data-common.js"></script>
10 <script>
11 description("Test that filename passed to FormData.append() takes precedence over filename in File, even if empty.");
12
13 self.jsTestIsAsync = true;
14
15 function runTest()
16 {
17     debug("Sending FormData containing one file with custom empty filename:");
18     
19     var input = document.getElementsByTagName("input")[0];
20     if (window.eventSender) {
21         eventSender.beginDragWithFiles(['../resources/file-for-drag-to-send.txt']);
22         moveMouseToCenterOfElement(input);
23         eventSender.mouseUp();
24     }
25
26     var formData = new FormData;
27     formData.append("file", input.files[0], "");
28     var xhr = new XMLHttpRequest();
29     xhr.open("POST", "http://127.0.0.1:8000/xmlhttprequest/resources/multipart-post-echo-filenames.php", true);
30     xhr.onload = function() {
31         filename = xhr.responseText;
32         shouldBe("filename", "''");
33         formDataTestingCleanup();
34         finishJSTest();
35     }
36
37     xhr.send(formData);
38 }
39
40 if (window.eventSender) {
41     runTest();
42 } else {
43     debug("To run this test manually, please drag a file onto file input above");
44     document.getElementsByTagName("input")[0].onchange = runTest;
45 }
46
47 var successfullyParsed = true;
48 </script>
49 <script src="../../../../fast/js/resources/js-test-post.js"></script>
50 </body>
51 </html>
52