| 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:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
| 12 import 'package:pool/pool.dart'; | 12 import 'package:pool/pool.dart'; |
| 13 import 'package:shelf/shelf.dart' as shelf; | 13 import 'package:shelf/shelf.dart' as shelf; |
| 14 import 'package:shelf/shelf_io.dart' as shelf_io; | 14 import 'package:shelf/shelf_io.dart' as shelf_io; |
| 15 import 'package:shelf_static/shelf_static.dart'; | 15 import 'package:shelf_static/shelf_static.dart'; |
| 16 import 'package:shelf_web_socket/shelf_web_socket.dart'; | 16 import 'package:shelf_web_socket/shelf_web_socket.dart'; |
| 17 | 17 |
| 18 import '../../backend/metadata.dart'; |
| 18 import '../../backend/suite.dart'; | 19 import '../../backend/suite.dart'; |
| 19 import '../../backend/test_platform.dart'; | 20 import '../../backend/test_platform.dart'; |
| 20 import '../../util/io.dart'; | 21 import '../../util/io.dart'; |
| 21 import '../../util/path_handler.dart'; | 22 import '../../util/path_handler.dart'; |
| 22 import '../../util/one_off_handler.dart'; | 23 import '../../util/one_off_handler.dart'; |
| 23 import '../../utils.dart'; | 24 import '../../utils.dart'; |
| 24 import '../load_exception.dart'; | 25 import '../load_exception.dart'; |
| 25 import 'browser.dart'; | 26 import 'browser.dart'; |
| 26 import 'browser_manager.dart'; | 27 import 'browser_manager.dart'; |
| 27 import 'compiler_pool.dart'; | 28 import 'compiler_pool.dart'; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 ''', headers: {'Content-Type': 'text/html'}); | 217 ''', headers: {'Content-Type': 'text/html'}); |
| 217 } | 218 } |
| 218 | 219 |
| 219 return new shelf.Response.notFound('Not found.'); | 220 return new shelf.Response.notFound('Not found.'); |
| 220 } | 221 } |
| 221 | 222 |
| 222 /// Loads the test suite at [path] on the browser [browser]. | 223 /// Loads the test suite at [path] on the browser [browser]. |
| 223 /// | 224 /// |
| 224 /// This will start a browser to load the suite if one isn't already running. | 225 /// This will start a browser to load the suite if one isn't already running. |
| 225 /// Throws an [ArgumentError] if [browser] isn't a browser platform. | 226 /// Throws an [ArgumentError] if [browser] isn't a browser platform. |
| 226 Future<Suite> loadSuite(String path, TestPlatform browser) { | 227 Future<Suite> loadSuite(String path, TestPlatform browser, |
| 228 Metadata metadata) { |
| 227 if (!browser.isBrowser) { | 229 if (!browser.isBrowser) { |
| 228 throw new ArgumentError("$browser is not a browser."); | 230 throw new ArgumentError("$browser is not a browser."); |
| 229 } | 231 } |
| 230 | 232 |
| 231 return new Future.sync(() { | 233 return new Future.sync(() { |
| 232 if (_pubServeUrl != null) { | 234 if (_pubServeUrl != null) { |
| 233 var suitePrefix = p.relative(path, from: p.join(_root, 'test')) + | 235 var suitePrefix = p.relative(path, from: p.join(_root, 'test')) + |
| 234 '.browser_test'; | 236 '.browser_test'; |
| 235 var jsUrl = _pubServeUrl.resolve('$suitePrefix.dart.js'); | 237 var jsUrl = _pubServeUrl.resolve('$suitePrefix.dart.js'); |
| 236 return _pubServeSuite(path, jsUrl).then((_) => | 238 return _pubServeSuite(path, jsUrl).then((_) => |
| 237 _pubServeUrl.resolve('$suitePrefix.html')); | 239 _pubServeUrl.resolve('$suitePrefix.html')); |
| 238 } | 240 } |
| 239 | 241 |
| 240 return new Future.sync(() => browser.isJS ? _compileSuite(path) : null) | 242 return new Future.sync(() => browser.isJS ? _compileSuite(path) : null) |
| 241 .then((_) { | 243 .then((_) { |
| 242 if (_closed) return null; | 244 if (_closed) return null; |
| 243 return url.resolveUri( | 245 return url.resolveUri( |
| 244 p.toUri(p.relative(path, from: _root) + ".browser_test.html")); | 246 p.toUri(p.relative(path, from: _root) + ".browser_test.html")); |
| 245 }); | 247 }); |
| 246 }).then((suiteUrl) { | 248 }).then((suiteUrl) { |
| 247 if (_closed) return null; | 249 if (_closed) return null; |
| 248 | 250 |
| 249 // TODO(nweiz): Don't start the browser until all the suites are compiled. | 251 // TODO(nweiz): Don't start the browser until all the suites are compiled. |
| 250 return _browserManagerFor(browser).then((browserManager) { | 252 return _browserManagerFor(browser).then((browserManager) { |
| 251 if (_closed) return null; | 253 if (_closed) return null; |
| 252 return browserManager.loadSuite(path, suiteUrl); | 254 return browserManager.loadSuite(path, suiteUrl, metadata); |
| 253 }).then((suite) { | 255 }).then((suite) { |
| 254 if (_closed) return null; | 256 if (_closed) return null; |
| 255 if (suite != null) return suite.change(platform: browser.name); | 257 if (suite != null) return suite.change(platform: browser.name); |
| 256 | 258 |
| 257 // If the browser manager fails to load a suite and the server isn't | 259 // If the browser manager fails to load a suite and the server isn't |
| 258 // closed, it's probably because the browser failed. We emit the failure | 260 // closed, it's probably because the browser failed. We emit the failure |
| 259 // here to ensure that it gets surfaced. | 261 // here to ensure that it gets surfaced. |
| 260 return _browsers[browser].onExit; | 262 return _browsers[browser].onExit; |
| 261 }); | 263 }); |
| 262 }); | 264 }); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 if (_pubServeUrl == null) { | 393 if (_pubServeUrl == null) { |
| 392 new Directory(_compiledDir).deleteSync(recursive: true); | 394 new Directory(_compiledDir).deleteSync(recursive: true); |
| 393 } else { | 395 } else { |
| 394 _http.close(); | 396 _http.close(); |
| 395 } | 397 } |
| 396 | 398 |
| 397 _closeCompleter.complete(); | 399 _closeCompleter.complete(); |
| 398 }).catchError(_closeCompleter.completeError); | 400 }).catchError(_closeCompleter.completeError); |
| 399 } | 401 } |
| 400 } | 402 } |
| OLD | NEW |