Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 'dart:async'; | 10 import 'dart:async'; |
| 11 import 'dart:convert'; | |
| 11 import 'dart:io'; | 12 import 'dart:io'; |
| 12 | 13 |
| 13 import "package:async_helper/async_helper.dart"; | 14 import "package:async_helper/async_helper.dart"; |
| 14 import "package:expect/expect.dart"; | 15 import "package:expect/expect.dart"; |
| 15 | 16 |
| 16 void testGetEmptyRequest() { | 17 void testGetEmptyRequest() { |
| 17 HttpServer.bind("127.0.0.1", 0).then((server) { | 18 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 18 server.listen((request) { | 19 server.listen((request) { |
| 19 request.pipe(request.response); | 20 request.pipe(request.response); |
| 20 }); | 21 }); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 .catchError((error) => asyncEnd(), | 115 .catchError((error) => asyncEnd(), |
| 115 test: (error) => error is HttpException); | 116 test: (error) => error is HttpException); |
| 116 }); | 117 }); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void testGetDataServerForceClose() { | 120 void testGetDataServerForceClose() { |
| 120 asyncStart(); | 121 asyncStart(); |
| 121 var completer = new Completer(); | 122 var completer = new Completer(); |
| 122 HttpServer.bind("127.0.0.1", 0).then((server) { | 123 HttpServer.bind("127.0.0.1", 0).then((server) { |
| 123 server.listen((request) { | 124 server.listen((request) { |
| 125 request.response.bufferOutput = false; | |
| 124 request.response.contentLength = 100; | 126 request.response.contentLength = 100; |
| 125 request.response.write("data"); | 127 request.response.write("data"); |
| 126 request.response.write("more data"); | 128 request.response.write("more data"); |
| 127 completer.future.then((_) => server.close(force: true)); | 129 completer.future.then((_) => server.close(force: true)); |
| 128 }); | 130 }); |
| 129 | 131 |
| 130 var client = new HttpClient(); | 132 var client = new HttpClient(); |
| 131 client.get("127.0.0.1", server.port, "/") | 133 client.get("127.0.0.1", server.port, "/") |
| 132 .then((request) => request.close()) | 134 .then((request) => request.close()) |
| 133 .then((response) { | 135 .then((response) { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 155 var client = new HttpClient(); | 157 var client = new HttpClient(); |
| 156 client.post("127.0.0.1", server.port, "/") | 158 client.post("127.0.0.1", server.port, "/") |
| 157 .then((request) => request.close()) | 159 .then((request) => request.close()) |
| 158 .then((response) { | 160 .then((response) { |
| 159 response.listen((data) {}, onDone: server.close); | 161 response.listen((data) {}, onDone: server.close); |
| 160 }); | 162 }); |
| 161 }); | 163 }); |
| 162 } | 164 } |
| 163 | 165 |
| 164 | 166 |
| 167 void testNoBuffer() { | |
| 168 asyncStart(); | |
| 169 HttpServer.bind("127.0.0.1", 0).then((server) { | |
| 170 var response; | |
| 171 server.listen((request) { | |
| 172 response = request.response; | |
| 173 response.bufferOutput = false; | |
| 174 response.writeln('init'); | |
| 175 }); | |
| 176 | |
| 177 var client = new HttpClient(); | |
| 178 client.get("127.0.0.1", server.port, "/") | |
| 179 .then((request) => request.close()) | |
| 180 .then((clientResponse) { | |
| 181 var iterator = new StreamIterator( | |
| 182 clientResponse.transform(UTF8.decoder) | |
| 183 .transform(new LineSplitter())); | |
| 184 iterator.moveNext().then((hasValue) { | |
| 185 Expect.isTrue(hasValue); | |
| 186 Expect.equals('init', iterator.current); | |
| 187 int count = 0; | |
| 188 void run() { | |
| 189 if (count == 10) { | |
| 190 response.close(); | |
| 191 iterator.moveNext().then((hasValue) { | |
| 192 Expect.isFalse(hasValue); | |
| 193 server.close(); | |
| 194 asyncEnd(); | |
| 195 }); | |
| 196 } else { | |
| 197 response.writeln('output$count'); | |
|
Søren Gjesse
2014/04/08 13:03:24
He he the client writes to the response.
Anders Johnsen
2014/04/08 13:07:00
The server response, yeah.
| |
| 198 iterator.moveNext().then((hasValue) { | |
| 199 Expect.isTrue(hasValue); | |
| 200 Expect.equals('output$count', iterator.current); | |
| 201 count++; | |
| 202 run(); | |
| 203 }); | |
| 204 } | |
| 205 } | |
| 206 run(); | |
| 207 }); | |
| 208 }); | |
| 209 }); | |
| 210 } | |
| 211 | |
| 212 | |
| 165 void main() { | 213 void main() { |
| 166 testGetEmptyRequest(); | 214 testGetEmptyRequest(); |
| 167 testGetDataRequest(); | 215 testGetDataRequest(); |
| 168 testGetInvalidHost(); | 216 testGetInvalidHost(); |
| 169 testGetServerClose(); | 217 testGetServerClose(); |
| 170 testGetServerCloseNoKeepAlive(); | 218 testGetServerCloseNoKeepAlive(); |
| 171 testGetServerForceClose(); | 219 testGetServerForceClose(); |
| 172 // TODO(14953): This test can only run, when buffering is disabled. | 220 testGetDataServerForceClose(); |
| 173 // testGetDataServerForceClose(); | |
| 174 testPostEmptyRequest(); | 221 testPostEmptyRequest(); |
| 222 testNoBuffer(); | |
| 175 } | 223 } |
| OLD | NEW |