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

Side by Side Diff: tests/standalone/io/http_client_connect_test.dart

Issue 14640008: Change the signature for all network bind calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments by whesse@ Created 7 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
OLDNEW
1 // Copyright (c) 2013, 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
11 import 'dart:async'; 11 import 'dart:async';
12 import 'dart:io'; 12 import 'dart:io';
13 import 'dart:isolate'; 13 import 'dart:isolate';
14 14
15 void testGetEmptyRequest() { 15 void testGetEmptyRequest() {
16 HttpServer.bind().then((server) { 16 HttpServer.bind("127.0.0.1", 0).then((server) {
17 server.listen((request) { 17 server.listen((request) {
18 request.pipe(request.response); 18 request.pipe(request.response);
19 }); 19 });
20 20
21 var client = new HttpClient(); 21 var client = new HttpClient();
22 client.get("127.0.0.1", server.port, "/") 22 client.get("127.0.0.1", server.port, "/")
23 .then((request) => request.close()) 23 .then((request) => request.close())
24 .then((response) { 24 .then((response) {
25 response.listen( 25 response.listen(
26 (data) {}, 26 (data) {},
27 onDone: server.close); 27 onDone: server.close);
28 }); 28 });
29 }); 29 });
30 } 30 }
31 31
32 void testGetDataRequest() { 32 void testGetDataRequest() {
33 HttpServer.bind().then((server) { 33 HttpServer.bind("127.0.0.1", 0).then((server) {
34 var data = "lalala".codeUnits; 34 var data = "lalala".codeUnits;
35 server.listen((request) { 35 server.listen((request) {
36 request.response.add(data); 36 request.response.add(data);
37 request.pipe(request.response); 37 request.pipe(request.response);
38 }); 38 });
39 39
40 var client = new HttpClient(); 40 var client = new HttpClient();
41 client.get("127.0.0.1", server.port, "/") 41 client.get("127.0.0.1", server.port, "/")
42 .then((request) => request.close()) 42 .then((request) => request.close())
43 .then((response) { 43 .then((response) {
(...skipping 12 matching lines...) Expand all
56 var port = new ReceivePort(); 56 var port = new ReceivePort();
57 var client = new HttpClient(); 57 var client = new HttpClient();
58 client.get("__SOMETHING_INVALID__", 8888, "/") 58 client.get("__SOMETHING_INVALID__", 8888, "/")
59 .catchError((error) { 59 .catchError((error) {
60 port.close(); 60 port.close();
61 client.close(); 61 client.close();
62 }); 62 });
63 } 63 }
64 64
65 void testGetServerClose() { 65 void testGetServerClose() {
66 HttpServer.bind().then((server) { 66 HttpServer.bind("127.0.0.1", 0).then((server) {
67 server.listen((request) { 67 server.listen((request) {
68 server.close(); 68 server.close();
69 }); 69 });
70 70
71 var port = new ReceivePort(); 71 var port = new ReceivePort();
72 var client = new HttpClient(); 72 var client = new HttpClient();
73 client.get("127.0.0.1", server.port, "/") 73 client.get("127.0.0.1", server.port, "/")
74 .then((request) => request.close()) 74 .then((request) => request.close())
75 .then((response) { 75 .then((response) {
76 Expect.fail("Request not expected"); 76 Expect.fail("Request not expected");
77 }) 77 })
78 .catchError((error) => port.close(), 78 .catchError((error) => port.close(),
79 test: (error) => error is HttpParserException); 79 test: (error) => error is HttpParserException);
80 }); 80 });
81 } 81 }
82 82
83 void testGetDataServerClose() { 83 void testGetDataServerClose() {
84 var completer = new Completer(); 84 var completer = new Completer();
85 HttpServer.bind().then((server) { 85 HttpServer.bind("127.0.0.1", 0).then((server) {
86 server.listen((request) { 86 server.listen((request) {
87 request.response.contentLength = 100; 87 request.response.contentLength = 100;
88 request.response.write("data"); 88 request.response.write("data");
89 request.response.write("more data"); 89 request.response.write("more data");
90 completer.future.then((_) => server.close()); 90 completer.future.then((_) => server.close());
91 }); 91 });
92 92
93 var port = new ReceivePort(); 93 var port = new ReceivePort();
94 var client = new HttpClient(); 94 var client = new HttpClient();
95 client.get("127.0.0.1", server.port, "/") 95 client.get("127.0.0.1", server.port, "/")
96 .then((request) => request.close()) 96 .then((request) => request.close())
97 .then((response) { 97 .then((response) {
98 // Close the (incomplete) response, now we have seen the response object . 98 // Close the (incomplete) response, now we have seen the response object .
99 completer.complete(null); 99 completer.complete(null);
100 int errors = 0; 100 int errors = 0;
101 response.listen( 101 response.listen(
102 (data) {}, 102 (data) {},
103 onError: (error) => errors++, 103 onError: (error) => errors++,
104 onDone: () { 104 onDone: () {
105 port.close(); 105 port.close();
106 Expect.equals(1, errors); 106 Expect.equals(1, errors);
107 }); 107 });
108 }); 108 });
109 }); 109 });
110 } 110 }
111 111
112 void testPostEmptyRequest() { 112 void testPostEmptyRequest() {
113 HttpServer.bind().then((server) { 113 HttpServer.bind("127.0.0.1", 0).then((server) {
114 server.listen((request) { 114 server.listen((request) {
115 request.pipe(request.response); 115 request.pipe(request.response);
116 }); 116 });
117 117
118 var client = new HttpClient(); 118 var client = new HttpClient();
119 client.post("127.0.0.1", server.port, "/") 119 client.post("127.0.0.1", server.port, "/")
120 .then((request) => request.close()) 120 .then((request) => request.close())
121 .then((response) { 121 .then((response) {
122 response.listen((data) {}, onDone: server.close); 122 response.listen((data) {}, onDone: server.close);
123 }); 123 });
124 }); 124 });
125 } 125 }
126 126
127 127
128 void main() { 128 void main() {
129 testGetEmptyRequest(); 129 testGetEmptyRequest();
130 testGetDataRequest(); 130 testGetDataRequest();
131 testGetInvalidHost(); 131 testGetInvalidHost();
132 testGetServerClose(); 132 testGetServerClose();
133 testGetDataServerClose(); 133 testGetDataServerClose();
134 testPostEmptyRequest(); 134 testPostEmptyRequest();
135 } 135 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_body_test.dart ('k') | tests/standalone/io/http_client_request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698