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