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 library test_utils; | 5 library test_utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
11 | 11 |
12 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
13 import '../lib/src/byte_stream.dart'; | 13 import '../lib/src/byte_stream.dart'; |
14 import '../lib/http.dart' as http; | 14 import '../lib/http.dart' as http; |
15 import '../lib/src/utils.dart'; | 15 import '../lib/src/utils.dart'; |
| 16 import 'safe_http_server.dart'; |
16 | 17 |
17 /// The current server instance. | 18 /// The current server instance. |
18 HttpServer _server; | 19 HttpServer _server; |
19 | 20 |
20 /// The URL for the current server instance. | 21 /// The URL for the current server instance. |
21 Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); | 22 Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); |
22 | 23 |
23 /// A dummy URL for constructing requests that won't be sent. | 24 /// A dummy URL for constructing requests that won't be sent. |
24 Uri get dummyUrl => Uri.parse('http://dartlang.org/'); | 25 Uri get dummyUrl => Uri.parse('http://dartlang.org/'); |
25 | 26 |
26 /// Starts a new HTTP server. | 27 /// Starts a new HTTP server. |
27 Future startServer() { | 28 Future startServer() { |
28 return HttpServer.bind("127.0.0.1", 0).then((s) { | 29 return SafeHttpServer.bind("127.0.0.1", 0).then((s) { |
29 _server = s; | 30 _server = s; |
30 s.listen((request) { | 31 s.listen((request) { |
31 var path = request.uri.path; | 32 var path = request.uri.path; |
32 var response = request.response; | 33 var response = request.response; |
33 | 34 |
34 if (path == '/error') { | 35 if (path == '/error') { |
35 response.statusCode = 400; | 36 response.statusCode = 400; |
36 response.contentLength = 0; | 37 response.contentLength = 0; |
37 response.close(); | 38 response.close(); |
38 return; | 39 return; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 const isSocketIOException = const _SocketIOException(); | 198 const isSocketIOException = const _SocketIOException(); |
198 | 199 |
199 /// A matcher for functions that throw SocketIOException. | 200 /// A matcher for functions that throw SocketIOException. |
200 const Matcher throwsSocketIOException = | 201 const Matcher throwsSocketIOException = |
201 const Throws(isSocketIOException); | 202 const Throws(isSocketIOException); |
202 | 203 |
203 class _SocketIOException extends TypeMatcher { | 204 class _SocketIOException extends TypeMatcher { |
204 const _SocketIOException() : super("SocketIOException"); | 205 const _SocketIOException() : super("SocketIOException"); |
205 bool matches(item, MatchState matchState) => item is SocketIOException; | 206 bool matches(item, MatchState matchState) => item is SocketIOException; |
206 } | 207 } |
OLD | NEW |