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 UTF8, JSON; | 7 import "dart:convert" show UTF8, JSON; |
8 import "dart:core"; | 8 import "dart:core"; |
9 import "dart:io"; | 9 import "dart:io"; |
10 import "dart:math" show min; | 10 import "dart:math" show min; |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 } | 461 } |
462 return exists; | 462 return exists; |
463 }); | 463 }); |
464 } | 464 } |
465 return Process.run(_binary, ["--version"]).then((var versionResult) { | 465 return Process.run(_binary, ["--version"]).then((var versionResult) { |
466 if (versionResult.exitCode != 0) { | 466 if (versionResult.exitCode != 0) { |
467 _logEvent("Failed to chrome get version"); | 467 _logEvent("Failed to chrome get version"); |
468 _logEvent("Make sure $_binary is a valid program for running chrome"); | 468 _logEvent("Make sure $_binary is a valid program for running chrome"); |
469 return false; | 469 return false; |
470 } | 470 } |
471 _version = versionResult.stdout; | 471 _version = versionResult.stdout as String; |
472 return true; | 472 return true; |
473 }); | 473 }); |
474 } | 474 } |
475 | 475 |
476 Future<bool> start(String url) { | 476 Future<bool> start(String url) { |
477 _logEvent("Starting chrome browser on: $url"); | 477 _logEvent("Starting chrome browser on: $url"); |
478 // Get the version and log that. | 478 // Get the version and log that. |
479 return _getVersion().then((success) { | 479 return _getVersion().then<bool>((success) { |
480 if (!success) return false; | 480 if (!success) return false; |
481 _logEvent("Got version: $_version"); | 481 _logEvent("Got version: $_version"); |
482 | 482 |
483 return Directory.systemTemp.createTemp().then((userDir) { | 483 return Directory.systemTemp.createTemp().then((userDir) { |
484 _cleanup = () { | 484 _cleanup = () { |
485 try { | 485 try { |
486 userDir.deleteSync(recursive: true); | 486 userDir.deleteSync(recursive: true); |
487 } catch (e) { | 487 } catch (e) { |
488 _logEvent( | 488 _logEvent( |
489 "Error: failed to delete Chrome user-data-dir ${userDir.path}" | 489 "Error: failed to delete Chrome user-data-dir ${userDir.path}" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", | 608 "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Internet Explorer", |
609 "/v", | 609 "/v", |
610 "svcVersion" | 610 "svcVersion" |
611 ]; | 611 ]; |
612 return Process.run("reg", args).then((result) { | 612 return Process.run("reg", args).then((result) { |
613 if (result.exitCode == 0) { | 613 if (result.exitCode == 0) { |
614 // The string we get back looks like this: | 614 // The string we get back looks like this: |
615 // HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer | 615 // HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer |
616 // version REG_SZ 9.0.8112.16421 | 616 // version REG_SZ 9.0.8112.16421 |
617 var findString = "REG_SZ"; | 617 var findString = "REG_SZ"; |
618 var index = result.stdout.indexOf(findString); | 618 var index = (result.stdout as String).indexOf(findString); |
619 if (index > 0) { | 619 if (index > 0) { |
620 return result.stdout.substring(index + findString.length).trim(); | 620 return (result.stdout as String) |
| 621 .substring(index + findString.length) |
| 622 .trim(); |
621 } | 623 } |
622 } | 624 } |
623 return "Could not get the version of internet explorer"; | 625 return "Could not get the version of internet explorer"; |
624 }); | 626 }); |
625 } | 627 } |
626 | 628 |
627 // Clears the recovery cache if the static resetBrowserConfiguration flag is | 629 // Clears the recovery cache if the static resetBrowserConfiguration flag is |
628 // set. | 630 // set. |
629 Future<bool> resetConfiguration() { | 631 Future<bool> resetConfiguration() { |
630 if (!Browser.resetBrowserConfiguration) return new Future.value(true); | 632 if (!Browser.resetBrowserConfiguration) return new Future.value(true); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 | 812 |
811 Future<bool> start(String url) { | 813 Future<bool> start(String url) { |
812 _logEvent("Starting firefox browser on: $url"); | 814 _logEvent("Starting firefox browser on: $url"); |
813 // Get the version and log that. | 815 // Get the version and log that. |
814 return Process.run(_binary, ["--version"]).then((var versionResult) { | 816 return Process.run(_binary, ["--version"]).then((var versionResult) { |
815 if (versionResult.exitCode != 0) { | 817 if (versionResult.exitCode != 0) { |
816 _logEvent("Failed to firefox get version"); | 818 _logEvent("Failed to firefox get version"); |
817 _logEvent("Make sure $_binary is a valid program for running firefox"); | 819 _logEvent("Make sure $_binary is a valid program for running firefox"); |
818 return new Future.value(false); | 820 return new Future.value(false); |
819 } | 821 } |
820 version = versionResult.stdout; | 822 version = versionResult.stdout as String; |
821 _logEvent("Got version: $version"); | 823 _logEvent("Got version: $version"); |
822 | 824 |
823 return Directory.systemTemp.createTemp().then((userDir) { | 825 return Directory.systemTemp.createTemp().then((userDir) { |
824 _createPreferenceFile(userDir.path); | 826 _createPreferenceFile(userDir.path); |
825 _cleanup = () { | 827 _cleanup = () { |
826 userDir.deleteSync(recursive: true); | 828 userDir.deleteSync(recursive: true); |
827 }; | 829 }; |
828 var args = [ | 830 var args = [ |
829 "-profile", | 831 "-profile", |
830 "${userDir.path}", | 832 "${userDir.path}", |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 /// driver page to the browsers, serves tests, and receives results and | 938 /// driver page to the browsers, serves tests, and receives results and |
937 /// requests back from the browsers. | 939 /// requests back from the browsers. |
938 class BrowserTestRunner { | 940 class BrowserTestRunner { |
939 static const int MAX_NEXT_TEST_TIMEOUTS = 10; | 941 static const int MAX_NEXT_TEST_TIMEOUTS = 10; |
940 static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 120); | 942 static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 120); |
941 static const Duration RESTART_BROWSER_INTERVAL = const Duration(seconds: 60); | 943 static const Duration RESTART_BROWSER_INTERVAL = const Duration(seconds: 60); |
942 | 944 |
943 /// If the queue was recently empty, don't start another browser. | 945 /// If the queue was recently empty, don't start another browser. |
944 static const Duration MIN_NONEMPTY_QUEUE_TIME = const Duration(seconds: 1); | 946 static const Duration MIN_NONEMPTY_QUEUE_TIME = const Duration(seconds: 1); |
945 | 947 |
946 final Map<String, String> configuration; | 948 final Map<String, dynamic> configuration; |
947 final BrowserTestingServer testingServer; | 949 final BrowserTestingServer testingServer; |
948 | 950 |
949 final String localIp; | 951 final String localIp; |
950 final String browserName; | 952 final String browserName; |
951 int maxNumBrowsers; | 953 int maxNumBrowsers; |
952 final bool checkedMode; | 954 final bool checkedMode; |
953 int numBrowsers = 0; | 955 int numBrowsers = 0; |
954 // Used to send back logs from the browser (start, stop etc) | 956 // Used to send back logs from the browser (start, stop etc) |
955 Function logger; | 957 Function logger; |
956 | 958 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 // When no browser is currently starting, _currentStartingBrowserId is null. | 991 // When no browser is currently starting, _currentStartingBrowserId is null. |
990 bool get aBrowserIsCurrentlyStarting => _currentStartingBrowserId != null; | 992 bool get aBrowserIsCurrentlyStarting => _currentStartingBrowserId != null; |
991 void markCurrentlyStarting(String id) { | 993 void markCurrentlyStarting(String id) { |
992 _currentStartingBrowserId = id; | 994 _currentStartingBrowserId = id; |
993 } | 995 } |
994 | 996 |
995 void markNotCurrentlyStarting(String id) { | 997 void markNotCurrentlyStarting(String id) { |
996 if (_currentStartingBrowserId == id) _currentStartingBrowserId = null; | 998 if (_currentStartingBrowserId == id) _currentStartingBrowserId = null; |
997 } | 999 } |
998 | 1000 |
999 BrowserTestRunner(Map configuration, String localIp, String browserName, | 1001 BrowserTestRunner(Map<String, dynamic> configuration, String localIp, |
1000 this.maxNumBrowsers) | 1002 String browserName, this.maxNumBrowsers) |
1001 : configuration = configuration, | 1003 : configuration = configuration, |
1002 localIp = localIp, | 1004 localIp = localIp, |
1003 browserName = (browserName == 'ff') ? 'firefox' : browserName, | 1005 browserName = (browserName == 'ff') ? 'firefox' : browserName, |
1004 checkedMode = configuration['checked'], | 1006 checkedMode = configuration['checked'] as bool, |
1005 testingServer = new BrowserTestingServer( | 1007 testingServer = new BrowserTestingServer( |
1006 configuration, | 1008 configuration, |
1007 localIp, | 1009 localIp, |
1008 Browser.requiresIframe(browserName), | 1010 Browser.requiresIframe(browserName), |
1009 Browser.requiresFocus(browserName)) { | 1011 Browser.requiresFocus(browserName)) { |
1010 testingServer.testRunner = this; | 1012 testingServer.testRunner = this; |
1011 } | 1013 } |
1012 | 1014 |
1013 Future start() async { | 1015 Future start() async { |
1014 await testingServer.start(); | 1016 await testingServer.start(); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 | 1375 |
1374 TestChangedCallback testDoneCallBack; | 1376 TestChangedCallback testDoneCallBack; |
1375 TestChangedCallback testStatusUpdateCallBack; | 1377 TestChangedCallback testStatusUpdateCallBack; |
1376 TestChangedCallback testStartedCallBack; | 1378 TestChangedCallback testStartedCallBack; |
1377 NextTestCallback nextTestCallBack; | 1379 NextTestCallback nextTestCallBack; |
1378 | 1380 |
1379 BrowserTestingServer( | 1381 BrowserTestingServer( |
1380 this.configuration, this.localIp, this.useIframe, this.requiresFocus); | 1382 this.configuration, this.localIp, this.useIframe, this.requiresFocus); |
1381 | 1383 |
1382 Future start() { | 1384 Future start() { |
1383 var testDriverErrorPort = configuration['test_driver_error_port']; | 1385 var testDriverErrorPort = configuration['test_driver_error_port'] as int; |
1384 return HttpServer | 1386 return HttpServer |
1385 .bind(localIp, testDriverErrorPort) | 1387 .bind(localIp, testDriverErrorPort) |
1386 .then(setupErrorServer) | 1388 .then(setupErrorServer) |
1387 .then(setupDispatchingServer); | 1389 .then(setupDispatchingServer); |
1388 } | 1390 } |
1389 | 1391 |
1390 void setupErrorServer(HttpServer server) { | 1392 void setupErrorServer(HttpServer server) { |
1391 errorReportingServer = server; | 1393 errorReportingServer = server; |
1392 void errorReportingHandler(HttpRequest request) { | 1394 void errorReportingHandler(HttpRequest request) { |
1393 StringBuffer buffer = new StringBuffer(); | 1395 StringBuffer buffer = new StringBuffer(); |
(...skipping 15 matching lines...) Expand all Loading... |
1409 } | 1411 } |
1410 | 1412 |
1411 void errorHandler(e) { | 1413 void errorHandler(e) { |
1412 if (!underTermination) print("Error occured in httpserver: $e"); | 1414 if (!underTermination) print("Error occured in httpserver: $e"); |
1413 } | 1415 } |
1414 | 1416 |
1415 errorReportingServer.listen(errorReportingHandler, onError: errorHandler); | 1417 errorReportingServer.listen(errorReportingHandler, onError: errorHandler); |
1416 } | 1418 } |
1417 | 1419 |
1418 void setupDispatchingServer(_) { | 1420 void setupDispatchingServer(_) { |
1419 DispatchingServer server = configuration['_servers_'].server; | 1421 var server = (configuration['_servers_'] as TestingServers).server; |
1420 void noCache(HttpRequest request) { | 1422 void noCache(HttpRequest request) { |
1421 request.response.headers | 1423 request.response.headers |
1422 .set("Cache-Control", "no-cache, no-store, must-revalidate"); | 1424 .set("Cache-Control", "no-cache, no-store, must-revalidate"); |
1423 } | 1425 } |
1424 | 1426 |
1425 int testId(HttpRequest request) => | 1427 int testId(HttpRequest request) => |
1426 int.parse(request.uri.queryParameters["id"]); | 1428 int.parse(request.uri.queryParameters["id"]); |
1427 String browserId(HttpRequest request, String prefix) => | 1429 String browserId(HttpRequest request, String prefix) => |
1428 request.uri.path.substring(prefix.length + 1); | 1430 request.uri.path.substring(prefix.length + 1); |
1429 | 1431 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 return nextTest == null ? waitSignal : nextTest.toJSON(); | 1527 return nextTest == null ? waitSignal : nextTest.toJSON(); |
1526 } | 1528 } |
1527 | 1529 |
1528 String getDriverUrl(String browserId) { | 1530 String getDriverUrl(String browserId) { |
1529 if (errorReportingServer == null) { | 1531 if (errorReportingServer == null) { |
1530 print("Bad browser testing server, you are not started yet. Can't " | 1532 print("Bad browser testing server, you are not started yet. Can't " |
1531 "produce driver url"); | 1533 "produce driver url"); |
1532 exit(1); | 1534 exit(1); |
1533 // This should never happen - exit immediately; | 1535 // This should never happen - exit immediately; |
1534 } | 1536 } |
1535 var port = configuration['_servers_'].port; | 1537 var port = (configuration['_servers_'] as TestingServers).port; |
1536 return "http://$localIp:$port/driver/$browserId"; | 1538 return "http://$localIp:$port/driver/$browserId"; |
1537 } | 1539 } |
1538 | 1540 |
1539 Future<String> getDriverPage(String browserId) async { | 1541 Future<String> getDriverPage(String browserId) async { |
1540 await testRunner.browserStatus[browserId].browser.onDriverPageRequested(); | 1542 await testRunner.browserStatus[browserId].browser.onDriverPageRequested(); |
1541 var errorReportingUrl = | 1543 var errorReportingUrl = |
1542 "http://$localIp:${errorReportingServer.port}/$browserId"; | 1544 "http://$localIp:${errorReportingServer.port}/$browserId"; |
1543 String driverContent = """ | 1545 String driverContent = """ |
1544 <!DOCTYPE html><html> | 1546 <!DOCTYPE html><html> |
1545 <head> | 1547 <head> |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 'exit code: ${result.exitCode}\n' | 1948 'exit code: ${result.exitCode}\n' |
1947 'stdout: ${result.stdout}\n' | 1949 'stdout: ${result.stdout}\n' |
1948 'stderr: ${result.stderr}'); | 1950 'stderr: ${result.stderr}'); |
1949 } else { | 1951 } else { |
1950 print('[$message] Successfully uploaded screenshot to $storageUrl'); | 1952 print('[$message] Successfully uploaded screenshot to $storageUrl'); |
1951 } | 1953 } |
1952 new File(screenshotFile).deleteSync(); | 1954 new File(screenshotFile).deleteSync(); |
1953 } | 1955 } |
1954 print('--------------------------------------------------------------------'); | 1956 print('--------------------------------------------------------------------'); |
1955 } | 1957 } |
OLD | NEW |