OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library multipart_test; | 5 library multipart_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:utf'; | 9 import 'dart:utf'; |
10 | 10 |
11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 expect(request, bodyMatches(''' | 69 expect(request, bodyMatches(''' |
70 --{{boundary}} | 70 --{{boundary}} |
71 content-disposition: form-data; name="field1" | 71 content-disposition: form-data; name="field1" |
72 | 72 |
73 value1 | 73 value1 |
74 --{{boundary}} | 74 --{{boundary}} |
75 content-disposition: form-data; name="field2" | 75 content-disposition: form-data; name="field2" |
76 | 76 |
77 value2 | 77 value2 |
78 --{{boundary}} | 78 --{{boundary}} |
79 content-type: text/plain; charset=UTF-8 | 79 content-type: text/plain; charset=utf-8 |
80 content-disposition: form-data; name="file1"; filename="filename1.txt" | 80 content-disposition: form-data; name="file1"; filename="filename1.txt" |
81 | 81 |
82 contents1 | 82 contents1 |
83 --{{boundary}} | 83 --{{boundary}} |
84 content-type: text/plain; charset=UTF-8 | 84 content-type: text/plain; charset=utf-8 |
85 content-disposition: form-data; name="file2" | 85 content-disposition: form-data; name="file2" |
86 | 86 |
87 contents2 | 87 contents2 |
88 --{{boundary}}-- | 88 --{{boundary}}-- |
89 ''')); | 89 ''')); |
90 }); | 90 }); |
91 | 91 |
92 test('with a unicode field name', () { | 92 test('with a unicode field name', () { |
93 var request = new http.MultipartRequest('POST', dummyUrl); | 93 var request = new http.MultipartRequest('POST', dummyUrl); |
94 request.fields['fïēld'] = 'value'; | 94 request.fields['fïēld'] = 'value'; |
95 | 95 |
96 expect(request, bodyMatches(''' | 96 expect(request, bodyMatches(''' |
97 --{{boundary}} | 97 --{{boundary}} |
98 content-disposition: form-data; name="f%C3%AF%C4%93ld" | 98 content-disposition: form-data; name="f%C3%AF%C4%93ld" |
99 | 99 |
100 value | 100 value |
101 --{{boundary}}-- | 101 --{{boundary}}-- |
102 ''')); | 102 ''')); |
103 }); | 103 }); |
104 | 104 |
105 test('with a unicode field value', () { | 105 test('with a unicode field value', () { |
106 var request = new http.MultipartRequest('POST', dummyUrl); | 106 var request = new http.MultipartRequest('POST', dummyUrl); |
107 request.fields['field'] = 'vⱥlūe'; | 107 request.fields['field'] = 'vⱥlūe'; |
108 | 108 |
109 expect(request, bodyMatches(''' | 109 expect(request, bodyMatches(''' |
110 --{{boundary}} | 110 --{{boundary}} |
111 content-disposition: form-data; name="field" | 111 content-disposition: form-data; name="field" |
112 content-type: text/plain; charset=UTF-8 | 112 content-type: text/plain; charset=utf-8 |
113 | 113 |
114 vⱥlūe | 114 vⱥlūe |
115 --{{boundary}}-- | 115 --{{boundary}}-- |
116 ''')); | 116 ''')); |
117 }); | 117 }); |
118 | 118 |
119 test('with a unicode filename', () { | 119 test('with a unicode filename', () { |
120 var request = new http.MultipartRequest('POST', dummyUrl); | 120 var request = new http.MultipartRequest('POST', dummyUrl); |
121 request.files.add(new http.MultipartFile.fromString('file', 'contents', | 121 request.files.add(new http.MultipartFile.fromString('file', 'contents', |
122 filename: 'fïlēname.txt')); | 122 filename: 'fïlēname.txt')); |
123 | 123 |
124 expect(request, bodyMatches(''' | 124 expect(request, bodyMatches(''' |
125 --{{boundary}} | 125 --{{boundary}} |
126 content-type: text/plain; charset=UTF-8 | 126 content-type: text/plain; charset=utf-8 |
127 content-disposition: form-data; name="file"; filename="f%C3%AFl%C4%93nam
e.txt" | 127 content-disposition: form-data; name="file"; filename="f%C3%AFl%C4%93nam
e.txt" |
128 | 128 |
129 contents | 129 contents |
130 --{{boundary}}-- | 130 --{{boundary}}-- |
131 ''')); | 131 ''')); |
132 }); | 132 }); |
133 | 133 |
134 test('with a string file with a content-type but no charset', () { | 134 test('with a string file with a content-type but no charset', () { |
135 var request = new http.MultipartRequest('POST', dummyUrl); | 135 var request = new http.MultipartRequest('POST', dummyUrl); |
136 var file = new http.MultipartFile.fromString('file', '{"hello": "world"}', | 136 var file = new http.MultipartFile.fromString('file', '{"hello": "world"}', |
137 contentType: new ContentType('application', 'json')); | 137 contentType: new ContentType('application', 'json')); |
138 request.files.add(file); | 138 request.files.add(file); |
139 | 139 |
140 expect(request, bodyMatches(''' | 140 expect(request, bodyMatches(''' |
141 --{{boundary}} | 141 --{{boundary}} |
142 content-type: application/json; charset=UTF-8 | 142 content-type: application/json; charset=utf-8 |
143 content-disposition: form-data; name="file" | 143 content-disposition: form-data; name="file" |
144 | 144 |
145 {"hello": "world"} | 145 {"hello": "world"} |
146 --{{boundary}}-- | 146 --{{boundary}}-- |
147 ''')); | 147 ''')); |
148 }); | 148 }); |
149 | 149 |
150 // TODO(nweiz): test creating a multipart file with a charset other than UTF-8 | 150 // TODO(nweiz): test creating a multipart file with a charset other than UTF-8 |
151 // once issue 6284 is fixed. | 151 // once issue 6284 is fixed. |
152 | 152 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 content-type: application/octet-stream | 226 content-type: application/octet-stream |
227 content-disposition: form-data; name="file"; filename="test-file" | 227 content-disposition: form-data; name="file"; filename="test-file" |
228 | 228 |
229 hello | 229 hello |
230 --{{boundary}}-- | 230 --{{boundary}}-- |
231 ''')); | 231 ''')); |
232 }), completes); | 232 }), completes); |
233 }); | 233 }); |
234 }); | 234 }); |
235 } | 235 } |
OLD | NEW |