| 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.phantom_js; | 5 library test.runner.browser.phantom_js; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 11 | 11 |
| 12 import '../../util/exit_codes.dart' as exit_codes; |
| 12 import '../../util/io.dart'; | 13 import '../../util/io.dart'; |
| 14 import '../application_exception.dart'; |
| 13 import 'browser.dart'; | 15 import 'browser.dart'; |
| 14 | 16 |
| 15 /// The PhantomJS script that opens the host page. | 17 /// The PhantomJS script that opens the host page. |
| 16 final _script = """ | 18 final _script = """ |
| 17 var system = require('system'); | 19 var system = require('system'); |
| 18 var page = require('webpage').create(); | 20 var page = require('webpage').create(); |
| 19 | 21 |
| 22 // PhantomJS versions older than 2.0.0 don't support the latest WebSocket spec. |
| 23 if (phantom.version.major < 2) phantom.exit(${exit_codes.protocol}); |
| 24 |
| 20 // Pipe browser messages to the process's stdout. This isn't used by default, | 25 // Pipe browser messages to the process's stdout. This isn't used by default, |
| 21 // but it can be useful for debugging. | 26 // but it can be useful for debugging. |
| 22 page.onConsoleMessage = function(message) { | 27 page.onConsoleMessage = function(message) { |
| 23 console.log(message); | 28 console.log(message); |
| 24 } | 29 } |
| 25 | 30 |
| 26 page.open(system.args[1], function(status) { | 31 page.open(system.args[1], function(status) { |
| 27 if (status !== "success") phantom.exit(1); | 32 if (status !== "success") phantom.exit(1); |
| 28 }); | 33 }); |
| 29 """; | 34 """; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // PhantomJS synchronously emits standard output, which means that if we | 71 // PhantomJS synchronously emits standard output, which means that if we |
| 67 // don't drain its stdout stream it can deadlock. | 72 // don't drain its stdout stream it can deadlock. |
| 68 process.stdout.listen((_) {}); | 73 process.stdout.listen((_) {}); |
| 69 | 74 |
| 70 _process = process; | 75 _process = process; |
| 71 _onProcessStartedCompleter.complete(); | 76 _onProcessStartedCompleter.complete(); |
| 72 | 77 |
| 73 return _process.exitCode; | 78 return _process.exitCode; |
| 74 }); | 79 }); |
| 75 }).then((exitCode) { | 80 }).then((exitCode) { |
| 81 if (exitCode == exit_codes.protocol) { |
| 82 throw new ApplicationException( |
| 83 "Only PhantomJS version 2.0.0 or greater is supported."); |
| 84 } |
| 76 if (exitCode != 0) throw "PhantomJS failed with exit code $exitCode."; | 85 if (exitCode != 0) throw "PhantomJS failed with exit code $exitCode."; |
| 77 }).then(_onExitCompleter.complete) | 86 }).then(_onExitCompleter.complete) |
| 78 .catchError(_onExitCompleter.completeError); | 87 .catchError(_onExitCompleter.completeError); |
| 79 } | 88 } |
| 80 | 89 |
| 81 Future close() { | 90 Future close() { |
| 82 _onProcessStarted.then((_) => _process.kill()); | 91 _onProcessStarted.then((_) => _process.kill()); |
| 83 | 92 |
| 84 // Swallow exceptions. The user should explicitly use [onExit] for these. | 93 // Swallow exceptions. The user should explicitly use [onExit] for these. |
| 85 return onExit.catchError((_) {}); | 94 return onExit.catchError((_) {}); |
| 86 } | 95 } |
| 87 } | 96 } |
| OLD | NEW |