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

Unified Diff: tests/standalone/io/https_client_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/https_client_certificate_test.dart ('k') | tests/standalone/io/https_server_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/https_client_test.dart
diff --git a/tests/standalone/io/https_client_test.dart b/tests/standalone/io/https_client_test.dart
index 847249fc135b8b96a947df4f69d93047a689f36f..37b3d4f01779014606e65efb13d1f8a9f8238a51 100644
--- a/tests/standalone/io/https_client_test.dart
+++ b/tests/standalone/io/https_client_test.dart
@@ -7,50 +7,46 @@ import "dart:uri";
import "dart:isolate";
-int testGoogleUrlCount = 0;
void testGoogleUrl() {
+ int testsStarted = 0;
+ int testsFinished = 0;
+ bool allStarted = false;
HttpClient client = new HttpClient();
void testUrl(String url) {
+ testsStarted++;
var requestUri = Uri.parse(url);
- var conn = client.getUrl(requestUri);
-
- conn.onRequest = (HttpClientRequest request) {
- request.outputStream.close();
- };
- conn.onResponse = (HttpClientResponse response) {
- testGoogleUrlCount++;
- Expect.isTrue(response.statusCode < 500);
- if (requestUri.path.length == 0) {
- Expect.isTrue(response.statusCode != 404);
- }
- response.inputStream.onData = () {
- response.inputStream.read();
- };
- response.inputStream.onClosed = () {
- if (testGoogleUrlCount == 4) client.shutdown();
- };
- };
- conn.onError = (error) => Expect.fail("Unexpected IO error $error");
+ client.getUrl(requestUri)
+ .then((HttpClientRequest request) => request.close())
+ .then((HttpClientResponse response) {
+ Expect.isTrue(response.statusCode < 500);
+ if (requestUri.path.length == 0) {
+ Expect.isTrue(response.statusCode != 404);
+ }
+ response.listen((data) { }, onDone: () {
+ if (++testsFinished == testsStarted && allStarted) client.close();
+ });
+ })
+ .catchError((error) => Expect.fail("Unexpected IO error: $error"));
}
testUrl('https://www.google.dk');
testUrl('https://www.google.dk');
testUrl('https://www.google.dk/#q=foo');
testUrl('https://www.google.dk/#hl=da&q=foo');
+ allStarted = true;
}
void testBadHostName() {
HttpClient client = new HttpClient();
- HttpClientConnection connection = client.getUrl(
- Uri.parse("https://some.bad.host.name.7654321/"));
- connection.onRequest = (HttpClientRequest request) {
- Expect.fail("Should not open a request on bad hostname");
- };
ReceivePort port = new ReceivePort();
- connection.onError = (Exception error) {
- port.close(); // We expect onError to be called, due to bad host name.
- };
+ client.getUrl(Uri.parse("https://some.bad.host.name.7654321/"))
+ .then((HttpClientRequest request) {
+ Expect.fail("Should not open a request on bad hostname");
+ })
+ .catchError((error) {
+ port.close(); // Should throw an error on bad hostname.
+ });
}
void InitializeSSL() {
« no previous file with comments | « tests/standalone/io/https_client_certificate_test.dart ('k') | tests/standalone/io/https_server_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698