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

Side by Side Diff: pkg/http/test/request_test.dart

Issue 12440002: Make instances of HeaderValue and ContentType immutable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from nweiz@ Created 7 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « pkg/http/test/multipart_test.dart ('k') | sdk/lib/io/http.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 request_test; 5 library request_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import '../lib/http.dart' as http; 10 import '../lib/http.dart' as http;
11 import '../lib/src/utils.dart'; 11 import '../lib/src/utils.dart';
12 import 'utils.dart'; 12 import 'utils.dart';
13 13
14 void main() { 14 void main() {
15 test('.send', () { 15 test('.send', () {
16 expect(startServer().then((_) { 16 expect(startServer().then((_) {
17 17
18 var request = new http.Request('POST', serverUrl); 18 var request = new http.Request('POST', serverUrl);
19 request.body = "hello"; 19 request.body = "hello";
20 20
21 expect(request.send().then((response) { 21 expect(request.send().then((response) {
22 expect(response.statusCode, equals(200)); 22 expect(response.statusCode, equals(200));
23 return response.stream.bytesToString(); 23 return response.stream.bytesToString();
24 }).whenComplete(stopServer), completion(parse(equals({ 24 }).whenComplete(stopServer), completion(parse(equals({
25 'method': 'POST', 25 'method': 'POST',
26 'path': '/', 26 'path': '/',
27 'headers': { 27 'headers': {
28 'content-type': ['text/plain; charset=UTF-8'], 28 'content-type': ['text/plain; charset=utf-8'],
29 'content-length': ['5'] 29 'content-length': ['5']
30 }, 30 },
31 'body': 'hello' 31 'body': 'hello'
32 })))); 32 }))));
33 }), completes); 33 }), completes);
34 }); 34 });
35 35
36 group('#contentLength', () { 36 group('#contentLength', () {
37 test('is computed from bodyBytes', () { 37 test('is computed from bodyBytes', () {
38 var request = new http.Request('POST', dummyUrl); 38 var request = new http.Request('POST', dummyUrl);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 var request = new http.Request('POST', dummyUrl); 239 var request = new http.Request('POST', dummyUrl);
240 request.encoding = Encoding.ISO_8859_1; 240 request.encoding = Encoding.ISO_8859_1;
241 expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull); 241 expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull);
242 }); 242 });
243 243
244 test('is set to application/x-www-form-urlencoded with charset utf-8 if ' 244 test('is set to application/x-www-form-urlencoded with charset utf-8 if '
245 'bodyFields is set', () { 245 'bodyFields is set', () {
246 var request = new http.Request('POST', dummyUrl); 246 var request = new http.Request('POST', dummyUrl);
247 request.bodyFields = {'hello': 'world'}; 247 request.bodyFields = {'hello': 'world'};
248 expect(request.headers[HttpHeaders.CONTENT_TYPE], 248 expect(request.headers[HttpHeaders.CONTENT_TYPE],
249 equals('application/x-www-form-urlencoded; charset=UTF-8')); 249 equals('application/x-www-form-urlencoded; charset=utf-8'));
250 }); 250 });
251 251
252 test('is set to application/x-www-form-urlencoded with the given charset ' 252 test('is set to application/x-www-form-urlencoded with the given charset '
253 'if bodyFields and encoding are set', () { 253 'if bodyFields and encoding are set', () {
254 var request = new http.Request('POST', dummyUrl); 254 var request = new http.Request('POST', dummyUrl);
255 request.encoding = Encoding.ISO_8859_1; 255 request.encoding = Encoding.ISO_8859_1;
256 request.bodyFields = {'hello': 'world'}; 256 request.bodyFields = {'hello': 'world'};
257 expect(request.headers[HttpHeaders.CONTENT_TYPE], 257 expect(request.headers[HttpHeaders.CONTENT_TYPE],
258 equals('application/x-www-form-urlencoded; charset=ISO-8859-1')); 258 equals('application/x-www-form-urlencoded; charset=iso-8859-1'));
259 }); 259 });
260 260
261 test('is set to text/plain and the given encoding if body and encoding are ' 261 test('is set to text/plain and the given encoding if body and encoding are '
262 'both set', () { 262 'both set', () {
263 var request = new http.Request('POST', dummyUrl); 263 var request = new http.Request('POST', dummyUrl);
264 request.encoding = Encoding.ISO_8859_1; 264 request.encoding = Encoding.ISO_8859_1;
265 request.body = 'hello, world'; 265 request.body = 'hello, world';
266 expect(request.headers[HttpHeaders.CONTENT_TYPE], 266 expect(request.headers[HttpHeaders.CONTENT_TYPE],
267 equals('text/plain; charset=ISO-8859-1')); 267 equals('text/plain; charset=iso-8859-1'));
268 }); 268 });
269 269
270 test('is modified to include utf-8 if body is set', () { 270 test('is modified to include utf-8 if body is set', () {
271 var request = new http.Request('POST', dummyUrl); 271 var request = new http.Request('POST', dummyUrl);
272 request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json'; 272 request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json';
273 request.body = '{"hello": "world"}'; 273 request.body = '{"hello": "world"}';
274 expect(request.headers[HttpHeaders.CONTENT_TYPE], 274 expect(request.headers[HttpHeaders.CONTENT_TYPE],
275 equals('application/json; charset=UTF-8')); 275 equals('application/json; charset=utf-8'));
276 }); 276 });
277 277
278 test('is modified to include the given encoding if encoding is set', () { 278 test('is modified to include the given encoding if encoding is set', () {
279 var request = new http.Request('POST', dummyUrl); 279 var request = new http.Request('POST', dummyUrl);
280 request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json'; 280 request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json';
281 request.encoding = Encoding.ISO_8859_1; 281 request.encoding = Encoding.ISO_8859_1;
282 expect(request.headers[HttpHeaders.CONTENT_TYPE], 282 expect(request.headers[HttpHeaders.CONTENT_TYPE],
283 equals('application/json; charset=ISO-8859-1')); 283 equals('application/json; charset=iso-8859-1'));
284 }); 284 });
285 285
286 test('has its charset overridden by an explicit encoding', () { 286 test('has its charset overridden by an explicit encoding', () {
287 var request = new http.Request('POST', dummyUrl); 287 var request = new http.Request('POST', dummyUrl);
288 request.headers[HttpHeaders.CONTENT_TYPE] = 288 request.headers[HttpHeaders.CONTENT_TYPE] =
289 'application/json; charset=utf-8'; 289 'application/json; charset=utf-8';
290 request.encoding = Encoding.ISO_8859_1; 290 request.encoding = Encoding.ISO_8859_1;
291 expect(request.headers[HttpHeaders.CONTENT_TYPE], 291 expect(request.headers[HttpHeaders.CONTENT_TYPE],
292 equals('application/json; charset=ISO-8859-1')); 292 equals('application/json; charset=iso-8859-1'));
293 }); 293 });
294 294
295 test("doen't have its charset overridden by setting bodyFields", () { 295 test("doen't have its charset overridden by setting bodyFields", () {
296 var request = new http.Request('POST', dummyUrl); 296 var request = new http.Request('POST', dummyUrl);
297 request.headers[HttpHeaders.CONTENT_TYPE] = 297 request.headers[HttpHeaders.CONTENT_TYPE] =
298 'application/x-www-form-urlencoded; charset=iso-8859-1'; 298 'application/x-www-form-urlencoded; charset=iso-8859-1';
299 request.bodyFields = {'hello': 'world'}; 299 request.bodyFields = {'hello': 'world'};
300 expect(request.headers[HttpHeaders.CONTENT_TYPE], 300 expect(request.headers[HttpHeaders.CONTENT_TYPE],
301 equals('application/x-www-form-urlencoded; charset=iso-8859-1')); 301 equals('application/x-www-form-urlencoded; charset=iso-8859-1'));
302 }); 302 });
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 }); 386 });
387 387
388 group('#toString()', () { 388 group('#toString()', () {
389 test('includes the method and URL', () { 389 test('includes the method and URL', () {
390 var request = new http.Request('POST', dummyUrl); 390 var request = new http.Request('POST', dummyUrl);
391 expect(request.toString(), 'POST $dummyUrl'); 391 expect(request.toString(), 'POST $dummyUrl');
392 }); 392 });
393 }); 393 });
394 } 394 }
395 395
OLDNEW
« no previous file with comments | « pkg/http/test/multipart_test.dart ('k') | sdk/lib/io/http.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698