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

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

Issue 261763002: Rip out the last dart:io dependency from pkg/http. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 7 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/lib/src/multipart_file.dart ('k') | pkg/http/test/html/client_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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library client_test;
6
7 import 'dart:io';
8
9 import 'package:http/http.dart' as http;
10 import 'package:unittest/unittest.dart';
11
12 import 'utils.dart';
13
14 void main() {
15 tearDown(stopServer);
16
17 test('#send a StreamedRequest', () {
18 expect(startServer().then((_) {
19 var client = new http.Client();
20 var request = new http.StreamedRequest("POST", serverUrl);
21 request.headers[HttpHeaders.CONTENT_TYPE] =
22 'application/json; charset=utf-8';
23 request.headers[HttpHeaders.USER_AGENT] = 'Dart';
24
25 expect(client.send(request).then((response) {
26 expect(response.request, equals(request));
27 expect(response.statusCode, equals(200));
28 expect(response.headers['single'], equals('value'));
29 // dart:io internally normalizes outgoing headers so that they never
30 // have multiple headers with the same name, so there's no way to test
31 // whether we handle that case correctly.
32
33 return response.stream.bytesToString();
34 }).whenComplete(client.close), completion(parse(equals({
35 'method': 'POST',
36 'path': '/',
37 'headers': {
38 'content-type': ['application/json; charset=utf-8'],
39 'accept-encoding': ['gzip'],
40 'user-agent': ['Dart'],
41 'transfer-encoding': ['chunked']
42 },
43 'body': '{"hello": "world"}'
44 }))));
45
46 request.sink.add('{"hello": "world"}'.codeUnits);
47 request.sink.close();
48 }), completes);
49 });
50
51 test('#send with an invalid URL', () {
52 expect(startServer().then((_) {
53 var client = new http.Client();
54 var url = Uri.parse('http://http.invalid');
55 var request = new http.StreamedRequest("POST", url);
56 request.headers[HttpHeaders.CONTENT_TYPE] =
57 'application/json; charset=utf-8';
58
59 expect(client.send(request), throwsSocketException);
60
61 request.sink.add('{"hello": "world"}'.codeUnits);
62 request.sink.close();
63 }), completes);
64 });
65 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/multipart_file.dart ('k') | pkg/http/test/html/client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698