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

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

Issue 12330133: Don't use external servers in the tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed long lines 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012, 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 // VMOptions=
6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write
9
10 import "dart:io";
11 import "dart:uri";
12 import "dart:isolate";
13
14 void testGoogle() {
15 HttpClient client = new HttpClient();
16 client.get('www.google.com', 80, '/')
17 .then((request) => request.close())
18 .then((response) {
19 Expect.isTrue(response.statusCode < 500);
20 response.listen((data) {}, onDone: client.close);
21 })
22 .catchError((error) => Expect.fail("Unexpected IO error: $error"));
23 }
24
25 int testGoogleUrlCount = 0;
26 void testGoogleUrl() {
27 HttpClient client = new HttpClient();
28
29 void testUrl(String url) {
30 var requestUri = Uri.parse(url);
31 client.getUrl(requestUri)
32 .then((request) => request.close())
33 .then((response) {
34 testGoogleUrlCount++;
35 Expect.isTrue(response.statusCode < 500);
36 if (requestUri.path.length == 0) {
37 Expect.isTrue(response.statusCode != 404);
38 }
39 response.listen((data) {}, onDone: () {
40 if (testGoogleUrlCount == 5) client.close();
41 });
42 })
43 .catchError((error) => Expect.fail("Unexpected IO error: $error"));
44 }
45
46 testUrl('http://www.google.com');
47 testUrl('http://www.google.com/abc');
48 testUrl('http://www.google.com/?abc');
49 testUrl('http://www.google.com/abc?abc');
50 testUrl('http://www.google.com/abc?abc#abc');
51 }
52
53 void testInvalidUrl() {
54 HttpClient client = new HttpClient();
55 Expect.throws(
56 () => client.getUrl(Uri.parse('ftp://www.google.com')));
57 }
58
59 void testBadHostName() {
60 HttpClient client = new HttpClient();
61 ReceivePort port = new ReceivePort();
62 client.get("some.bad.host.name.7654321", 0, "/")
63 .then((request) {
64 Expect.fail("Should not open a request on bad hostname");
65 }).catchError((error) {
66 port.close(); // We expect onError to be called, due to bad host name.
67 }, test: (error) => error is! String);
68 }
69
70 void main() {
71 testGoogle();
72 testGoogleUrl();
73 testInvalidUrl();
74 testBadHostName();
75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698