| 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:core"; | 7 import "dart:core"; |
| 8 import "dart:io"; | 8 import "dart:io"; |
| 9 | 9 |
| 10 import 'android.dart'; | 10 import 'android.dart'; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 if (line.contains("CFBundleShortVersionString")) { | 227 if (line.contains("CFBundleShortVersionString")) { |
| 228 versionOnNextLine = true; | 228 versionOnNextLine = true; |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 return null; | 231 return null; |
| 232 }); | 232 }); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void _createLaunchHTML(var path, var url) { | 235 void _createLaunchHTML(var path, var url) { |
| 236 var file = new File("${path}/launch.html"); | 236 var file = new File("${path}/launch.html"); |
| 237 var randomFile = file.openSync(mode: FileMode.WRITE); | 237 var randomFile = file.openSync(FileMode.WRITE); |
| 238 var content = '<script language="JavaScript">location = "$url"</script>'; | 238 var content = '<script language="JavaScript">location = "$url"</script>'; |
| 239 randomFile.writeStringSync(content); | 239 randomFile.writeStringSync(content); |
| 240 randomFile.close(); | 240 randomFile.close(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 Future<bool> start(String url) { | 243 Future<bool> start(String url) { |
| 244 _logEvent("Starting Safari browser on: $url"); | 244 _logEvent("Starting Safari browser on: $url"); |
| 245 // Get the version and log that. | 245 // Get the version and log that. |
| 246 return allowPopUps().then((success) { | 246 return allowPopUps().then((success) { |
| 247 if (!success) { | 247 if (!success) { |
| 248 return new Future.value(false); | 248 return new Future.immediate(false); |
| 249 } | 249 } |
| 250 return getVersion().then((version) { | 250 return getVersion().then((version) { |
| 251 _logEvent("Got version: $version"); | 251 _logEvent("Got version: $version"); |
| 252 var args = ["'$url'"]; | 252 var args = ["'$url'"]; |
| 253 return new Directory('').createTemp().then((userDir) { | 253 return new Directory('').createTemp().then((userDir) { |
| 254 _cleanup = () { userDir.deleteSync(recursive: true); }; | 254 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 255 _createLaunchHTML(userDir.path, url); | 255 _createLaunchHTML(userDir.path, url); |
| 256 var args = ["${userDir.path}/launch.html"]; | 256 var args = ["${userDir.path}/launch.html"]; |
| 257 return startBrowser(binary, args); | 257 return startBrowser(binary, args); |
| 258 }); | 258 }); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 274 */ | 274 */ |
| 275 const String binary = "google-chrome"; | 275 const String binary = "google-chrome"; |
| 276 | 276 |
| 277 Future<bool> start(String url) { | 277 Future<bool> start(String url) { |
| 278 _logEvent("Starting chrome browser on: $url"); | 278 _logEvent("Starting chrome browser on: $url"); |
| 279 // Get the version and log that. | 279 // Get the version and log that. |
| 280 return Process.run(binary, ["--version"]).then((var versionResult) { | 280 return Process.run(binary, ["--version"]).then((var versionResult) { |
| 281 if (versionResult.exitCode != 0) { | 281 if (versionResult.exitCode != 0) { |
| 282 _logEvent("Failed to chrome get version"); | 282 _logEvent("Failed to chrome get version"); |
| 283 _logEvent("Make sure $binary is a valid program for running chrome"); | 283 _logEvent("Make sure $binary is a valid program for running chrome"); |
| 284 return new Future.value(false); | 284 return new Future.immediate(false); |
| 285 } | 285 } |
| 286 version = versionResult.stdout; | 286 version = versionResult.stdout; |
| 287 _logEvent("Got version: $version"); | 287 _logEvent("Got version: $version"); |
| 288 | 288 |
| 289 return new Directory('').createTemp().then((userDir) { | 289 return new Directory('').createTemp().then((userDir) { |
| 290 _cleanup = () { userDir.deleteSync(recursive: true); }; | 290 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 291 var args = ["--user-data-dir=${userDir.path}", url, | 291 var args = ["--user-data-dir=${userDir.path}", url, |
| 292 "--disable-extensions", "--disable-popup-blocking", | 292 "--disable-extensions", "--disable-popup-blocking", |
| 293 "--bwsi", "--no-first-run"]; | 293 "--bwsi", "--no-first-run"]; |
| 294 return startBrowser(binary, args); | 294 return startBrowser(binary, args); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 return _adbDevice.startActivity(chromeIntent).then((_) => true); | 356 return _adbDevice.startActivity(chromeIntent).then((_) => true); |
| 357 }); | 357 }); |
| 358 } | 358 } |
| 359 | 359 |
| 360 Future<bool> close() { | 360 Future<bool> close() { |
| 361 if (_adbDevice != null) { | 361 if (_adbDevice != null) { |
| 362 return _adbDevice.forceStop(chromePackage).then((_) { | 362 return _adbDevice.forceStop(chromePackage).then((_) { |
| 363 return _adbDevice.killAll().then((_) => true); | 363 return _adbDevice.killAll().then((_) => true); |
| 364 }); | 364 }); |
| 365 } | 365 } |
| 366 return new Future.value(true); | 366 return new Future.immediate(true); |
| 367 } | 367 } |
| 368 | 368 |
| 369 String toString() => "chromeOnAndroid"; | 369 String toString() => "chromeOnAndroid"; |
| 370 } | 370 } |
| 371 | 371 |
| 372 class Firefox extends Browser { | 372 class Firefox extends Browser { |
| 373 /** | 373 /** |
| 374 * The binary used to run firefox - changing this can be nececcary for | 374 * The binary used to run firefox - changing this can be nececcary for |
| 375 * testing or using non standard firefox installation. | 375 * testing or using non standard firefox installation. |
| 376 */ | 376 */ |
| 377 const String binary = "firefox"; | 377 const String binary = "firefox"; |
| 378 | 378 |
| 379 const String enablePopUp = | 379 const String enablePopUp = |
| 380 'user_pref("dom.disable_open_during_load", false);'; | 380 'user_pref("dom.disable_open_during_load", false);'; |
| 381 const String disableDefaultCheck = | 381 const String disableDefaultCheck = |
| 382 'user_pref("browser.shell.checkDefaultBrowser", false);'; | 382 'user_pref("browser.shell.checkDefaultBrowser", false);'; |
| 383 | 383 |
| 384 Future _createPreferenceFile(var path) { | 384 Future _createPreferenceFile(var path) { |
| 385 var file = new File("${path.toString()}/user.js"); | 385 var file = new File("${path.toString()}/user.js"); |
| 386 var randomFile = file.openSync(mode: FileMode.WRITE); | 386 var randomFile = file.openSync(FileMode.WRITE); |
| 387 randomFile.writeStringSync(enablePopUp); | 387 randomFile.writeStringSync(enablePopUp); |
| 388 randomFile.writeStringSync(disableDefaultCheck); | 388 randomFile.writeStringSync(disableDefaultCheck); |
| 389 randomFile.close(); | 389 randomFile.close(); |
| 390 } | 390 } |
| 391 | 391 |
| 392 | 392 |
| 393 Future<bool> start(String url) { | 393 Future<bool> start(String url) { |
| 394 _logEvent("Starting firefox browser on: $url"); | 394 _logEvent("Starting firefox browser on: $url"); |
| 395 // Get the version and log that. | 395 // Get the version and log that. |
| 396 return Process.run(binary, ["--version"]).then((var versionResult) { | 396 return Process.run(binary, ["--version"]).then((var versionResult) { |
| 397 if (versionResult.exitCode != 0) { | 397 if (versionResult.exitCode != 0) { |
| 398 _logEvent("Failed to firefox get version"); | 398 _logEvent("Failed to firefox get version"); |
| 399 _logEvent("Make sure $binary is a valid program for running firefox"); | 399 _logEvent("Make sure $binary is a valid program for running firefox"); |
| 400 return new Future.value(false); | 400 return new Future.immediate(false); |
| 401 } | 401 } |
| 402 version = versionResult.stdout; | 402 version = versionResult.stdout; |
| 403 _logEvent("Got version: $version"); | 403 _logEvent("Got version: $version"); |
| 404 | 404 |
| 405 return new Directory('').createTemp().then((userDir) { | 405 return new Directory('').createTemp().then((userDir) { |
| 406 _createPreferenceFile(userDir.path); | 406 _createPreferenceFile(userDir.path); |
| 407 _cleanup = () { userDir.deleteSync(recursive: true); }; | 407 _cleanup = () { userDir.deleteSync(recursive: true); }; |
| 408 var args = ["-profile", "${userDir.path}", | 408 var args = ["-profile", "${userDir.path}", |
| 409 "-no-remote", "-new-instance", url]; | 409 "-no-remote", "-new-instance", url]; |
| 410 return startBrowser(binary, args); | 410 return startBrowser(binary, args); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 755 |
| 756 BrowserTestingServer(this.local_ip, this.useIframe); | 756 BrowserTestingServer(this.local_ip, this.useIframe); |
| 757 | 757 |
| 758 Future start() { | 758 Future start() { |
| 759 return HttpServer.bind(local_ip, 0).then((createdServer) { | 759 return HttpServer.bind(local_ip, 0).then((createdServer) { |
| 760 httpServer = createdServer; | 760 httpServer = createdServer; |
| 761 void handler(HttpRequest request) { | 761 void handler(HttpRequest request) { |
| 762 DebugLogger.info("Handling request to: ${request.uri.path}"); | 762 DebugLogger.info("Handling request to: ${request.uri.path}"); |
| 763 if (request.uri.path.startsWith(reportPath)) { | 763 if (request.uri.path.startsWith(reportPath)) { |
| 764 var browserId = request.uri.path.substring(reportPath.length + 1); | 764 var browserId = request.uri.path.substring(reportPath.length + 1); |
| 765 var testId = | 765 var testId = int.parse(request.queryParameters["id"].split("=")[1]); |
| 766 int.parse(request.uri.queryParameters["id"].split("=")[1]); | 766 |
| 767 handleReport(request, browserId, testId); | 767 handleReport(request, browserId, testId); |
| 768 // handleReport will asynchroniously fetch the data and will handle | 768 // handleReport will asynchroniously fetch the data and will handle |
| 769 // the closing of the streams. | 769 // the closing of the streams. |
| 770 return; | 770 return; |
| 771 } | 771 } |
| 772 var textResponse = ""; | 772 var textResponse = ""; |
| 773 if (request.uri.path.startsWith(driverPath)) { | 773 if (request.uri.path.startsWith(driverPath)) { |
| 774 var browserId = request.uri.path.substring(driverPath.length + 1); | 774 var browserId = request.uri.path.substring(driverPath.length + 1); |
| 775 textResponse = getDriverPage(browserId); | 775 textResponse = getDriverPage(browserId); |
| 776 } else if (request.uri.path.startsWith(nextTestPath)) { | 776 } else if (request.uri.path.startsWith(nextTestPath)) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 | 887 |
| 888 function newTaskHandler() { | 888 function newTaskHandler() { |
| 889 if (this.readyState == this.DONE) { | 889 if (this.readyState == this.DONE) { |
| 890 if (this.status == 200) { | 890 if (this.status == 200) { |
| 891 if (this.responseText == '$waitSignal') { | 891 if (this.responseText == '$waitSignal') { |
| 892 setTimeout(getNextTask, 500); | 892 setTimeout(getNextTask, 500); |
| 893 } else if (this.responseText == '$terminateSignal') { | 893 } else if (this.responseText == '$terminateSignal') { |
| 894 // Don't do anything, we will be killed shortly. | 894 // Don't do anything, we will be killed shortly. |
| 895 } else { | 895 } else { |
| 896 var elapsed = new Date() - start; | 896 var elapsed = new Date() - start; |
| 897 reportError('Done getting task at: ' + elapsed); |
| 897 // TODO(ricow): Do something more clever here. | 898 // TODO(ricow): Do something more clever here. |
| 898 if (nextTask != undefined) alert('This is really bad'); | 899 if (nextTask != undefined) alert('This is really bad'); |
| 899 // The task is send to us as: | 900 // The task is send to us as: |
| 900 // URL#ID | 901 // URL#ID |
| 901 var split = this.responseText.split('#'); | 902 var split = this.responseText.split('#'); |
| 902 var nextTask = split[0]; | 903 var nextTask = split[0]; |
| 903 current_id = split[1]; | 904 current_id = split[1]; |
| 904 reportError('Done getting task : ' + elapsed); | |
| 905 did_start = false; | 905 did_start = false; |
| 906 run(nextTask); | 906 run(nextTask); |
| 907 } | 907 } |
| 908 } else { | 908 } else { |
| 909 reportError('Could not contact the server and get a new task'); | 909 reportError('Could not contact the server and get a new task'); |
| 910 } | 910 } |
| 911 } | 911 } |
| 912 } | 912 } |
| 913 | 913 |
| 914 function getNextTask() { | 914 function getNextTask() { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 </head> | 1007 </head> |
| 1008 <body onload="startTesting()"> | 1008 <body onload="startTesting()"> |
| 1009 Dart test driver, number of tests: <div id="number"></div> | 1009 Dart test driver, number of tests: <div id="number"></div> |
| 1010 <iframe id="embedded_iframe"></iframe> | 1010 <iframe id="embedded_iframe"></iframe> |
| 1011 </body> | 1011 </body> |
| 1012 </html> | 1012 </html> |
| 1013 """; | 1013 """; |
| 1014 return driverContent; | 1014 return driverContent; |
| 1015 } | 1015 } |
| 1016 } | 1016 } |
| OLD | NEW |