| 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 | 10 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 return Future.wait(futures).then((values) { | 484 return Future.wait(futures).then((values) { |
| 485 testingServer.httpServer.close(); | 485 testingServer.httpServer.close(); |
| 486 printDoubleReportingTests(); | 486 printDoubleReportingTests(); |
| 487 return !values.contains(false); | 487 return !values.contains(false); |
| 488 }); | 488 }); |
| 489 } | 489 } |
| 490 | 490 |
| 491 Browser getInstance() { | 491 Browser getInstance() { |
| 492 if (browserName == "chrome") { | 492 if (browserName == "chrome") { |
| 493 return new Chrome(); | 493 return new Chrome(); |
| 494 } else if (browserName == "firefox") { | 494 } else if (browserName == "ff") { |
| 495 return new Firefox(); | 495 return new Firefox(); |
| 496 } | 496 } |
| 497 throw "Non supported browser for browser controller"; | 497 throw "Non supported browser for browser controller"; |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 | 500 |
| 501 class BrowserTestingServer { | 501 class BrowserTestingServer { |
| 502 const String server = "127.0.0.1"; | 502 const String server = "127.0.0.1"; |
| 503 | 503 |
| 504 /// Interface of the testing server: | 504 /// Interface of the testing server: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 return "http://$server:${httpServer.port}/driver/$browserId"; | 603 return "http://$server:${httpServer.port}/driver/$browserId"; |
| 604 } | 604 } |
| 605 | 605 |
| 606 | 606 |
| 607 String getDriverPage(String browserId) { | 607 String getDriverPage(String browserId) { |
| 608 String driverContent = """ | 608 String driverContent = """ |
| 609 <!DOCTYPE html><html> | 609 <!DOCTYPE html><html> |
| 610 <head> | 610 <head> |
| 611 <title>Driving page</title> | 611 <title>Driving page</title> |
| 612 <script type='text/javascript'> | 612 <script type='text/javascript'> |
| 613 var numberOfTests = 0; | 613 var number_of_tests = 0; |
| 614 var currentId; | 614 var current_id; |
| 615 var testing_window; | 615 var testing_window; |
| 616 var last_reported_id; |
| 616 | 617 |
| 617 function newTaskHandler() { | 618 function newTaskHandler() { |
| 618 if (this.readyState == this.DONE) { | 619 if (this.readyState == this.DONE) { |
| 619 if (this.status == 200) { | 620 if (this.status == 200) { |
| 620 if (this.responseText == '$waitSignal') { | 621 if (this.responseText == '$waitSignal') { |
| 621 setTimeout(getNextTask, 500); | 622 setTimeout(getNextTask, 500); |
| 622 } else if (this.responseText == '$terminateSignal') { | 623 } else if (this.responseText == '$terminateSignal') { |
| 623 // Don't do anything, we will be killed shortly. | 624 // Don't do anything, we will be killed shortly. |
| 624 } else { | 625 } else { |
| 625 // TODO(ricow): Do something more clever here. | 626 // TODO(ricow): Do something more clever here. |
| 626 if (nextTask != undefined) alert('This is really bad'); | 627 if (nextTask != undefined) alert('This is really bad'); |
| 627 // The task is send to us as: | 628 // The task is send to us as: |
| 628 // URL#ID | 629 // URL#ID |
| 629 var split = this.responseText.split('#'); | 630 var split = this.responseText.split('#'); |
| 630 var nextTask = split[0]; | 631 var nextTask = split[0]; |
| 631 id = split[1]; | 632 current_id = split[1]; |
| 632 run(nextTask); | 633 run(nextTask); |
| 633 } | 634 } |
| 634 } else { | 635 } else { |
| 635 // We are basically in trouble - do something clever. | 636 // We are basically in trouble - do something clever. |
| 636 } | 637 } |
| 637 } | 638 } |
| 638 } | 639 } |
| 639 | 640 |
| 640 function getNextTask() { | 641 function getNextTask() { |
| 641 var client = new XMLHttpRequest(); | 642 var client = new XMLHttpRequest(); |
| 642 client.onreadystatechange = newTaskHandler; | 643 client.onreadystatechange = newTaskHandler; |
| 643 client.open('GET', '$nextTestPath/$browserId'); | 644 client.open('GET', '$nextTestPath/$browserId'); |
| 644 client.send(); | 645 client.send(); |
| 645 } | 646 } |
| 646 | 647 |
| 647 function run(url) { | 648 function run(url) { |
| 648 numberOfTests++; | 649 number_of_tests++; |
| 649 document.getElementById('number').innerHTML = numberOfTests; | 650 document.getElementById('number').innerHTML = number_of_tests; |
| 650 if (testing_window == undefined) { | 651 if (testing_window == undefined) { |
| 651 testing_window = window.open(url); | 652 testing_window = window.open(url); |
| 652 } else { | 653 } else { |
| 653 testing_window.location = url; | 654 testing_window.location = url; |
| 654 } | 655 } |
| 655 } | 656 } |
| 656 | 657 |
| 657 function reportMessage(msg) { | 658 function reportMessage(msg) { |
| 658 var client = new XMLHttpRequest(); | 659 var client = new XMLHttpRequest(); |
| 659 function handleReady() { | 660 function handleReady() { |
| 660 if (this.readyState == this.DONE) { | 661 if (this.readyState == this.DONE) { |
| 661 getNextTask(); | 662 if (current_id != last_reported_id) { |
| 663 getNextTask(); |
| 664 last_reported_id = current_id; |
| 665 } |
| 662 } | 666 } |
| 663 } | 667 } |
| 664 client.onreadystatechange = handleReady; | 668 client.onreadystatechange = handleReady; |
| 665 client.open('POST', '$reportPath/${browserId}?id=' + id); | 669 client.open('POST', '$reportPath/${browserId}?id=' + current_id); |
| 666 client.setRequestHeader('Content-type', | 670 client.setRequestHeader('Content-type', |
| 667 'application/x-www-form-urlencoded'); | 671 'application/x-www-form-urlencoded'); |
| 668 client.send(msg); | 672 client.send(msg); |
| 669 // TODO(ricow) add error handling to somehow report the fact that | 673 // TODO(ricow) add error handling to somehow report the fact that |
| 670 // we could not send back a result. | 674 // we could not send back a result. |
| 671 } | 675 } |
| 672 | 676 |
| 673 function messageHandler(e) { | 677 function messageHandler(e) { |
| 674 var msg = e.data; | 678 var msg = e.data; |
| 675 if (typeof msg != 'string') return; | 679 if (typeof msg != 'string') return; |
| 676 reportMessage(msg); | 680 reportMessage(msg); |
| 677 } | 681 } |
| 678 | 682 |
| 679 window.addEventListener('message', messageHandler, false); | 683 window.addEventListener('message', messageHandler, false); |
| 680 waitForDone = false; | 684 waitForDone = false; |
| 681 | 685 |
| 682 getNextTask(); | 686 getNextTask(); |
| 683 | 687 |
| 684 </script> | 688 </script> |
| 685 </head> | 689 </head> |
| 686 <body> | 690 <body> |
| 687 Dart test driver, number of tests: <div id="number"></div> | 691 Dart test driver, number of tests: <div id="number"></div> |
| 688 </body> | 692 </body> |
| 689 </html> | 693 </html> |
| 690 """; | 694 """; |
| 691 return driverContent; | 695 return driverContent; |
| 692 } | 696 } |
| 693 } | 697 } |
| OLD | NEW |