Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: tools/testing/dart/browser_controller.dart

Issue 15742006: Update browser controller and unittest lib to use start marker to figure out when to start new test… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 _processClosed = () { 96 _processClosed = () {
97 timer.cancel(); 97 timer.cancel();
98 _logEvent("Proccess exited, cancel timer in kill loop"); 98 _logEvent("Proccess exited, cancel timer in kill loop");
99 _processClosed = null; 99 _processClosed = null;
100 process = null; 100 process = null;
101 completer.complete(true); 101 completer.complete(true);
102 }; 102 };
103 103
104 104
105 _logEvent("calling kill function"); 105 _logEvent("calling kill function");
106 if (killFunction()) { 106 if (process != null && killFunction()) {
107 // We successfully sent the signal. 107 // We successfully sent the signal.
108 _logEvent("killing signal sent"); 108 _logEvent("killing signal sent");
109 } else { 109 } else {
110 _logEvent("The process is already dead, kill signal could not be send"); 110 _logEvent("The process is already dead, kill signal could not be send");
111 completer.complete(true); 111 completer.complete(true);
112 } 112 }
113 return completer.future; 113 return completer.future;
114 } 114 }
115 115
116 116
(...skipping 16 matching lines...) Expand all
133 * This sets up the error handling and usage logging. 133 * This sets up the error handling and usage logging.
134 */ 134 */
135 Future<bool> startBrowser(String command, List<String> arguments) { 135 Future<bool> startBrowser(String command, List<String> arguments) {
136 return Process.start(command, arguments).then((startedProcess) { 136 return Process.start(command, arguments).then((startedProcess) {
137 process = startedProcess; 137 process = startedProcess;
138 process.stdout.transform(new StringDecoder()).listen((data) { 138 process.stdout.transform(new StringDecoder()).listen((data) {
139 _addStdout(data); 139 _addStdout(data);
140 }, onError: (error) { 140 }, onError: (error) {
141 // This should _never_ happen, but we really want this in the log 141 // This should _never_ happen, but we really want this in the log
142 // if it actually does due to dart:io or vm bug. 142 // if it actually does due to dart:io or vm bug.
143 _usageLog.add( 143 _logEvent("An error occured in the process stdout handling: $error");
144 "An error occured in the process stdout handling: $error");
145 }); 144 });
146 145
147 process.stderr.transform(new StringDecoder()).listen((data) { 146 process.stderr.transform(new StringDecoder()).listen((data) {
148 _addStderr(data); 147 _addStderr(data);
149 }, onError: (error) { 148 }, onError: (error) {
150 // This should _never_ happen, but we really want this in the log 149 // This should _never_ happen, but we really want this in the log
151 // if it actually does due to dart:io or vm bug. 150 // if it actually does due to dart:io or vm bug.
152 _usageLog.add( 151 _logEvent("An error occured in the process stderr handling: $error");
153 "An error occured in the process stderr handling: $error");
154 }); 152 });
155 153
156 process.exitCode.then((exitCode) { 154 process.exitCode.then((exitCode) {
157 _logEvent("Browser closed with exitcode $exitCode"); 155 _logEvent("Browser closed with exitcode $exitCode");
158 if (_processClosed != null) _processClosed(); 156 if (_processClosed != null) _processClosed();
159 if (_cleanup != null) _cleanup(); 157 if (_cleanup != null) _cleanup();
160 if (onClose != null) onClose(exitCode); 158 if (onClose != null) onClose(exitCode);
161 }); 159 });
162 return true; 160 return true;
163 }).catchError((error) { 161 }).catchError((error) {
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 printDoubleReportingTests(); 484 printDoubleReportingTests();
487 return !values.contains(false); 485 return !values.contains(false);
488 }); 486 });
489 } 487 }
490 488
491 Browser getInstance() { 489 Browser getInstance() {
492 if (browserName == "chrome") { 490 if (browserName == "chrome") {
493 return new Chrome(); 491 return new Chrome();
494 } else if (browserName == "ff") { 492 } else if (browserName == "ff") {
495 return new Firefox(); 493 return new Firefox();
494 } else {
495 throw "Non supported browser for browser controller";
496 } 496 }
497 throw "Non supported browser for browser controller";
498 } 497 }
499 } 498 }
500 499
501 class BrowserTestingServer { 500 class BrowserTestingServer {
502 const String server = "127.0.0.1"; 501 const String server = "127.0.0.1";
503 502
504 /// Interface of the testing server: 503 /// Interface of the testing server:
505 /// 504 ///
506 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch 505 /// GET /driver/BROWSER_ID -- This will get the driver page to fetch
507 /// and run tests ... 506 /// and run tests ...
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 String getDriverPage(String browserId) { 606 String getDriverPage(String browserId) {
608 String driverContent = """ 607 String driverContent = """
609 <!DOCTYPE html><html> 608 <!DOCTYPE html><html>
610 <head> 609 <head>
611 <title>Driving page</title> 610 <title>Driving page</title>
612 <script type='text/javascript'> 611 <script type='text/javascript'>
613 var number_of_tests = 0; 612 var number_of_tests = 0;
614 var current_id; 613 var current_id;
615 var testing_window; 614 var testing_window;
616 var last_reported_id; 615 var last_reported_id;
616 // We use this to determine if we did actually get back a start event
617 // from the test we just loaded.
618 var did_start = false;
kustermann 2013/05/22 17:08:50 I think you're on an old revision. Could you rebas
ricow1 2013/05/22 17:36:12 did not know that landed, done
617 619
618 function newTaskHandler() { 620 function newTaskHandler() {
619 if (this.readyState == this.DONE) { 621 if (this.readyState == this.DONE) {
620 if (this.status == 200) { 622 if (this.status == 200) {
621 if (this.responseText == '$waitSignal') { 623 if (this.responseText == '$waitSignal') {
622 setTimeout(getNextTask, 500); 624 setTimeout(getNextTask, 500);
623 } else if (this.responseText == '$terminateSignal') { 625 } else if (this.responseText == '$terminateSignal') {
624 // Don't do anything, we will be killed shortly. 626 // Don't do anything, we will be killed shortly.
625 } else { 627 } else {
626 // TODO(ricow): Do something more clever here. 628 // TODO(ricow): Do something more clever here.
627 if (nextTask != undefined) alert('This is really bad'); 629 if (nextTask != undefined) alert('This is really bad');
628 // The task is send to us as: 630 // The task is send to us as:
629 // URL#ID 631 // URL#ID
630 var split = this.responseText.split('#'); 632 var split = this.responseText.split('#');
631 var nextTask = split[0]; 633 var nextTask = split[0];
632 current_id = split[1]; 634 current_id = split[1];
635 did_start = false;
633 run(nextTask); 636 run(nextTask);
634 } 637 }
635 } else { 638 } else {
636 // We are basically in trouble - do something clever. 639 // We are basically in trouble - do something clever.
637 } 640 }
638 } 641 }
639 } 642 }
640 643
641 function getNextTask() { 644 function getNextTask() {
642 var client = new XMLHttpRequest(); 645 var client = new XMLHttpRequest();
643 client.onreadystatechange = newTaskHandler; 646 client.onreadystatechange = newTaskHandler;
644 client.open('GET', '$nextTestPath/$browserId'); 647 client.open('GET', '$nextTestPath/$browserId');
645 client.send(); 648 client.send();
646 } 649 }
647 650
648 function run(url) { 651 function run(url) {
649 number_of_tests++; 652 number_of_tests++;
650 document.getElementById('number').innerHTML = number_of_tests; 653 document.getElementById('number').innerHTML = number_of_tests;
651 if (testing_window == undefined) { 654 if (testing_window == undefined) {
652 testing_window = window.open(url); 655 testing_window = window.open(url);
653 } else { 656 } else {
654 testing_window.location = url; 657 testing_window.location = url;
655 } 658 }
656 } 659 }
657 660
658 function reportMessage(msg) { 661 function reportMessage(msg) {
662 if (msg == 'STARTING') {
663 did_start = true;
664 return;
665 }
659 var client = new XMLHttpRequest(); 666 var client = new XMLHttpRequest();
660 function handleReady() { 667 function handleReady() {
661 if (this.readyState == this.DONE) { 668 if (this.readyState == this.DONE) {
662 if (current_id != last_reported_id) { 669 if (last_reported_id != current_id && did_start) {
663 getNextTask(); 670 getNextTask();
664 last_reported_id = current_id; 671 last_reported_id = current_id;
665 } 672 }
666 } 673 }
667 } 674 }
668 client.onreadystatechange = handleReady; 675 client.onreadystatechange = handleReady;
669 client.open('POST', '$reportPath/${browserId}?id=' + current_id); 676 // If did_start is false it means that we did actually set the url on
677 // the testing_window, but this is a report left in the event loop or
678 // a callback because the page did not load yet.
679 // In both cases this is a double report from the last test.
680 var posting_id = did_start ? current_id : last_reported_id;
681 client.open('POST', '$reportPath/${browserId}?id=' + posting_id);
670 client.setRequestHeader('Content-type', 682 client.setRequestHeader('Content-type',
671 'application/x-www-form-urlencoded'); 683 'application/x-www-form-urlencoded');
672 client.send(msg); 684 client.send(msg);
673 // TODO(ricow) add error handling to somehow report the fact that 685 // TODO(ricow) add error handling to somehow report the fact that
674 // we could not send back a result. 686 // we could not send back a result.
675 } 687 }
676 688
677 function messageHandler(e) { 689 function messageHandler(e) {
678 var msg = e.data; 690 var msg = e.data;
679 if (typeof msg != 'string') return; 691 if (typeof msg != 'string') return;
680 reportMessage(msg); 692 reportMessage(msg);
681 } 693 }
682 694
683 window.addEventListener('message', messageHandler, false); 695 window.addEventListener('message', messageHandler, false);
684 waitForDone = false; 696 waitForDone = false;
685 697
686 getNextTask(); 698 getNextTask();
687 699
688 </script> 700 </script>
689 </head> 701 </head>
690 <body> 702 <body>
691 Dart test driver, number of tests: <div id="number"></div> 703 Dart test driver, number of tests: <div id="number"></div>
692 </body> 704 </body>
693 </html> 705 </html>
694 """; 706 """;
695 return driverContent; 707 return driverContent;
696 } 708 }
697 } 709 }
OLDNEW
« pkg/unittest/lib/test_controller.js ('K') | « pkg/unittest/lib/test_controller.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698