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

Unified Diff: tests/standalone/io/http_head_test.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/io/http_date_test.dart ('k') | tests/standalone/io/http_headers_state_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_head_test.dart
diff --git a/tests/standalone/io/http_head_test.dart b/tests/standalone/io/http_head_test.dart
index 7880e2d3278ca7fb5a7a0f6113809df2669b9b30..215872ce5418620628c3a647577196c1f0b6eaf3 100644
--- a/tests/standalone/io/http_head_test.dart
+++ b/tests/standalone/io/http_head_test.dart
@@ -1,52 +1,47 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "dart:io";
void testHEAD(int totalConnections) {
- HttpServer server = new HttpServer();
- server.onError = (e) => Expect.fail("Unexpected error $e");
- server.listen("127.0.0.1", 0, backlog: totalConnections);
- server.addRequestHandler(
- (request) => request.path == "/test100",
- (HttpRequest request, HttpResponse response) {
- response.contentLength = 100;
- response.outputStream.close();
- });
- server.addRequestHandler(
- (request) => request.path == "/test200",
- (HttpRequest request, HttpResponse response) {
- response.contentLength = 200;
- List<int> data = new List<int>.fixedLength(200);
- response.outputStream.write(data);
- response.outputStream.close();
+ HttpServer.bind().then((server) {
+ server.listen((request) {
+ var response = request.response;
+ if (request.uri.path == "/test100") {
+ response.contentLength = 100;
+ response.close();
+ } else if (request.uri.path == "/test200") {
+ response.contentLength = 200;
+ List<int> data = new List<int>.fixedLength(200, fill: 0);
+ response.add(data);
+ response.close();
+ } else {
+ assert(false);
+ }
});
- HttpClient client = new HttpClient();
+ HttpClient client = new HttpClient();
- int count = 0;
- for (int i = 0; i < totalConnections; i++) {
- HttpClientConnection conn;
- int len = (i % 2 == 0) ? 100 : 200;
- if (i % 2 == 0) {
- conn = client.open("HEAD", "127.0.0.1", server.port, "/test$len");
- } else {
- conn = client.open("HEAD", "127.0.0.1", server.port, "/test$len");
+ int count = 0;
+ for (int i = 0; i < totalConnections; i++) {
+ int len = (i % 2 == 0) ? 100 : 200;
+ client.open("HEAD", "127.0.0.1", server.port, "/test$len")
+ .then((request) => request.close())
+ .then((HttpClientResponse response) {
+ Expect.equals(len, response.contentLength);
+ response.listen(
+ (_) => Expect.fail("Data from HEAD request"),
+ onDone: () {
+ count++;
+ if (count == totalConnections) {
+ client.close();
+ server.close();
+ }
+ });
+ });
}
- conn.onError = (e) => Expect.fail("Unexpected error $e");
- conn.onResponse = (HttpClientResponse response) {
- Expect.equals(len, response.contentLength);
- response.inputStream.onData = () => Expect.fail("Data from HEAD request");
- response.inputStream.onClosed = () {
- count++;
- if (count == totalConnections) {
- client.shutdown();
- server.close();
- }
- };
- };
- }
+ });
}
void main() {
« no previous file with comments | « tests/standalone/io/http_date_test.dart ('k') | tests/standalone/io/http_headers_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698