| 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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 439 |
| 440 | 440 |
| 441 /** | 441 /** |
| 442 * Describes a single test to be run int the browser. | 442 * Describes a single test to be run int the browser. |
| 443 */ | 443 */ |
| 444 class BrowserTest { | 444 class BrowserTest { |
| 445 // TODO(ricow): Add timeout callback instead of the string passing hack. | 445 // TODO(ricow): Add timeout callback instead of the string passing hack. |
| 446 Function doneCallback; | 446 Function doneCallback; |
| 447 String url; | 447 String url; |
| 448 int timeout; | 448 int timeout; |
| 449 Stopwatch stopwatch; |
| 449 // We store this here for easy access when tests time out (instead of | 450 // We store this here for easy access when tests time out (instead of |
| 450 // capturing this in a closure) | 451 // capturing this in a closure) |
| 451 Timer timeoutTimer; | 452 Timer timeoutTimer; |
| 452 | 453 |
| 453 // Used for debugging, this is simply a unique identifier assigned to each | 454 // Used for debugging, this is simply a unique identifier assigned to each |
| 454 // test. | 455 // test. |
| 455 int id; | 456 int id; |
| 456 static int _idCounter = 0; | 457 static int _idCounter = 0; |
| 457 | 458 |
| 458 BrowserTest(this.url, this.doneCallback, this.timeout) { | 459 BrowserTest(this.url, this.doneCallback, this.timeout) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (testCache.containsKey(testId)) { | 567 if (testCache.containsKey(testId)) { |
| 567 doubleReportingTests.add(testId); | 568 doubleReportingTests.add(testId); |
| 568 return; | 569 return; |
| 569 } | 570 } |
| 570 | 571 |
| 571 if (status.timeout) { | 572 if (status.timeout) { |
| 572 // We don't do anything, this browser is currently being killed and | 573 // We don't do anything, this browser is currently being killed and |
| 573 // replaced. | 574 // replaced. |
| 574 } else if (status.currentTest != null) { | 575 } else if (status.currentTest != null) { |
| 575 status.currentTest.timeoutTimer.cancel(); | 576 status.currentTest.timeoutTimer.cancel(); |
| 577 status.currentTest.stopwatch.stop(); |
| 578 |
| 576 if (status.currentTest.id != testId) { | 579 if (status.currentTest.id != testId) { |
| 577 print("Expected test id ${status.currentTest.id} for" | 580 print("Expected test id ${status.currentTest.id} for" |
| 578 "${status.currentTest.url}"); | 581 "${status.currentTest.url}"); |
| 579 print("Got test id ${testId}"); | 582 print("Got test id ${testId}"); |
| 580 print("Last test id was ${status.lastTest.id} for " | 583 print("Last test id was ${status.lastTest.id} for " |
| 581 "${status.currentTest.url}"); | 584 "${status.currentTest.url}"); |
| 582 throw("This should never happen, wrong test id"); | 585 throw("This should never happen, wrong test id"); |
| 583 } | 586 } |
| 584 testCache[testId] = status.currentTest.url; | 587 testCache[testId] = status.currentTest.url; |
| 585 status.currentTest.doneCallback(output); | 588 status.currentTest.doneCallback(output, |
| 589 status.currentTest.stopwatch.elapsed); |
| 586 status.lastTest = status.currentTest; | 590 status.lastTest = status.currentTest; |
| 587 status.currentTest = null; | 591 status.currentTest = null; |
| 588 } else { | 592 } else { |
| 589 print("\nThis is bad, should never happen, handleResult no test"); | 593 print("\nThis is bad, should never happen, handleResult no test"); |
| 590 print("URL: ${status.lastTest.url}"); | 594 print("URL: ${status.lastTest.url}"); |
| 591 print(output); | 595 print(output); |
| 592 terminate().then((_) { | 596 terminate().then((_) { |
| 593 exit(1); | 597 exit(1); |
| 594 }); | 598 }); |
| 595 } | 599 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 640 } |
| 637 if (success) { | 641 if (success) { |
| 638 browserStatus[browser.id] = new BrowserTestingStatus(browser); | 642 browserStatus[browser.id] = new BrowserTestingStatus(browser); |
| 639 } else { | 643 } else { |
| 640 // TODO(ricow): Handle this better. | 644 // TODO(ricow): Handle this better. |
| 641 print("This is bad, should never happen, could not start browser"); | 645 print("This is bad, should never happen, could not start browser"); |
| 642 exit(1); | 646 exit(1); |
| 643 } | 647 } |
| 644 }); | 648 }); |
| 645 }); | 649 }); |
| 646 | 650 status.currentTest.stopwatch.stop(); |
| 647 status.currentTest.doneCallback("TIMEOUT"); | 651 status.currentTest.doneCallback("TIMEOUT", |
| 652 status.currentTest.stopwatch.elapsed); |
| 648 status.currentTest = null; | 653 status.currentTest = null; |
| 649 } | 654 } |
| 650 | 655 |
| 651 BrowserTest getNextTest(String browserId) { | 656 BrowserTest getNextTest(String browserId) { |
| 652 if (testQueue.isEmpty) return null; | 657 if (testQueue.isEmpty) return null; |
| 653 var status = browserStatus[browserId]; | 658 var status = browserStatus[browserId]; |
| 654 if (status == null) return null; | 659 if (status == null) return null; |
| 655 DebugLogger.info("${new DateTime.now()}: Handling getNext for browser " | 660 DebugLogger.info("${new DateTime.now()}: Handling getNext for browser " |
| 656 "${browserId} timeout status: ${status.timeout}"); | 661 "${browserId} timeout status: ${status.timeout}"); |
| 657 | 662 |
| 658 // We are currently terminating this browser, don't start a new test. | 663 // We are currently terminating this browser, don't start a new test. |
| 659 if (status.timeout) return null; | 664 if (status.timeout) return null; |
| 660 BrowserTest test = testQueue.removeLast(); | 665 BrowserTest test = testQueue.removeLast(); |
| 661 if (status.currentTest == null) { | 666 if (status.currentTest == null) { |
| 662 status.currentTest = test; | 667 status.currentTest = test; |
| 663 } else { | 668 } else { |
| 664 // TODO(ricow): Handle this better. | 669 // TODO(ricow): Handle this better. |
| 665 print("This is bad, should never happen, getNextTest all full"); | 670 print("This is bad, should never happen, getNextTest all full"); |
| 666 print("This happened for browser $browserId"); | 671 print("This happened for browser $browserId"); |
| 667 print("Old test was: ${status.currentTest.url}"); | 672 print("Old test was: ${status.currentTest.url}"); |
| 668 print("Timed out tests:"); | 673 print("Timed out tests:"); |
| 669 for (var v in timedOut) { | 674 for (var v in timedOut) { |
| 670 print(" $v"); | 675 print(" $v"); |
| 671 } | 676 } |
| 672 exit(1); | 677 exit(1); |
| 673 } | 678 } |
| 674 Timer timer = new Timer(new Duration(seconds: test.timeout), | 679 Timer timer = new Timer(new Duration(seconds: test.timeout), |
| 675 () { handleTimeout(status); }); | 680 () { handleTimeout(status); }); |
| 676 status.currentTest.timeoutTimer = timer; | 681 status.currentTest.timeoutTimer = timer; |
| 682 status.currentTest.stopwatch = new Stopwatch()..start(); |
| 677 return test; | 683 return test; |
| 678 } | 684 } |
| 679 | 685 |
| 680 void queueTest(BrowserTest test) { | 686 void queueTest(BrowserTest test) { |
| 681 testQueue.add(test); | 687 testQueue.add(test); |
| 682 } | 688 } |
| 683 | 689 |
| 684 void printDoubleReportingTests() { | 690 void printDoubleReportingTests() { |
| 685 if (doubleReportingTests.length == 0) return; | 691 if (doubleReportingTests.length == 0) return; |
| 686 // TODO(ricow): die on double reporting. | 692 // TODO(ricow): die on double reporting. |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 </head> | 936 </head> |
| 931 <body onload="startTesting()"> | 937 <body onload="startTesting()"> |
| 932 Dart test driver, number of tests: <div id="number"></div> | 938 Dart test driver, number of tests: <div id="number"></div> |
| 933 <iframe id="embedded_iframe"></iframe> | 939 <iframe id="embedded_iframe"></iframe> |
| 934 </body> | 940 </body> |
| 935 </html> | 941 </html> |
| 936 """; | 942 """; |
| 937 return driverContent; | 943 return driverContent; |
| 938 } | 944 } |
| 939 } | 945 } |
| OLD | NEW |