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

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

Issue 11825010: Update pkg/http to use the new async APIs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 11 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/http_test.dart ('k') | pkg/http/test/multipart_test.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) 2012, 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 mock_client_test; 5 library mock_client_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 16 matching lines...) Expand all
27 'field1': 'value1', 27 'field1': 'value1',
28 'field2': 'value2' 28 'field2': 'value2'
29 }).then((response) => response.body), completion(parse(equals({ 29 }).then((response) => response.body), completion(parse(equals({
30 'field1': 'value1', 30 'field1': 'value1',
31 'field2': 'value2' 31 'field2': 'value2'
32 })))); 32 }))));
33 }); 33 });
34 34
35 test('handles a streamed request', () { 35 test('handles a streamed request', () {
36 var client = new MockClient.streaming((request, bodyStream) { 36 var client = new MockClient.streaming((request, bodyStream) {
37 return consumeInputStream(bodyStream).then((body) { 37 return bodyStream.bytesToString().then((bodyString) {
38 var stream = new ListInputStream(); 38 var stream = new StreamController<List<int>>.singleSubscription();
39 async.then((_) { 39 async.then((_) {
40 var bodyString = new String.fromCharCodes(body); 40 stream.add('Request body was "$bodyString"'.charCodes);
41 stream.write('Request body was "$bodyString"'.charCodes); 41 stream.close();
42 stream.markEndOfStream();
43 }); 42 });
44 43
45 return new http.StreamedResponse(stream, 200, -1); 44 return new http.StreamedResponse(stream, 200, -1);
46 }); 45 });
47 }); 46 });
48 47
49 var uri = new Uri.fromString("http://example.com/foo"); 48 var uri = new Uri.fromString("http://example.com/foo");
50 var request = new http.Request("POST", uri); 49 var request = new http.Request("POST", uri);
51 request.body = "hello, world"; 50 request.body = "hello, world";
52 var future = client.send(request) 51 var future = client.send(request)
53 .then(http.Response.fromStream) 52 .then(http.Response.fromStream)
54 .then((response) => response.body); 53 .then((response) => response.body);
55 expect(future, completion(equals('Request body was "hello, world"'))); 54 expect(future, completion(equals('Request body was "hello, world"')));
56 }); 55 });
57 56
58 test('handles a request with no body', () { 57 test('handles a request with no body', () {
59 var client = new MockClient((request) { 58 var client = new MockClient((request) {
60 return new Future.immediate(new http.Response('you did it', 200)); 59 return new Future.immediate(new http.Response('you did it', 200));
61 }); 60 });
62 61
63 expect(client.read("http://example.com/foo"), 62 expect(client.read("http://example.com/foo"),
64 completion(equals('you did it'))); 63 completion(equals('you did it')));
65 }); 64 });
66 } 65 }
OLDNEW
« no previous file with comments | « pkg/http/test/http_test.dart ('k') | pkg/http/test/multipart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698