| 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 727 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 738 class BrowserTestingStatus { | 738 class BrowserTestingStatus { | 
| 739   Browser browser; | 739   Browser browser; | 
| 740   BrowserTest currentTest; | 740   BrowserTest currentTest; | 
| 741 | 741 | 
| 742   // This is currently not used for anything except for error reporting. | 742   // This is currently not used for anything except for error reporting. | 
| 743   // Given the usefulness of this in debugging issues this should not be | 743   // Given the usefulness of this in debugging issues this should not be | 
| 744   // removed even when we have a really stable system. | 744   // removed even when we have a really stable system. | 
| 745   BrowserTest lastTest; | 745   BrowserTest lastTest; | 
| 746   bool timeout = false; | 746   bool timeout = false; | 
| 747   Timer nextTestTimeout; | 747   Timer nextTestTimeout; | 
| 748   Stopwatch timeSinceRestart = new Stopwatch(); |  | 
| 749 | 748 | 
| 750   BrowserTestingStatus(Browser this.browser); | 749   BrowserTestingStatus(Browser this.browser); | 
| 751 } | 750 } | 
| 752 | 751 | 
| 753 | 752 | 
| 754 /** | 753 /** | 
| 755  * Describes a single test to be run in the browser. | 754  * Describes a single test to be run in the browser. | 
| 756  */ | 755  */ | 
| 757 class BrowserTest { | 756 class BrowserTest { | 
| 758   // TODO(ricow): Add timeout callback instead of the string passing hack. | 757   // TODO(ricow): Add timeout callback instead of the string passing hack. | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 796 | 795 | 
| 797 /** | 796 /** | 
| 798  * Encapsulates all the functionality for running tests in browsers. | 797  * Encapsulates all the functionality for running tests in browsers. | 
| 799  * The interface is rather simple. After starting, the runner tests | 798  * The interface is rather simple. After starting, the runner tests | 
| 800  * are simply added to the queue and a the supplied callbacks are called | 799  * are simply added to the queue and a the supplied callbacks are called | 
| 801  * whenever a test completes. | 800  * whenever a test completes. | 
| 802  */ | 801  */ | 
| 803 class BrowserTestRunner { | 802 class BrowserTestRunner { | 
| 804   static const int MAX_NEXT_TEST_TIMEOUTS = 10; | 803   static const int MAX_NEXT_TEST_TIMEOUTS = 10; | 
| 805   static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 60); | 804   static const Duration NEXT_TEST_TIMEOUT = const Duration(seconds: 60); | 
| 806   static const Duration RESTART_BROWSER_INTERVAL = const Duration(seconds: 60); |  | 
| 807 | 805 | 
| 808   final Map globalConfiguration; | 806   final Map globalConfiguration; | 
| 809   final bool checkedMode; // needed for dartium | 807   final bool checkedMode; // needed for dartium | 
| 810 | 808 | 
| 811   String localIp; | 809   String localIp; | 
| 812   String browserName; | 810   String browserName; | 
| 813   int maxNumBrowsers; | 811   int maxNumBrowsers; | 
| 814   // Used to send back logs from the browser (start, stop etc) | 812   // Used to send back logs from the browser (start, stop etc) | 
| 815   Function logger; | 813   Function logger; | 
| 816   int browserIdCount = 0; | 814   int browserIdCount = 0; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 859       testingServer.nextTestCallBack = getNextTest; | 857       testingServer.nextTestCallBack = getNextTest; | 
| 860       return getBrowsers().then((browsers) { | 858       return getBrowsers().then((browsers) { | 
| 861         var futures = []; | 859         var futures = []; | 
| 862         for (var browser in browsers) { | 860         for (var browser in browsers) { | 
| 863           var url = testingServer.getDriverUrl(browser.id); | 861           var url = testingServer.getDriverUrl(browser.id); | 
| 864           var future = browser.start(url).then((success) { | 862           var future = browser.start(url).then((success) { | 
| 865             if (success) { | 863             if (success) { | 
| 866               var status = new BrowserTestingStatus(browser); | 864               var status = new BrowserTestingStatus(browser); | 
| 867               browserStatus[browser.id] = status; | 865               browserStatus[browser.id] = status; | 
| 868               status.nextTestTimeout = createNextTestTimer(status); | 866               status.nextTestTimeout = createNextTestTimer(status); | 
| 869               status.timeSinceRestart.start(); |  | 
| 870             } | 867             } | 
| 871             return success; | 868             return success; | 
| 872           }); | 869           }); | 
| 873           futures.add(future); | 870           futures.add(future); | 
| 874         } | 871         } | 
| 875         return Future.wait(futures).then((values) { | 872         return Future.wait(futures).then((values) { | 
| 876           return !values.contains(false); | 873           return !values.contains(false); | 
| 877         }); | 874         }); | 
| 878       }); | 875       }); | 
| 879     }); | 876     }); | 
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1044     } else { | 1041     } else { | 
| 1045       browserStatus.remove(id); | 1042       browserStatus.remove(id); | 
| 1046       browser = getInstance(); | 1043       browser = getInstance(); | 
| 1047       new_id = "BROWSER$browserIdCount"; | 1044       new_id = "BROWSER$browserIdCount"; | 
| 1048       browserIdCount++; | 1045       browserIdCount++; | 
| 1049     } | 1046     } | 
| 1050     browser.id = new_id; | 1047     browser.id = new_id; | 
| 1051     var status = new BrowserTestingStatus(browser); | 1048     var status = new BrowserTestingStatus(browser); | 
| 1052     browserStatus[new_id] = status; | 1049     browserStatus[new_id] = status; | 
| 1053     status.nextTestTimeout = createNextTestTimer(status); | 1050     status.nextTestTimeout = createNextTestTimer(status); | 
| 1054     status.timeSinceRestart.start(); |  | 
| 1055     browser.start(testingServer.getDriverUrl(new_id)).then((success) { | 1051     browser.start(testingServer.getDriverUrl(new_id)).then((success) { | 
| 1056       // We may have started terminating in the mean time. | 1052       // We may have started terminating in the mean time. | 
| 1057       if (underTermination) { | 1053       if (underTermination) { | 
| 1058         if (status.nextTestTimeout != null) { | 1054         if (status.nextTestTimeout != null) { | 
| 1059           status.nextTestTimeout.cancel(); | 1055           status.nextTestTimeout.cancel(); | 
| 1060           status.nextTestTimeout = null; | 1056           status.nextTestTimeout = null; | 
| 1061         } | 1057         } | 
| 1062         browser.close().then((success) { | 1058         browser.close().then((success) { | 
| 1063          // We should never hit this, print it out. | 1059          // We should never hit this, print it out. | 
| 1064           if (!success) { | 1060           if (!success) { | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 1080     if (status == null) return null; | 1076     if (status == null) return null; | 
| 1081     if (status.nextTestTimeout != null) { | 1077     if (status.nextTestTimeout != null) { | 
| 1082       status.nextTestTimeout.cancel(); | 1078       status.nextTestTimeout.cancel(); | 
| 1083       status.nextTestTimeout = null; | 1079       status.nextTestTimeout = null; | 
| 1084     } | 1080     } | 
| 1085     if (testQueue.isEmpty) return null; | 1081     if (testQueue.isEmpty) return null; | 
| 1086 | 1082 | 
| 1087     // We are currently terminating this browser, don't start a new test. | 1083     // We are currently terminating this browser, don't start a new test. | 
| 1088     if (status.timeout) return null; | 1084     if (status.timeout) return null; | 
| 1089 | 1085 | 
| 1090     // Restart content_shell and dartium on Android if they have been |  | 
| 1091     // running for longer than RESTART_BROWSER_INTERVAL. The tests have |  | 
| 1092     // had flaky timeouts, and this may help. |  | 
| 1093     if ((browserName == 'ContentShellOnAndroid' || |  | 
| 1094          browserName == 'DartiumOnAndroid' ) && |  | 
| 1095         status.timeSinceRestart.elapsed > RESTART_BROWSER_INTERVAL) { |  | 
| 1096       var id = status.browser.id; |  | 
| 1097       status.browser.close().then((_) { |  | 
| 1098         // We don't want to start a new browser if we are terminating. |  | 
| 1099         if (underTermination) return; |  | 
| 1100         restartBrowser(id); |  | 
| 1101       }); |  | 
| 1102       // Don't send a test to the browser we are restarting. |  | 
| 1103       return null; |  | 
| 1104     } |  | 
| 1105 |  | 
| 1106     BrowserTest test = testQueue.removeLast(); | 1086     BrowserTest test = testQueue.removeLast(); | 
| 1107     if (status.currentTest == null) { | 1087     if (status.currentTest == null) { | 
| 1108       status.currentTest = test; | 1088       status.currentTest = test; | 
| 1109       status.currentTest.lastKnownMessage = ''; | 1089       status.currentTest.lastKnownMessage = ''; | 
| 1110     } else { | 1090     } else { | 
| 1111       // TODO(ricow): Handle this better. | 1091       // TODO(ricow): Handle this better. | 
| 1112       print("Browser requested next test before reporting previous result"); | 1092       print("Browser requested next test before reporting previous result"); | 
| 1113       print("This happened for browser $browserId"); | 1093       print("This happened for browser $browserId"); | 
| 1114       print("Old test was: ${status.currentTest.url}"); | 1094       print("Old test was: ${status.currentTest.url}"); | 
| 1115       print("The test before that was: ${status.lastTest.url}"); | 1095       print("The test before that was: ${status.lastTest.url}"); | 
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1577     Dart test driver, number of tests: <div id="number"></div><br> | 1557     Dart test driver, number of tests: <div id="number"></div><br> | 
| 1578     Currently executing: <div id="currently_executing"></div><br> | 1558     Currently executing: <div id="currently_executing"></div><br> | 
| 1579     Unhandled error: <div id="unhandled_error"></div> | 1559     Unhandled error: <div id="unhandled_error"></div> | 
| 1580     <iframe id="embedded_iframe"></iframe> | 1560     <iframe id="embedded_iframe"></iframe> | 
| 1581   </body> | 1561   </body> | 
| 1582 </html> | 1562 </html> | 
| 1583 """; | 1563 """; | 
| 1584     return driverContent; | 1564     return driverContent; | 
| 1585   } | 1565   } | 
| 1586 } | 1566 } | 
| OLD | NEW | 
|---|