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

Side by Side Diff: tests/standalone/io/https_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, 9 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 import "dart:io";
6 import "dart:uri";
7 import "dart:isolate";
8
9
10 void testGoogleUrl() {
11 int testsStarted = 0;
12 int testsFinished = 0;
13 bool allStarted = false;
14 HttpClient client = new HttpClient();
15
16 void testUrl(String url) {
17 testsStarted++;
18 var requestUri = Uri.parse(url);
19 client.getUrl(requestUri)
20 .then((HttpClientRequest request) => request.close())
21 .then((HttpClientResponse response) {
22 Expect.isTrue(response.statusCode < 500);
23 if (requestUri.path.length == 0) {
24 Expect.isTrue(response.statusCode != 404);
25 }
26 response.listen((data) { }, onDone: () {
27 if (++testsFinished == testsStarted && allStarted) client.close();
28 });
29 })
30 .catchError((error) => Expect.fail("Unexpected IO error: $error"));
31 }
32
33 testUrl('https://www.google.dk');
34 testUrl('https://www.google.dk');
35 testUrl('https://www.google.dk/#q=foo');
36 testUrl('https://www.google.dk/#hl=da&q=foo');
37 allStarted = true;
38 }
39
40 void testBadHostName() {
41 HttpClient client = new HttpClient();
42 ReceivePort port = new ReceivePort();
43 client.getUrl(Uri.parse("https://some.bad.host.name.7654321/"))
44 .then((HttpClientRequest request) {
45 Expect.fail("Should not open a request on bad hostname");
46 })
47 .catchError((error) {
48 port.close(); // Should throw an error on bad hostname.
49 });
50 }
51
52 void InitializeSSL() {
53 SecureSocket.initialize();
54 }
55
56 void main() {
57 testGoogleUrl();
58 testBadHostName();
59 Expect.throws(InitializeSSL);
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698