| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.runner.browser.server; | 5 library test.runner.browser.server; |
| 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_multi_server/http_multi_server.dart'; |
| 11 import 'package:path/path.dart' as p; | 12 import 'package:path/path.dart' as p; |
| 12 import 'package:pool/pool.dart'; | 13 import 'package:pool/pool.dart'; |
| 13 import 'package:shelf/shelf.dart' as shelf; | 14 import 'package:shelf/shelf.dart' as shelf; |
| 14 import 'package:shelf/shelf_io.dart' as shelf_io; | 15 import 'package:shelf/shelf_io.dart' as shelf_io; |
| 15 import 'package:shelf_static/shelf_static.dart'; | 16 import 'package:shelf_static/shelf_static.dart'; |
| 16 import 'package:shelf_web_socket/shelf_web_socket.dart'; | 17 import 'package:shelf_web_socket/shelf_web_socket.dart'; |
| 17 | 18 |
| 18 import '../../backend/metadata.dart'; | 19 import '../../backend/metadata.dart'; |
| 19 import '../../backend/suite.dart'; | 20 import '../../backend/suite.dart'; |
| 20 import '../../backend/test_platform.dart'; | 21 import '../../backend/test_platform.dart'; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 BrowserServer._(String root, String packageRoot, Uri pubServeUrl, bool color) | 139 BrowserServer._(String root, String packageRoot, Uri pubServeUrl, bool color) |
| 139 : _root = root == null ? p.current : root, | 140 : _root = root == null ? p.current : root, |
| 140 _packageRoot = packageRootFor(root, packageRoot), | 141 _packageRoot = packageRootFor(root, packageRoot), |
| 141 _pubServeUrl = pubServeUrl, | 142 _pubServeUrl = pubServeUrl, |
| 142 _compiledDir = pubServeUrl == null ? createTempDir() : null, | 143 _compiledDir = pubServeUrl == null ? createTempDir() : null, |
| 143 _http = pubServeUrl == null ? null : new HttpClient(), | 144 _http = pubServeUrl == null ? null : new HttpClient(), |
| 144 _compilers = new CompilerPool(color: color); | 145 _compilers = new CompilerPool(color: color); |
| 145 | 146 |
| 146 /// Starts the underlying server. | 147 /// Starts the underlying server. |
| 147 Future _load() { | 148 Future _load() async { |
| 148 var cascade = new shelf.Cascade() | 149 var cascade = new shelf.Cascade() |
| 149 .add(_webSocketHandler.handler); | 150 .add(_webSocketHandler.handler); |
| 150 | 151 |
| 151 if (_pubServeUrl == null) { | 152 if (_pubServeUrl == null) { |
| 152 cascade = cascade | 153 cascade = cascade |
| 153 .add(_createPackagesHandler()) | 154 .add(_createPackagesHandler()) |
| 154 .add(_jsHandler.handler) | 155 .add(_jsHandler.handler) |
| 155 .add(createStaticHandler(_root)) | 156 .add(createStaticHandler(_root)) |
| 156 .add(_wrapperHandler); | 157 .add(_wrapperHandler); |
| 157 } | 158 } |
| 158 | 159 |
| 159 var pipeline = new shelf.Pipeline() | 160 var pipeline = new shelf.Pipeline() |
| 160 .addMiddleware(nestingMiddleware(_secret)) | 161 .addMiddleware(nestingMiddleware(_secret)) |
| 161 .addHandler(cascade.handler); | 162 .addHandler(cascade.handler); |
| 162 | 163 |
| 163 return shelf_io.serve(pipeline, 'localhost', 0).then((server) { | 164 _server = await HttpMultiServer.loopback(0); |
| 164 _server = server; | 165 shelf_io.serveRequests(_server, pipeline); |
| 165 }); | |
| 166 } | 166 } |
| 167 | 167 |
| 168 /// Returns a handler that serves the contents of the "packages/" directory | 168 /// Returns a handler that serves the contents of the "packages/" directory |
| 169 /// for any URL that contains "packages/". | 169 /// for any URL that contains "packages/". |
| 170 /// | 170 /// |
| 171 /// This is a factory so it can wrap a static handler. | 171 /// This is a factory so it can wrap a static handler. |
| 172 shelf.Handler _createPackagesHandler() { | 172 shelf.Handler _createPackagesHandler() { |
| 173 var staticHandler = | 173 var staticHandler = |
| 174 createStaticHandler(_packageRoot, serveFilesOutsidePath: true); | 174 createStaticHandler(_packageRoot, serveFilesOutsidePath: true); |
| 175 | 175 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 if (_pubServeUrl == null) { | 417 if (_pubServeUrl == null) { |
| 418 new Directory(_compiledDir).deleteSync(recursive: true); | 418 new Directory(_compiledDir).deleteSync(recursive: true); |
| 419 } else { | 419 } else { |
| 420 _http.close(); | 420 _http.close(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 _closeCompleter.complete(); | 423 _closeCompleter.complete(); |
| 424 }).catchError(_closeCompleter.completeError); | 424 }).catchError(_closeCompleter.completeError); |
| 425 } | 425 } |
| 426 } | 426 } |
| OLD | NEW |