OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <body> | |
4 <script src="../../../../resources/js-test.js"></script> | |
5 <script> | |
6 description("Test that we can send empty name in Formdata."); | |
sof
2014/10/10 06:27:10
"Test that empty names can be used in FormData.app
| |
7 | |
8 self.jsTestIsAsync = true; | |
9 | |
10 function shouldContain(string, substring, message) { | |
11 if (string.indexOf(substring) >= 0) { | |
12 testPassed(message); | |
13 } else { | |
14 testFailed("the formatdata containing"+ substring + " is failed to echo correctly"); | |
sof
2014/10/10 06:27:10
formatdata => FormData.
is failed => failed.
Also
| |
15 } | |
16 } | |
17 | |
18 var formDataString = new FormData(); | |
sof
2014/10/10 06:27:10
The String variable suffix doesn't seem to add muc
sof
2014/10/10 06:27:10
Could you wrap this up as firstTest() and then inv
| |
19 formDataString.append('', 'empty'); | |
20 formDataString.append('hello', 'world'); | |
21 var xhrString = new XMLHttpRequest(); | |
22 xhrString.open('POST', 'http://localhost:8000/xmlhttprequest/resources/post-echo .cgi', true); | |
sof
2014/10/10 06:27:11
local/ do run as local tests (despite being in htt
| |
23 | |
24 stringResponse = function() { | |
sof
2014/10/10 06:27:10
Just inline this as
xhrString.onload = function (
| |
25 if (xhrString.readyState == xhrString.DONE) { | |
26 shouldContain(xhrString.response, 'name=""\r\n\r\nempty', | |
27 'the formdata of string type containing a empty name is echoed corre ctly'); | |
28 shouldContain(xhrString.response, 'name="hello"\r\n\r\nworld', | |
29 'the formdata of string type containing a name is echoed correctly') ; | |
30 secondTest(); | |
31 } | |
32 } | |
33 xhrString.onreadystatechange = stringResponse; | |
sof
2014/10/10 06:27:10
onload is simpler, I think. Then you don't need to
| |
34 xhrString.send(formDataString); | |
35 | |
36 function secondTest() { | |
37 var formDataFile = new FormData(); | |
sof
2014/10/10 06:27:11
The File variable suffix doesn't seem to add much,
| |
38 formDataFile.append('', new Blob(), 'empty-name.txt'); | |
39 formDataFile.append('testFile', new Blob(), 'custom-name.txt'); | |
40 var xhrFile = new XMLHttpRequest(); | |
41 xhrFile.open('POST', 'http://localhost:8000/xmlhttprequest/resources/post-ec ho.cgi', true); | |
sof
2014/10/10 06:27:10
localhost => 127.0.0.1
| |
42 | |
43 fileResponse = function() { | |
sof
2014/10/10 06:27:11
xhr.onload = function () {
...
};
| |
44 if (xhrFile.readyState == xhrFile.DONE) { | |
45 shouldContain(xhrFile.response, 'name=""; filename="empty-name.txt"' , | |
46 'the formdata of file type containing a empty name is echoed cor rectly.'); | |
47 shouldContain(xhrFile.response, 'name="testFile"; filename="custom-n ame.txt"', | |
48 'the formdata of file type containing a name is echoed correctly .'); | |
49 finishJSTest(); | |
50 } | |
51 } | |
52 xhrFile.onreadystatechange = fileResponse; | |
53 xhrFile.send(formDataFile); | |
54 } | |
55 </script> | |
56 </body> | |
57 </html> | |
OLD | NEW |