Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/post-formdata.html

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed most feedback. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <script src="/js-test-resources/js-test.js"></script>
4 <script>
5 description("Test verifies that FormData is sent correctly when using " +
6 "<a href='http://www.w3.org/TR/XMLHttpRequest/#the-send-method'>XMLH ttpRequest asynchronously.</a>");
7
8 var xhrFormDataTestUrl = '/xmlhttprequest/resources/multipart-post-echo.php';
9 var xhrFormDataTestCases = [{
10 data: { string: 'string value' },
11 result: "string=string value"
12 }, {
13 data: { bareBlob: new Blob(['blob-value']) },
14 result: 'bareBlob=blob:application/octet-stream:blob-value'
15 }, {
16 data: { mimeBlob: new Blob(['blob-value'], { type: 'text/html' }) },
17 result: 'mimeBlob=blob:text/html:blob-value'
18 }, {
19 data: {
20 namedBlob: {
21 value: new Blob(['blob-value']),
22 fileName: 'blob-file.txt'
23 }
24 },
25 result: 'namedBlob=blob-file.txt:application/octet-stream:blob-value'
26 }, {
27 data: { bareFile: new File(['file-value'], 'file-name.txt') },
28 result: 'bareFile=file-name.txt:application/octet-stream:file-value'
29 }, {
30 data: {
31 mimeFile: new File(['file-value'], 'file-name.html', { type: 'text/html' })
32 },
33 result: 'mimeFile=file-name.html:text/html:file-value'
34 }, {
35 data: {
36 renamedFile: {
37 value: new File(['file-value'], 'file-name.html', { type: 'text/html ' }),
38 fileName: 'file-name-override.html'
39 }
40 },
41 result: 'renamedFile=file-name-override.html:text/html:file-value'
42 }];
43
44 var xhr;
45 var expectedMimeType;
46 window.jsTestIsAsync = true;
47 var asyncTestCase = 0;
48
49 function runNextAsyncTest() {
50 asyncTestCase++;
51 runAsyncTests();
52 }
53
54 function reportResult(e) {
55 var testCase = xhrFormDataTestCases[asyncTestCase];
56 if (xhr.status === 200) {
57 echoResult = xhr.response;
58 shouldBeEqualToString("echoResult", testCase.result);
59 } else {
60 testFailed("Unknown error");
61 }
62
63 runNextAsyncTest();
64 }
65
66 function runAsyncTests() {
67 if (asyncTestCase >= xhrFormDataTestCases.length) {
68 finishJSTest();
69 return;
70 }
71
72 var testCase = xhrFormDataTestCases[asyncTestCase];
73 var formData = new FormData();
74 for (var fieldName in testCase.data) {
75 fieldValue = testCase.data[fieldName];
76 if (fieldValue.constructor === Object)
77 formData.append(fieldName, fieldValue.value, fieldValue.fileName);
78 else
79 formData.append(fieldName, fieldValue);
80 }
81
82 xhr = new XMLHttpRequest();
83 xhr.onloadend = reportResult;
84 xhr.open("POST", xhrFormDataTestUrl, true);
85 xhr.send(formData);
86 }
87
88 runAsyncTests();
89 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698