Chromium Code Reviews| 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 library browser; | 4 library browser; |
| 5 | 5 |
| 6 import "dart:async"; | 6 import "dart:async"; |
| 7 import "dart:convert" show LineSplitter, UTF8; | 7 import "dart:convert" show LineSplitter, UTF8; |
| 8 import "dart:core"; | 8 import "dart:core"; |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 Process process; | 33 Process process; |
| 34 | 34 |
| 35 Function logger; | 35 Function logger; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * Id of the browser | 38 * Id of the browser |
| 39 */ | 39 */ |
| 40 String id; | 40 String id; |
| 41 | 41 |
| 42 /** Print everything (stdout, stderr, usageLog) whenever we add to it */ | 42 /** Print everything (stdout, stderr, usageLog) whenever we add to it */ |
| 43 bool debugPrint = false; | 43 bool debugPrint = true; |
| 44 | 44 |
| 45 // This future returns when the process exits. It is also the return value | 45 // This future returns when the process exits. It is also the return value |
| 46 // of close() | 46 // of close() |
| 47 Future done; | 47 Future done; |
| 48 | 48 |
| 49 Browser(); | 49 Browser(); |
| 50 | 50 |
| 51 factory Browser.byName(String name) { | 51 factory Browser.byName(String name) { |
| 52 if (name == 'ff' || name == 'firefox') { | 52 if (name == 'ff' || name == 'firefox') { |
| 53 return new Firefox(); | 53 return new Firefox(); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 // Delete the user specific browser cache and profile data. | 311 // Delete the user specific browser cache and profile data. |
| 312 // Safari only have one per user, and you can't specify one by command line. | 312 // Safari only have one per user, and you can't specify one by command line. |
| 313 static bool deleteCache = false; | 313 static bool deleteCache = false; |
| 314 | 314 |
| 315 } | 315 } |
| 316 | 316 |
| 317 | 317 |
| 318 class Chrome extends Browser { | 318 class Chrome extends Browser { |
| 319 static String _binary = _getBinary(); | 319 static String _binary = _getBinary(); |
| 320 | 320 |
| 321 String _version = "Version not found yet"; | |
|
kustermann
2013/09/10 09:27:01
I'm not totally happy about this. You add new inst
ricow1
2013/09/10 10:07:04
Seems like a valid instance variable to me. Could
kustermann
2013/09/10 10:32:43
The issue that _version is not available right fro
| |
| 322 | |
| 321 // This is extracted to a function since we may need to support several | 323 // This is extracted to a function since we may need to support several |
| 322 // locations. | 324 // locations. |
| 323 static String _getWindowsBinary() { | 325 static String _getWindowsBinary() { |
| 324 return "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; | 326 return "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; |
| 325 } | 327 } |
| 326 | 328 |
| 327 static String _getBinary() { | 329 static String _getBinary() { |
| 328 if (Platform.isWindows) return _getWindowsBinary(); | 330 if (Platform.isWindows) return _getWindowsBinary(); |
| 329 if (Platform.isMacOS) { | 331 if (Platform.isMacOS) { |
| 330 return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; | 332 return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; |
| 331 } | 333 } |
| 332 if (Platform.isLinux) return 'google-chrome'; | 334 if (Platform.isLinux) return 'google-chrome'; |
| 333 } | 335 } |
| 334 | 336 |
| 337 Future<String> _getVersion() { | |
|
kustermann
2013/09/10 09:27:01
Make it Future<bool>
ricow1
2013/09/10 10:07:04
Done.
| |
| 338 if (Platform.isWindows) { | |
| 339 // The version flag does not work on windows. | |
| 340 // See issue: | |
| 341 // https://code.google.com/p/chromium/issues/detail?id=158372 | |
| 342 // The registry hack does not seem to work. | |
| 343 _version = "Can't get version on windows"; | |
| 344 // We still validate that the binary exists so that we can give good | |
| 345 // feedback. | |
| 346 return new File(_binary).exists().then((exists) { | |
| 347 if (!exists) { | |
| 348 _logEvent("Chrome binary not available."); | |
|
kustermann
2013/09/10 09:27:01
How about printing the path (i.e. _binary) here as
ricow1
2013/09/10 10:07:04
I do, in the next line!
| |
| 349 _logEvent("Make sure $_binary is a valid program for running chrome"); | |
| 350 } | |
| 351 return exists; | |
| 352 }); | |
| 353 } | |
| 354 return Process.run(_binary, ["--version"]).then((var versionResult) { | |
| 355 if (versionResult.exitCode != 0) { | |
| 356 _logEvent("Failed to chrome get version"); | |
| 357 _logEvent("Make sure $_binary is a valid program for running chrome"); | |
| 358 return false; | |
| 359 } | |
| 360 _version = versionResult.stdout; | |
| 361 return true; | |
| 362 }); | |
| 363 } | |
| 364 | |
| 365 | |
| 335 Future<bool> start(String url) { | 366 Future<bool> start(String url) { |
| 336 _logEvent("Starting chrome browser on: $url"); | 367 _logEvent("Starting chrome browser on: $url"); |
| 337 // Get the version and log that. | 368 // Get the version and log that. |
| 338 return Process.run(_binary, ["--version"]).then((var versionResult) { | 369 return _getVersion().then((success) { |
| 339 if (versionResult.exitCode != 0) { | 370 if (!success) return false; |
| 340 _logEvent("Failed to chrome get version"); | 371 _logEvent("Got version: $_version"); |
| 341 _logEvent("Make sure $binary is a valid program for running chrome"); | |
| 342 return new Future.value(false); | |
| 343 } | |
| 344 version = versionResult.stdout; | |
| 345 _logEvent("Got version: $version"); | |
| 346 | 372 |
| 347 return new Directory('').createTemp().then((userDir) { | 373 return new Directory('').createTemp().then((userDir) { |
| 348 _cleanup = () { userDir.deleteSync(recursive: true); }; | 374 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 349 var args = ["--user-data-dir=${userDir.path}", url, | 375 var args = ["--user-data-dir=${userDir.path}", url, |
| 350 "--disable-extensions", "--disable-popup-blocking", | 376 "--disable-extensions", "--disable-popup-blocking", |
| 351 "--bwsi", "--no-first-run"]; | 377 "--bwsi", "--no-first-run"]; |
| 352 return startBrowser(_binary, args); | 378 return startBrowser(_binary, args); |
| 353 | 379 |
| 354 }); | 380 }); |
| 355 }).catchError((e) { | 381 }).catchError((e) { |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 Dart test driver, number of tests: <div id="number"></div><br> | 1178 Dart test driver, number of tests: <div id="number"></div><br> |
| 1153 Currently executing: <div id="currently_executing"></div><br> | 1179 Currently executing: <div id="currently_executing"></div><br> |
| 1154 Unhandled error: <div id="unhandled_error"></div> | 1180 Unhandled error: <div id="unhandled_error"></div> |
| 1155 <iframe id="embedded_iframe"></iframe> | 1181 <iframe id="embedded_iframe"></iframe> |
| 1156 </body> | 1182 </body> |
| 1157 </html> | 1183 </html> |
| 1158 """; | 1184 """; |
| 1159 return driverContent; | 1185 return driverContent; |
| 1160 } | 1186 } |
| 1161 } | 1187 } |
| OLD | NEW |