| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 'package:http/http.dart' as http; | 13 import 'package:http/http.dart' as http; |
| 14 import 'package:http/src/utils.dart'; | 14 import 'package:http/src/utils.dart'; |
| 15 | 15 |
| 16 /// The current server instance. | 16 /// The current server instance. |
| 17 HttpServer _server; | 17 HttpServer _server; |
| 18 | 18 |
| 19 /// The URL for the current server instance. | 19 /// The URL for the current server instance. |
| 20 Uri get serverUrl => new Uri.fromString('http://localhost:${_server.port}'); | 20 Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); |
| 21 | 21 |
| 22 /// A dummy URL for constructing requests that won't be sent. | 22 /// A dummy URL for constructing requests that won't be sent. |
| 23 Uri get dummyUrl => new Uri.fromString('http://dartlang.org/'); | 23 Uri get dummyUrl => Uri.parse('http://dartlang.org/'); |
| 24 | 24 |
| 25 /// Starts a new HTTP server. | 25 /// Starts a new HTTP server. |
| 26 void startServer() { | 26 void startServer() { |
| 27 _server = new HttpServer(); | 27 _server = new HttpServer(); |
| 28 | 28 |
| 29 _server.addRequestHandler((request) => request.path == '/error', | 29 _server.addRequestHandler((request) => request.path == '/error', |
| 30 (request, response) { | 30 (request, response) { |
| 31 response.statusCode = 400; | 31 response.statusCode = 400; |
| 32 response.contentLength = 0; | 32 response.contentLength = 0; |
| 33 response.outputStream.close(); | 33 response.outputStream.close(); |
| 34 }); | 34 }); |
| 35 | 35 |
| 36 _server.addRequestHandler((request) => request.path == '/loop', | 36 _server.addRequestHandler((request) => request.path == '/loop', |
| 37 (request, response) { | 37 (request, response) { |
| 38 var n = int.parse(new Uri.fromString(request.uri).query); | 38 var n = int.parse(Uri.parse(request.uri).query); |
| 39 response.statusCode = 302; | 39 response.statusCode = 302; |
| 40 response.headers.set('location', | 40 response.headers.set('location', |
| 41 serverUrl.resolve('/loop?${n + 1}').toString()); | 41 serverUrl.resolve('/loop?${n + 1}').toString()); |
| 42 response.contentLength = 0; | 42 response.contentLength = 0; |
| 43 response.outputStream.close(); | 43 response.outputStream.close(); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 _server.addRequestHandler((request) => request.path == '/redirect', | 46 _server.addRequestHandler((request) => request.path == '/redirect', |
| 47 (request, response) { | 47 (request, response) { |
| 48 response.statusCode = 302; | 48 response.statusCode = 302; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 const isSocketIOException = const _SocketIOException(); | 183 const isSocketIOException = const _SocketIOException(); |
| 184 | 184 |
| 185 /// A matcher for functions that throw SocketIOException. | 185 /// A matcher for functions that throw SocketIOException. |
| 186 const Matcher throwsSocketIOException = | 186 const Matcher throwsSocketIOException = |
| 187 const Throws(isSocketIOException); | 187 const Throws(isSocketIOException); |
| 188 | 188 |
| 189 class _SocketIOException extends TypeMatcher { | 189 class _SocketIOException extends TypeMatcher { |
| 190 const _SocketIOException() : super("SocketIOException"); | 190 const _SocketIOException() : super("SocketIOException"); |
| 191 bool matches(item, MatchState matchState) => item is SocketIOException; | 191 bool matches(item, MatchState matchState) => item is SocketIOException; |
| 192 } | 192 } |
| OLD | NEW |