| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 /** The version of the browser - normally set when starting a browser */ | 31 /** The version of the browser - normally set when starting a browser */ |
| 32 String version = ""; | 32 String version = ""; |
| 33 /** | 33 /** |
| 34 * The underlying process - don't mess directly with this if you don't | 34 * The underlying process - don't mess directly with this if you don't |
| 35 * know what you are doing (this is an interactive process that needs | 35 * know what you are doing (this is an interactive process that needs |
| 36 * special threatment to not leak). | 36 * special threatment to not leak). |
| 37 */ | 37 */ |
| 38 Process process; | 38 Process process; |
| 39 | 39 |
| 40 Function logger; |
| 41 |
| 40 /** | 42 /** |
| 41 * Id of the browser | 43 * Id of the browser |
| 42 */ | 44 */ |
| 43 String id; | 45 String id; |
| 44 | 46 |
| 45 /** Callback that will be executed when the browser has closed */ | 47 /** Callback that will be executed when the browser has closed */ |
| 46 Function onClose; | 48 Function onClose; |
| 47 | 49 |
| 48 /** Print everything (stdout, stderr, usageLog) whenever we add to it */ | 50 /** Print everything (stdout, stderr, usageLog) whenever we add to it */ |
| 49 bool debugPrint = true; | 51 bool debugPrint = false; |
| 50 | 52 |
| 51 // We use this to gracefully handle double calls to close. | 53 // We use this to gracefully handle double calls to close. |
| 52 bool underTermination = false; | 54 bool underTermination = false; |
| 53 | 55 |
| 54 void _logEvent(String event) { | 56 void _logEvent(String event) { |
| 55 String toLog = "$this ($id) - ${new DateTime.now()}: $event \n"; | 57 String toLog = "$this ($id) - ${new DateTime.now()}: $event \n"; |
| 56 if (debugPrint) print("usageLog: $toLog"); | 58 if (debugPrint) print("usageLog: $toLog"); |
| 59 if (logger != null) logger(toLog); |
| 57 _usageLog.write(toLog); | 60 _usageLog.write(toLog); |
| 58 } | 61 } |
| 59 | 62 |
| 60 void _addStdout(String output) { | 63 void _addStdout(String output) { |
| 61 if (debugPrint) print("stdout: $output"); | 64 if (debugPrint) print("stdout: $output"); |
| 62 _stdout.write(output); | 65 _stdout.write(output); |
| 63 } | 66 } |
| 64 | 67 |
| 65 void _addStderr(String output) { | 68 void _addStderr(String output) { |
| 66 if (debugPrint) print("stderr: $output"); | 69 if (debugPrint) print("stderr: $output"); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 /** | 492 /** |
| 490 * Encapsulates all the functionality for running tests in browsers. | 493 * Encapsulates all the functionality for running tests in browsers. |
| 491 * The interface is rather simple. After starting the runner tests | 494 * The interface is rather simple. After starting the runner tests |
| 492 * are simply added to the queue and a the supplied callbacks are called | 495 * are simply added to the queue and a the supplied callbacks are called |
| 493 * whenever a test completes. | 496 * whenever a test completes. |
| 494 */ | 497 */ |
| 495 class BrowserTestRunner { | 498 class BrowserTestRunner { |
| 496 String local_ip; | 499 String local_ip; |
| 497 String browserName; | 500 String browserName; |
| 498 int maxNumBrowsers; | 501 int maxNumBrowsers; |
| 502 // Used to send back logs from the browser (start, stop etc) |
| 503 Function logger; |
| 499 | 504 |
| 500 bool underTermination = false; | 505 bool underTermination = false; |
| 501 | 506 |
| 502 List<BrowserTest> testQueue = new List<BrowserTest>(); | 507 List<BrowserTest> testQueue = new List<BrowserTest>(); |
| 503 Map<String, BrowserTestingStatus> browserStatus = | 508 Map<String, BrowserTestingStatus> browserStatus = |
| 504 new Map<String, BrowserTestingStatus>(); | 509 new Map<String, BrowserTestingStatus>(); |
| 505 | 510 |
| 506 var adbDeviceMapping = new Map<String, AdbDevice>(); | 511 var adbDeviceMapping = new Map<String, AdbDevice>(); |
| 507 // This cache is used to guarantee that we never see double reporting. | 512 // This cache is used to guarantee that we never see double reporting. |
| 508 // If we do we need to provide developers with this information. | 513 // If we do we need to provide developers with this information. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 futures.add(status.browser.close()); | 712 futures.add(status.browser.close()); |
| 708 } | 713 } |
| 709 return Future.wait(futures).then((values) { | 714 return Future.wait(futures).then((values) { |
| 710 testingServer.httpServer.close(); | 715 testingServer.httpServer.close(); |
| 711 printDoubleReportingTests(); | 716 printDoubleReportingTests(); |
| 712 return !values.contains(false); | 717 return !values.contains(false); |
| 713 }); | 718 }); |
| 714 } | 719 } |
| 715 | 720 |
| 716 Browser getInstance() { | 721 Browser getInstance() { |
| 722 var browser; |
| 717 if (browserName == "chrome") { | 723 if (browserName == "chrome") { |
| 718 return new Chrome(); | 724 browser = new Chrome(); |
| 719 } else if (browserName == "ff") { | 725 } else if (browserName == "ff") { |
| 720 return new Firefox(); | 726 browser = new Firefox(); |
| 721 } else if (browserName == "safari") { | 727 } else if (browserName == "safari") { |
| 722 return new Safari(); | 728 browser = new Safari(); |
| 723 } else { | 729 } else { |
| 724 throw "Non supported browser for browser controller"; | 730 throw "Non supported browser for browser controller"; |
| 725 } | 731 } |
| 732 browser.logger = logger; |
| 733 return browser; |
| 726 } | 734 } |
| 727 } | 735 } |
| 728 | 736 |
| 729 class BrowserTestingServer { | 737 class BrowserTestingServer { |
| 730 /// Interface of the testing server: | 738 /// Interface of the testing server: |
| 731 /// | 739 /// |
| 732 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch | 740 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch |
| 733 /// and run tests ... | 741 /// and run tests ... |
| 734 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" | 742 /// GET /next_test/BROWSER_ID -- returns "WAIT" "TERMINATE" or "url#id" |
| 735 /// where url is the test to run, and id is the id of the test. | 743 /// where url is the test to run, and id is the id of the test. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 </script> | 938 </script> |
| 931 </head> | 939 </head> |
| 932 <body> | 940 <body> |
| 933 Dart test driver, number of tests: <div id="number"></div> | 941 Dart test driver, number of tests: <div id="number"></div> |
| 934 </body> | 942 </body> |
| 935 </html> | 943 </html> |
| 936 """; | 944 """; |
| 937 return driverContent; | 945 return driverContent; |
| 938 } | 946 } |
| 939 } | 947 } |
| OLD | NEW |