Debian Codegraph @

closure-library/closure/goog/testing/multitestrunner.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Utility for running multiple test files that utilize the same
17 * interface as goog.testing.TestRunner. Each test is run in series and their
18 * results aggregated. The main usecase for the MultiTestRunner is to allow
19 * the testing of all tests in a project locally.
20 *
21 */
22
23 goog.setTestOnly('goog.testing.MultiTestRunner');
24 goog.provide('goog.testing.MultiTestRunner');
25 goog.provide('goog.testing.MultiTestRunner.TestFrame');
26
27 goog.require('goog.Timer');
28 goog.require('goog.array');
29 goog.require('goog.asserts');
30 goog.require('goog.dom');
31 goog.require('goog.dom.TagName');
32 goog.require('goog.dom.classlist');
33 goog.require('goog.events.EventHandler');
34 goog.require('goog.functions');
35 goog.require('goog.object');
36 goog.require('goog.string');
37 goog.require('goog.testing.TestCase');
38 goog.require('goog.ui.Component');
39 goog.require('goog.ui.ServerChart');
40 goog.require('goog.ui.TableSorter');
41
42
43
44 /**
45 * A component for running multiple tests within the browser.
46 * @param {goog.dom.DomHelper=} opt_domHelper A DOM helper.
47 * @extends {goog.ui.Component}
48 * @constructor
49 * @final
50 */
51 goog.testing.MultiTestRunner = function(opt_domHelper) {
52 goog.ui.Component.call(this, opt_domHelper);
53
54 /**
55 * Array of tests to execute, when combined with the base path this should be
56 * a relative path to the test from the page containing the multi testrunner.
57 * @type {Array<string>}
58 * @private
59 */
60 this.allTests_ = [];
61
62 /**
63 * Tests that match the filter function.
64 * @type {Array<string>}
65 * @private
66 */
67 this.activeTests_ = [];
68
69 /**
70 * An event handler for handling events.
71 * @type {goog.events.EventHandler<!goog.testing.MultiTestRunner>}
72 * @private
73 */
74 this.eh_ = new goog.events.EventHandler(this);
75
76 /**
77 * A table sorter for the stats.
78 * @type {goog.ui.TableSorter}
79 * @private
80 */
81 this.tableSorter_ = new goog.ui.TableSorter(this.dom_);
82
83 /**
84 * Array to hold individual test reports for tests that failed.
85 * @type {!Array<!string>}
86 * @private
87 */
88 this.failureReports_ = [];
89
90 /**
91 * Array of test result objects returned from G_testRunner.getTestResults for
92 * each individual test run.
93 * @private {!Array<!Object<string,!Array<!goog.testing.TestCase.IResult>>>}
94 */
95 this.allTestResults_ = [];
96 };
97 goog.inherits(goog.testing.MultiTestRunner, goog.ui.Component);
98
99
100 /**
101 * Default maximimum amount of time to spend at each stage of the test.
102 * @type {number}
103 */
104 goog.testing.MultiTestRunner.DEFAULT_TIMEOUT_MS = 45 * 1000;
105
106
107 /**
108 * Messages corresponding to the numeric states.
109 * @type {Array<string>}
110 */
111 goog.testing.MultiTestRunner.STATES = [
112 'waiting for test runner', 'initializing tests', 'waiting for tests to finish'
113 ];
114
115
116 /**
117 * Event type dispatched when tests are completed.
118 * @const
119 */
120 goog.testing.MultiTestRunner.TESTS_FINISHED = 'testsFinished';
121
122
123 /**
124 * The test suite's name.
125 * @type {string} name
126 * @private
127 */
128 goog.testing.MultiTestRunner.prototype.name_ = '';
129
130
131 /**
132 * The base path used to resolve files within the allTests_ array.
133 * @type {string}
134 * @private
135 */
136 goog.testing.MultiTestRunner.prototype.basePath_ = '';
137
138
139 /**
140 * A set of tests that have finished. All extant keys map to true.
141 * @type {Object<boolean>}
142 * @private
143 */
144 goog.testing.MultiTestRunner.prototype.finished_ = null;
145
146
147 /**
148 * Whether the report should contain verbose information about the passes.
149 * @type {boolean}
150 * @private
151 */
152 goog.testing.MultiTestRunner.prototype.verbosePasses_ = false;
153
154
155 /**
156 * Whether to hide passing tests completely in the report, makes verbosePasses_
157 * obsolete.
158 * @type {boolean}
159 * @private
160 */
161 goog.testing.MultiTestRunner.prototype.hidePasses_ = false;
162
163
164 /**
165 * Flag used to tell the test runner to stop after the current test.
166 * @type {boolean}
167 * @private
168 */
169 goog.testing.MultiTestRunner.prototype.stopped_ = false;
170
171
172 /**
173 * Flag indicating whether the test runner is active.
174 * @type {boolean}
175 * @private
176 */
177 goog.testing.MultiTestRunner.prototype.active_ = false;
178
179
180 /**
181 * Index of the next test to run.
182 * @type {number}
183 * @private
184 */
185 goog.testing.MultiTestRunner.prototype.startedCount_ = 0;
186
187
188 /**
189 * Count of the results received so far.
190 * @type {number}
191 * @private
192 */
193 goog.testing.MultiTestRunner.prototype.resultCount_ = 0;
194
195
196 /**
197 * Number of passes so far.
198 * @type {number}
199 * @private
200 */
201 goog.testing.MultiTestRunner.prototype.passes_ = 0;
202
203
204 /**
205 * Timestamp for the current start time.
206 * @type {number}
207 * @private
208 */
209 goog.testing.MultiTestRunner.prototype.startTime_ = 0;
210
211
212 /**
213 * Only tests whose paths patch this filter function will be
214 * executed.
215 * @type {function(string): boolean}
216 * @private
217 */
218 goog.testing.MultiTestRunner.prototype.filterFn_ = goog.functions.TRUE;
219
220
221 /**
222 * Number of milliseconds to wait for loading and initialization steps.
223 * @type {number}
224 * @private
225 */
226 goog.testing.MultiTestRunner.prototype.timeoutMs_ =
227 goog.testing.MultiTestRunner.DEFAULT_TIMEOUT_MS;
228
229
230 /**
231 * An array of objects containing stats about the tests.
232 * @type {Array<Object>?}
233 * @private
234 */
235 goog.testing.MultiTestRunner.prototype.stats_ = null;
236
237
238 /**
239 * Reference to the start button element.
240 * @type {Element}
241 * @private
242 */
243 goog.testing.MultiTestRunner.prototype.startButtonEl_ = null;
244
245
246 /**
247 * Reference to the stop button element.
248 * @type {Element}
249 * @private
250 */
251 goog.testing.MultiTestRunner.prototype.stopButtonEl_ = null;
252
253
254 /**
255 * Reference to the log element.
256 * @type {Element}
257 * @private
258 */
259 goog.testing.MultiTestRunner.prototype.logEl_ = null;
260
261
262 /**
263 * Reference to the report element.
264 * @type {Element}
265 * @private
266 */
267 goog.testing.MultiTestRunner.prototype.reportEl_ = null;
268
269
270 /**
271 * Reference to the stats element.
272 * @type {Element}
273 * @private
274 */
275 goog.testing.MultiTestRunner.prototype.statsEl_ = null;
276
277
278 /**
279 * Reference to the progress bar's element.
280 * @type {Element}
281 * @private
282 */
283 goog.testing.MultiTestRunner.prototype.progressEl_ = null;
284
285
286 /**
287 * Reference to the progress bar's inner row element.
288 * @type {Element}
289 * @private
290 */
291 goog.testing.MultiTestRunner.prototype.progressRow_ = null;
292
293
294 /**
295 * Reference to the log tab.
296 * @type {Element}
297 * @private
298 */
299 goog.testing.MultiTestRunner.prototype.logTabEl_ = null;
300
301
302 /**
303 * Reference to the report tab.
304 * @type {Element}
305 * @private
306 */
307 goog.testing.MultiTestRunner.prototype.reportTabEl_ = null;
308
309
310 /**
311 * Reference to the stats tab.
312 * @type {Element}
313 * @private
314 */
315 goog.testing.MultiTestRunner.prototype.statsTabEl_ = null;
316
317
318 /**
319 * The number of tests to run at a time.
320 * @type {number}
321 * @private
322 */
323 goog.testing.MultiTestRunner.prototype.poolSize_ = 1;
324
325
326 /**
327 * The size of the stats bucket for the number of files loaded histogram.
328 * @type {number}
329 * @private
330 */
331 goog.testing.MultiTestRunner.prototype.numFilesStatsBucketSize_ = 20;
332
333
334 /**
335 * The size of the stats bucket in ms for the run time histogram.
336 * @type {number}
337 * @private
338 */
339 goog.testing.MultiTestRunner.prototype.runTimeStatsBucketSize_ = 500;
340
341
342 /**
343 * Sets the name for the test suite.
344 * @param {string} name The suite's name.
345 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
346 */
347 goog.testing.MultiTestRunner.prototype.setName = function(name) {
348 this.name_ = name;
349 return this;
350 };
351
352
353 /**
354 * Returns the name for the test suite.
355 * @return {string} The name for the test suite.
356 */
357 goog.testing.MultiTestRunner.prototype.getName = function() {
358 return this.name_;
359 };
360
361
362 /**
363 * Sets the basepath that tests added using addTests are resolved with.
364 * @param {string} path The relative basepath.
365 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
366 */
367 goog.testing.MultiTestRunner.prototype.setBasePath = function(path) {
368 this.basePath_ = path;
369 return this;
370 };
371
372
373 /**
374 * Returns the basepath that tests added using addTests are resolved with.
375 * @return {string} The basepath that tests added using addTests are resolved
376 * with.
377 */
378 goog.testing.MultiTestRunner.prototype.getBasePath = function() {
379 return this.basePath_;
380 };
381
382
383 /**
384 * Sets whether the report should contain verbose information for tests that
385 * pass.
386 * @param {boolean} verbose Whether report should be verbose.
387 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
388 */
389 goog.testing.MultiTestRunner.prototype.setVerbosePasses = function(verbose) {
390 this.verbosePasses_ = verbose;
391 return this;
392 };
393
394
395 /**
396 * Returns whether the report should contain verbose information for tests that
397 * pass.
398 * @return {boolean} Whether the report should contain verbose information for
399 * tests that pass.
400 */
401 goog.testing.MultiTestRunner.prototype.getVerbosePasses = function() {
402 return this.verbosePasses_;
403 };
404
405
406 /**
407 * Sets whether the report should contain passing tests at all, makes
408 * setVerbosePasses obsolete.
409 * @param {boolean} hide Whether report should not contain passing tests.
410 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
411 */
412 goog.testing.MultiTestRunner.prototype.setHidePasses = function(hide) {
413 this.hidePasses_ = hide;
414 return this;
415 };
416
417
418 /**
419 * Returns whether the report should contain passing tests at all, makes
420 * setVerbosePasses obsolete.
421 * @return {boolean} Whether the report should contain passing tests at all,
422 * makes setVerbosePasses obsolete.
423 */
424 goog.testing.MultiTestRunner.prototype.getHidePasses = function() {
425 return this.hidePasses_;
426 };
427
428
429 /**
430 * Sets the bucket sizes for the histograms.
431 * @param {number} f Bucket size for num files loaded histogram.
432 * @param {number} t Bucket size for run time histogram.
433 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
434 */
435 goog.testing.MultiTestRunner.prototype.setStatsBucketSizes = function(f, t) {
436 this.numFilesStatsBucketSize_ = f;
437 this.runTimeStatsBucketSize_ = t;
438 return this;
439 };
440
441
442 /**
443 * Sets the number of milliseconds to wait for the page to load, initialize and
444 * run the tests.
445 * @param {number} timeout Time in milliseconds.
446 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
447 */
448 goog.testing.MultiTestRunner.prototype.setTimeout = function(timeout) {
449 this.timeoutMs_ = timeout;
450 return this;
451 };
452
453
454 /**
455 * Returns the number of milliseconds to wait for the page to load, initialize
456 * and run the tests.
457 * @return {number} The number of milliseconds to wait for the page to load,
458 * initialize and run the tests.
459 */
460 goog.testing.MultiTestRunner.prototype.getTimeout = function() {
461 return this.timeoutMs_;
462 };
463
464
465 /**
466 * Sets the number of tests that can be run at the same time. This only improves
467 * performance due to the amount of time spent loading the tests.
468 * @param {number} size The number of tests to run at a time.
469 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
470 */
471 goog.testing.MultiTestRunner.prototype.setPoolSize = function(size) {
472 this.poolSize_ = size;
473 return this;
474 };
475
476
477 /**
478 * Returns the number of tests that can be run at the same time. This only
479 * improves performance due to the amount of time spent loading the tests.
480 * @return {number} The number of tests that can be run at the same time. This
481 * only improves performance due to the amount of time spent loading the
482 * tests.
483 */
484 goog.testing.MultiTestRunner.prototype.getPoolSize = function() {
485 return this.poolSize_;
486 };
487
488
489 /**
490 * Sets a filter function. Only test paths that match the filter function
491 * will be executed.
492 * @param {function(string): boolean} filterFn Filters test paths.
493 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
494 */
495 goog.testing.MultiTestRunner.prototype.setFilterFunction = function(filterFn) {
496 this.filterFn_ = filterFn;
497 return this;
498 };
499
500
501 /**
502 * Returns a filter function. Only test paths that match the filter function
503 * will be executed.
504 * @return {function(string): boolean} A filter function. Only test paths that
505 * match the filter function will be executed.
506
507 */
508 goog.testing.MultiTestRunner.prototype.getFilterFunction = function() {
509 return this.filterFn_;
510 };
511
512
513 /**
514 * Adds an array of tests to the tests that the test runner should execute.
515 * @param {Array<string>} tests Adds tests to the test runner.
516 * @return {!goog.testing.MultiTestRunner} Instance for chaining.
517 */
518 goog.testing.MultiTestRunner.prototype.addTests = function(tests) {
519 goog.array.extend(this.allTests_, tests);
520 return this;
521 };
522
523
524 /**
525 * Returns the list of all tests added to the runner.
526 * @return {Array<string>} The list of all tests added to the runner.
527 */
528 goog.testing.MultiTestRunner.prototype.getAllTests = function() {
529 return this.allTests_;
530 };
531
532
533 /**
534 * Returns the list of tests that will be run when start() is called.
535 * @return {!Array<string>} The list of tests that will be run when start() is
536 * called.
537 */
538 goog.testing.MultiTestRunner.prototype.getTestsToRun = function() {
539 return goog.array.filter(this.allTests_, this.filterFn_);
540 };
541
542
543 /**
544 * Returns a list of tests from runner that have been marked as failed.
545 * @return {!Array<string>} A list of tests from runner that have been marked
546 * as failed.
547 */
548 goog.testing.MultiTestRunner.prototype.getTestsThatFailed = function() {
549 var stats = this.stats_;
550 var failedTests = [];
551 if (stats) {
552 for (var i = 0, stat; stat = stats[i]; i++) {
553 if (!stat.success) {
554 failedTests.push(stat.testFile);
555 }
556 }
557 }
558 return failedTests;
559 };
560
561
562 /**
563 * Returns a list of reports for tests that have finished since last "start".
564 * @return {!Array<string>} A list of tests reports.
565 */
566 goog.testing.MultiTestRunner.prototype.getFailureReports = function() {
567 return this.failureReports_;
568 };
569
570
571 /**
572 * Returns list of each frame's test results.
573 * @return {!Array<!Object<string,!Array<!goog.testing.TestCase.IResult>>>}
574 */
575 goog.testing.MultiTestRunner.prototype.getAllTestResults = function() {
576 return this.allTestResults_;
577 };
578
579
580 /**
581 * Deletes and re-creates the progress table inside the progess element.
582 * @private
583 */
584 goog.testing.MultiTestRunner.prototype.resetProgressDom_ = function() {
585 goog.dom.removeChildren(this.progressEl_);
586 var progressTable = this.dom_.createDom(goog.dom.TagName.TABLE);
587 var progressTBody = this.dom_.createDom(goog.dom.TagName.TBODY);
588 this.progressRow_ = this.dom_.createDom(goog.dom.TagName.TR);
589 for (var i = 0; i < this.activeTests_.length; i++) {
590 var progressCell = this.dom_.createDom(goog.dom.TagName.TD);
591 this.progressRow_.appendChild(progressCell);
592 }
593 progressTBody.appendChild(this.progressRow_);
594 progressTable.appendChild(progressTBody);
595 this.progressEl_.appendChild(progressTable);
596 };
597
598
599 /** @override */
600 goog.testing.MultiTestRunner.prototype.createDom = function() {
601 goog.testing.MultiTestRunner.superClass_.createDom.call(this);
602 var el = this.getElement();
603 el.className = goog.getCssName('goog-testrunner');
604
605 this.progressEl_ = this.dom_.createDom(goog.dom.TagName.DIV);
606 this.progressEl_.className = goog.getCssName('goog-testrunner-progress');
607 el.appendChild(this.progressEl_);
608
609 var buttons = this.dom_.createDom(goog.dom.TagName.DIV);
610 buttons.className = goog.getCssName('goog-testrunner-buttons');
611 this.startButtonEl_ =
612 this.dom_.createDom(goog.dom.TagName.BUTTON, null, 'Start');
613 this.stopButtonEl_ =
614 this.dom_.createDom(goog.dom.TagName.BUTTON, {'disabled': true}, 'Stop');
615 buttons.appendChild(this.startButtonEl_);
616 buttons.appendChild(this.stopButtonEl_);
617 el.appendChild(buttons);
618
619 this.eh_.listen(this.startButtonEl_, 'click', this.onStartClicked_);
620 this.eh_.listen(this.stopButtonEl_, 'click', this.onStopClicked_);
621
622 this.logEl_ = this.dom_.createElement(goog.dom.TagName.DIV);
623 this.logEl_.className = goog.getCssName('goog-testrunner-log');
624 el.appendChild(this.logEl_);
625
626 this.reportEl_ = this.dom_.createElement(goog.dom.TagName.DIV);
627 this.reportEl_.className = goog.getCssName('goog-testrunner-report');
628 this.reportEl_.style.display = 'none';
629 el.appendChild(this.reportEl_);
630
631 this.statsEl_ = this.dom_.createElement(goog.dom.TagName.DIV);
632 this.statsEl_.className = goog.getCssName('goog-testrunner-stats');
633 this.statsEl_.style.display = 'none';
634 el.appendChild(this.statsEl_);
635
636 this.logTabEl_ = this.dom_.createDom(goog.dom.TagName.DIV, null, 'Log');
637 this.logTabEl_.className = goog.getCssName('goog-testrunner-logtab') + ' ' +
638 goog.getCssName('goog-testrunner-activetab');
639 el.appendChild(this.logTabEl_);
640
641 this.reportTabEl_ = this.dom_.createDom(goog.dom.TagName.DIV, null, 'Report');
642 this.reportTabEl_.className = goog.getCssName('goog-testrunner-reporttab');
643 el.appendChild(this.reportTabEl_);
644
645 this.statsTabEl_ = this.dom_.createDom(goog.dom.TagName.DIV, null, 'Stats');
646 this.statsTabEl_.className = goog.getCssName('goog-testrunner-statstab');
647 el.appendChild(this.statsTabEl_);
648
649 this.eh_.listen(this.logTabEl_, 'click', this.onLogTabClicked_);
650 this.eh_.listen(this.reportTabEl_, 'click', this.onReportTabClicked_);
651 this.eh_.listen(this.statsTabEl_, 'click', this.onStatsTabClicked_);
652
653 };
654
655
656 /** @override */
657 goog.testing.MultiTestRunner.prototype.disposeInternal = function() {
658 goog.testing.MultiTestRunner.superClass_.disposeInternal.call(this);
659 this.tableSorter_.dispose();
660 this.eh_.dispose();
661 this.startButtonEl_ = null;
662 this.stopButtonEl_ = null;
663 this.logEl_ = null;
664 this.reportEl_ = null;
665 this.progressEl_ = null;
666 this.logTabEl_ = null;
667 this.reportTabEl_ = null;
668 this.statsTabEl_ = null;
669 this.statsEl_ = null;
670 };
671
672
673 /**
674 * Starts executing the tests.
675 */
676 goog.testing.MultiTestRunner.prototype.start = function() {
677 this.startButtonEl_.disabled = true;
678 this.stopButtonEl_.disabled = false;
679 this.stopped_ = false;
680 this.active_ = true;
681 this.finished_ = {};
682 this.activeTests_ = this.getTestsToRun();
683 this.startedCount_ = 0;
684 this.resultCount_ = 0;
685 this.passes_ = 0;
686 this.stats_ = [];
687 this.startTime_ = goog.now();
688 this.failureReports_ = [];
689
690 this.resetProgressDom_();
691 goog.dom.removeChildren(this.logEl_);
692
693 this.resetReport_();
694 this.clearStats_();
695 this.showTab_(0);
696
697 // No tests to run, finish early and return.
698 if (this.activeTests_.length == 0) {
699 this.finish_();
700 return;
701 }
702
703 // Ensure the pool isn't too big.
704 while (this.getChildCount() > this.poolSize_) {
705 this.removeChildAt(0, true).dispose();
706 }
707
708 // Start a test in each runner.
709 for (var i = 0; i < this.poolSize_; i++) {
710 if (i >= this.getChildCount()) {
711 var testFrame = new goog.testing.MultiTestRunner.TestFrame(
712 this.basePath_, this.timeoutMs_, this.verbosePasses_, this.dom_);
713 this.addChild(testFrame, true);
714 }
715 this.runNextTest_(
716 /** @type {goog.testing.MultiTestRunner.TestFrame} */
717 (this.getChildAt(i)));
718 }
719 };
720
721
722 /**
723 * Logs a message to the log window.
724 * @param {string} msg A message to log.
725 */
726 goog.testing.MultiTestRunner.prototype.log = function(msg) {
727 if (msg != '.') {
728 msg = this.getTimeStamp_() + ' : ' + msg;
729 }
730
731 this.logEl_.appendChild(this.dom_.createDom(goog.dom.TagName.DIV, null, msg));
732
733 // Autoscroll if we're near the bottom.
734 var top = this.logEl_.scrollTop;
735 var height = /** @type {!HTMLElement} */ (this.logEl_).scrollHeight -
736 /** @type {!HTMLElement} */ (this.logEl_).offsetHeight;
737 if (top == 0 || top > height - 50) {
738 this.logEl_.scrollTop = height;
739 }
740 };
741
742
743 /**
744 * Processes a result returned from a TestFrame. If there are tests remaining
745 * it will trigger the next one to be run, otherwise if there are no tests and
746 * all results have been received then it will call finish.
747 * @param {goog.testing.MultiTestRunner.TestFrame} frame The frame that just
748 * finished.
749 */
750 goog.testing.MultiTestRunner.prototype.processResult = function(frame) {
751 var success = frame.isSuccess();
752 var report = frame.getReport();
753 var test = frame.getTestFile();
754 var stats = frame.getStats();
755
756 if (!stats.success) {
757 this.failureReports_.push(report);
758 }
759
760 this.allTestResults_.push(frame.getTestResults());
761 this.stats_.push(stats);
762 this.finished_[test] = true;
763
764 var prefix = success ? '' : '*** FAILURE *** ';
765 this.log(
766 prefix + this.trimFileName_(test) + ' : ' +
767 (success ? 'Passed' : 'Failed'));
768
769 this.resultCount_++;
770
771 if (success) {
772 this.passes_++;
773 }
774
775 this.drawProgressSegment_(test, success);
776 this.writeCurrentSummary_();
777 if (!(success && this.hidePasses_)) {
778 this.drawTestResult_(test, success, report);
779 }
780
781 if (!this.stopped_ && this.startedCount_ < this.activeTests_.length) {
782 this.runNextTest_(frame);
783 } else if (this.resultCount_ == this.activeTests_.length) {
784 this.finish_();
785 }
786 };
787
788
789 /**
790 * Runs the next available test, if there are any left.
791 * @param {goog.testing.MultiTestRunner.TestFrame} frame Where to run the test.
792 * @private
793 */
794 goog.testing.MultiTestRunner.prototype.runNextTest_ = function(frame) {
795 if (this.startedCount_ < this.activeTests_.length) {
796 var nextTest = this.activeTests_[this.startedCount_++];
797 this.log(this.trimFileName_(nextTest) + ' : Loading');
798 frame.runTest(nextTest);
799 }
800 };
801
802
803 /**
804 * Handles the test finishing, processing the results and rendering the report.
805 * @private
806 */
807 goog.testing.MultiTestRunner.prototype.finish_ = function() {
808 if (this.stopped_) {
809 this.log('Stopped');
810 } else {
811 this.log('Finished');
812 }
813
814 this.startButtonEl_.disabled = false;
815 this.stopButtonEl_.disabled = true;
816 this.active_ = false;
817
818 this.showTab_(1);
819 this.drawStats_();
820
821 // Remove all the test frames
822 while (this.getChildCount() > 0) {
823 this.removeChildAt(0, true).dispose();
824 }
825
826 // Compute tests that did not finish before the stop button was hit.
827 var unfinished = [];
828 for (var i = 0; i < this.activeTests_.length; i++) {
829 var test = this.activeTests_[i];
830 if (!this.finished_[test]) {
831 unfinished.push(test);
832 }
833 }
834
835 if (unfinished.length) {
836 this.reportEl_.appendChild(
837 goog.dom.createDom(
838 goog.dom.TagName.PRE, undefined,
839 'These tests did not finish:\n' + unfinished.join('\n')));
840 }
841
842 this.dispatchEvent({
843 'type': goog.testing.MultiTestRunner.TESTS_FINISHED,
844 'allTestResults': this.getAllTestResults()
845 });
846 };
847
848
849 /**
850 * Resets the report, clearing out all children and drawing the initial summary.
851 * @private
852 */
853 goog.testing.MultiTestRunner.prototype.resetReport_ = function() {
854 goog.dom.removeChildren(this.reportEl_);
855 var summary = this.dom_.createDom(goog.dom.TagName.DIV);
856 summary.className = goog.getCssName('goog-testrunner-progress-summary');
857 this.reportEl_.appendChild(summary);
858 this.writeCurrentSummary_();
859 };
860
861
862 /**
863 * Draws the stats for the test run.
864 * @private
865 */
866 goog.testing.MultiTestRunner.prototype.drawStats_ = function() {
867 this.drawFilesHistogram_();
868
869 // Only show time stats if pool size is 1, otherwise times are wrong.
870 if (this.poolSize_ == 1) {
871 this.drawRunTimePie_();
872 this.drawTimeHistogram_();
873 }
874
875 this.drawWorstTestsTable_();
876 };
877
878
879 /**
880 * Draws the histogram showing number of files loaded.
881 * @private
882 */
883 goog.testing.MultiTestRunner.prototype.drawFilesHistogram_ = function() {
884 this.drawStatsHistogram_(
885 'numFilesLoaded', this.numFilesStatsBucketSize_, goog.functions.identity,
886 500,
887 'Histogram showing distribution of\nnumber of files loaded per test');
888 };
889
890
891 /**
892 * Draws the histogram showing how long each test took to complete.
893 * @private
894 */
895 goog.testing.MultiTestRunner.prototype.drawTimeHistogram_ = function() {
896 this.drawStatsHistogram_(
897 'totalTime', this.runTimeStatsBucketSize_,
898 function(x) { return x / 1000; }, 500,
899 'Histogram showing distribution of\ntime spent running tests in s');
900 };
901
902
903 /**
904 * Draws a stats histogram.
905 * @param {string} statsField Field of the stats object to graph.
906 * @param {number} bucketSize The size for the histogram's buckets.
907 * @param {function(number, ...*): *} valueTransformFn Function for
908 * transforming the x-labels value for display.
909 * @param {number} width The width in pixels of the graph.
910 * @param {string} title The graph's title.
911 * @private
912 */
913 goog.testing.MultiTestRunner.prototype.drawStatsHistogram_ = function(
914 statsField, bucketSize, valueTransformFn, width, title) {
915
916 var hist = {}, data = [], xlabels = [], ylabels = [];
917 var max = 0;
918 for (var i = 0; i < this.stats_.length; i++) {
919 var num = this.stats_[i][statsField];
920 var bucket = Math.floor(num / bucketSize) * bucketSize;
921 if (bucket > max) {
922 max = bucket;
923 }
924 if (!hist[bucket]) {
925 hist[bucket] = 1;
926 } else {
927 hist[bucket]++;
928 }
929 }
930 var maxBucketSize = 0;
931 for (var i = 0; i <= max; i += bucketSize) {
932 xlabels.push(valueTransformFn(i));
933 var count = hist[i] || 0;
934 if (count > maxBucketSize) {
935 maxBucketSize = count;
936 }
937 data.push(count);
938 }
939 var diff = Math.max(1, Math.ceil(maxBucketSize / 10));
940 for (var i = 0; i <= maxBucketSize; i += diff) {
941 ylabels.push(i);
942 }
943 var chart = new goog.ui.ServerChart(
944 goog.ui.ServerChart.ChartType.VERTICAL_STACKED_BAR, width, 250, null,
945 goog.ui.ServerChart.CHART_SERVER_HTTPS_URI);
946 chart.setTitle(title);
947 chart.addDataSet(data, 'ff9900');
948 chart.setLeftLabels(ylabels);
949 chart.setGridY(ylabels.length - 1);
950 chart.setXLabels(xlabels);
951 chart.render(this.statsEl_);
952 };
953
954
955 /**
956 * Draws a pie chart showing the percentage of time spent running the tests
957 * compared to loading them etc.
958 * @private
959 */
960 goog.testing.MultiTestRunner.prototype.drawRunTimePie_ = function() {
961 var totalTime = 0, runTime = 0;
962 for (var i = 0; i < this.stats_.length; i++) {
963 var stat = this.stats_[i];
964 totalTime += stat.totalTime;
965 runTime += stat.runTime;
966 }
967 var loadTime = totalTime - runTime;
968 var pie = new goog.ui.ServerChart(
969 goog.ui.ServerChart.ChartType.PIE, 500, 250, null,
970 goog.ui.ServerChart.CHART_SERVER_HTTPS_URI);
971 pie.setMinValue(0);
972 pie.setMaxValue(totalTime);
973 pie.addDataSet([runTime, loadTime], 'ff9900');
974 pie.setXLabels(
975 ['Test execution (' + runTime + 'ms)', 'Loading (' + loadTime + 'ms)']);
976 pie.render(this.statsEl_);
977 };
978
979
980 /**
981 * Draws a pie chart showing the percentage of time spent running the tests
982 * compared to loading them etc.
983 * @private
984 */
985 goog.testing.MultiTestRunner.prototype.drawWorstTestsTable_ = function() {
986 this.stats_.sort(function(a, b) {
987 return b['numFilesLoaded'] - a['numFilesLoaded'];
988 });
989
990 var tbody = goog.bind(this.dom_.createDom, this.dom_, 'tbody');
991 var thead = goog.bind(this.dom_.createDom, this.dom_, 'thead');
992 var tr = goog.bind(this.dom_.createDom, this.dom_, 'tr');
993 var th = goog.bind(this.dom_.createDom, this.dom_, 'th');
994 var td = goog.bind(this.dom_.createDom, this.dom_, 'td');
995 var a = goog.bind(this.dom_.createDom, this.dom_, 'a');
996
997 var head = thead(
998 {'style': 'cursor: pointer'},
999 tr(null, th(null, ' '), th(null, 'Test file'),
1000 th('center', 'Num files loaded'), th('center', 'Run time (ms)'),
1001 th('center', 'Total time (ms)')));
1002 var body = tbody();
1003 var table = this.dom_.createDom(goog.dom.TagName.TABLE, null, head, body);
1004
1005 for (var i = 0; i < this.stats_.length; i++) {
1006 var stat = this.stats_[i];
1007 body.appendChild(
1008 tr(null, td('center', String(i + 1)),
1009 td(null,
1010 a({'href': this.basePath_ + stat['testFile'], 'target': '_blank'},
1011 stat['testFile'])),
1012 td('center', String(stat['numFilesLoaded'])),
1013 td('center', String(stat['runTime'])),
1014 td('center', String(stat['totalTime']))));
1015 }
1016
1017 this.statsEl_.appendChild(table);
1018
1019 this.tableSorter_.setDefaultSortFunction(goog.ui.TableSorter.numericSort);
1020 this.tableSorter_.setSortFunction(
1021 1 /* test file name */, goog.ui.TableSorter.alphaSort);
1022 this.tableSorter_.decorate(table);
1023 };
1024
1025
1026 /**
1027 * Clears the stats page.
1028 * @private
1029 */
1030 goog.testing.MultiTestRunner.prototype.clearStats_ = function() {
1031 goog.dom.removeChildren(this.statsEl_);
1032 this.tableSorter_.exitDocument();
1033 };
1034
1035
1036 /**
1037 * Updates the report's summary.
1038 * @private
1039 */
1040 goog.testing.MultiTestRunner.prototype.writeCurrentSummary_ = function() {
1041 var total = this.activeTests_.length;
1042 var executed = this.resultCount_;
1043 var passes = this.passes_;
1044 var duration = Math.round((goog.now() - this.startTime_) / 1000);
1045 var text = executed + ' of ' + total + ' tests executed.<br>' + passes +
1046 ' passed, ' + (executed - passes) + ' failed.<br>' +
1047 'Duration: ' + duration + 's.';
1048 this.reportEl_.firstChild.innerHTML = text;
1049 };
1050
1051
1052 /**
1053 * Adds a segment to the progress bar.
1054 * @param {string} title Title for the segment.
1055 * @param {*} success Whether the segment should indicate a success.
1056 * @private
1057 */
1058 goog.testing.MultiTestRunner.prototype.drawProgressSegment_ = function(
1059 title, success) {
1060 var part = this.progressRow_.cells[this.resultCount_ - 1];
1061 part.title = title + ' : ' + (success ? 'SUCCESS' : 'FAILURE');
1062 part.style.backgroundColor = success ? '#090' : '#900';
1063 };
1064
1065
1066 /**
1067 * Draws a test result in the report pane.
1068 * @param {string} test Test name.
1069 * @param {*} success Whether the test succeeded.
1070 * @param {string} report The report.
1071 * @private
1072 */
1073 goog.testing.MultiTestRunner.prototype.drawTestResult_ = function(
1074 test, success, report) {
1075 var text = goog.string.isEmptyOrWhitespace(report) ?
1076 'No report for ' + test + '\n' :
1077 report;
1078 var el = this.dom_.createDom(goog.dom.TagName.DIV);
1079 text = goog.string.htmlEscape(text).replace(/\n/g, '<br>');
1080 if (success) {
1081 el.className = goog.getCssName('goog-testrunner-report-success');
1082 } else {
1083 text += '<a href="' + this.basePath_ + test +
1084 '">Run individually &raquo;</a><br>&nbsp;';
1085 el.className = goog.getCssName('goog-testrunner-report-failure');
1086 }
1087 el.innerHTML = text;
1088 this.reportEl_.appendChild(el);
1089 };
1090
1091
1092 /**
1093 * Returns the current timestamp.
1094 * @return {string} HH:MM:SS.
1095 * @private
1096 */
1097 goog.testing.MultiTestRunner.prototype.getTimeStamp_ = function() {
1098 var d = new Date;
1099 return goog.string.padNumber(d.getHours(), 2) + ':' +
1100 goog.string.padNumber(d.getMinutes(), 2) + ':' +
1101 goog.string.padNumber(d.getSeconds(), 2);
1102 };
1103
1104
1105 /**
1106 * Trims a filename to be less than 35-characters, ensuring that we do not break
1107 * a path part.
1108 * @param {string} name The file name.
1109 * @return {string} The shortened name.
1110 * @private
1111 */
1112 goog.testing.MultiTestRunner.prototype.trimFileName_ = function(name) {
1113 if (name.length < 35) {
1114 return name;
1115 }
1116 var parts = name.split('/');
1117 var result = '';
1118 while (result.length < 35 && parts.length > 0) {
1119 result = '/' + parts.pop() + result;
1120 }
1121 return '...' + result;
1122 };
1123
1124
1125 /**
1126 * Shows the report and hides the log if the argument is true.
1127 * @param {number} tab Which tab to show.
1128 * @private
1129 */
1130 goog.testing.MultiTestRunner.prototype.showTab_ = function(tab) {
1131 var activeTabCssClass = goog.getCssName('goog-testrunner-activetab');
1132
1133 var logTabElement = goog.asserts.assert(this.logTabEl_);
1134 var reportTabElement = goog.asserts.assert(this.reportTabEl_);
1135 var statsTabElement = goog.asserts.assert(this.statsTabEl_);
1136
1137 if (tab == 0) {
1138 this.logEl_.style.display = '';
1139 goog.dom.classlist.add(logTabElement, activeTabCssClass);
1140 } else {
1141 this.logEl_.style.display = 'none';
1142 goog.dom.classlist.remove(logTabElement, activeTabCssClass);
1143 }
1144
1145 if (tab == 1) {
1146 this.reportEl_.style.display = '';
1147 goog.dom.classlist.add(reportTabElement, activeTabCssClass);
1148 } else {
1149 this.reportEl_.style.display = 'none';
1150 goog.dom.classlist.remove(reportTabElement, activeTabCssClass);
1151 }
1152
1153 if (tab == 2) {
1154 this.statsEl_.style.display = '';
1155 goog.dom.classlist.add(statsTabElement, activeTabCssClass);
1156 } else {
1157 this.statsEl_.style.display = 'none';
1158 goog.dom.classlist.remove(statsTabElement, activeTabCssClass);
1159 }
1160 };
1161
1162
1163 /**
1164 * Handles the start button being clicked.
1165 * @param {goog.events.BrowserEvent} e The click event.
1166 * @private
1167 */
1168 goog.testing.MultiTestRunner.prototype.onStartClicked_ = function(e) {
1169 this.start();
1170 };
1171
1172
1173 /**
1174 * Handles the stop button being clicked.
1175 * @param {goog.events.BrowserEvent} e The click event.
1176 * @private
1177 */
1178 goog.testing.MultiTestRunner.prototype.onStopClicked_ = function(e) {
1179 this.stopped_ = true;
1180 this.finish_();
1181 };
1182
1183
1184 /**
1185 * Handles the log tab being clicked.
1186 * @param {goog.events.BrowserEvent} e The click event.
1187 * @private
1188 */
1189 goog.testing.MultiTestRunner.prototype.onLogTabClicked_ = function(e) {
1190 this.showTab_(0);
1191 };
1192
1193
1194 /**
1195 * Handles the log tab being clicked.
1196 * @param {goog.events.BrowserEvent} e The click event.
1197 * @private
1198 */
1199 goog.testing.MultiTestRunner.prototype.onReportTabClicked_ = function(e) {
1200 this.showTab_(1);
1201 };
1202
1203
1204 /**
1205 * Handles the stats tab being clicked.
1206 * @param {goog.events.BrowserEvent} e The click event.
1207 * @private
1208 */
1209 goog.testing.MultiTestRunner.prototype.onStatsTabClicked_ = function(e) {
1210 this.showTab_(2);
1211 };
1212
1213
1214
1215 /**
1216 * Class used to manage the interaction with a single iframe.
1217 * @param {string} basePath The base path for tests.
1218 * @param {number} timeoutMs The time to wait for the test to load and run.
1219 * @param {boolean} verbosePasses Whether to show results for passes.
1220 * @param {goog.dom.DomHelper=} opt_domHelper Optional dom helper.
1221 * @constructor
1222 * @extends {goog.ui.Component}
1223 * @final
1224 */
1225 goog.testing.MultiTestRunner.TestFrame = function(
1226 basePath, timeoutMs, verbosePasses, opt_domHelper) {
1227 goog.ui.Component.call(this, opt_domHelper);
1228
1229 /**
1230 * Base path where tests should be resolved from.
1231 * @type {string}
1232 * @private
1233 */
1234 this.basePath_ = basePath;
1235
1236 /**
1237 * The timeout for the test.
1238 * @type {number}
1239 * @private
1240 */
1241 this.timeoutMs_ = timeoutMs;
1242
1243 /**
1244 * Whether to show a summary for passing tests.
1245 * @type {boolean}
1246 * @private
1247 */
1248 this.verbosePasses_ = verbosePasses;
1249
1250 /**
1251 * An event handler for handling events.
1252 * @type {goog.events.EventHandler<!goog.testing.MultiTestRunner.TestFrame>}
1253 * @private
1254 */
1255 this.eh_ = new goog.events.EventHandler(this);
1256
1257 /**
1258 * Object to hold test results. Key is test method or file name (depending on
1259 * failure mode) and the value is an array of failure messages.
1260 * @private {!Object<string,!Array<!goog.testing.TestCase.IResult>>}
1261 */
1262 this.testResults_ = {};
1263 };
1264 goog.inherits(goog.testing.MultiTestRunner.TestFrame, goog.ui.Component);
1265
1266
1267 /**
1268 * Reference to the iframe.
1269 * @type {HTMLIFrameElement}
1270 * @private
1271 */
1272 goog.testing.MultiTestRunner.TestFrame.prototype.iframeEl_ = null;
1273
1274
1275 /**
1276 * Whether the iframe for the current test has loaded.
1277 * @type {boolean}
1278 * @private
1279 */
1280 goog.testing.MultiTestRunner.TestFrame.prototype.iframeLoaded_ = false;
1281
1282
1283 /**
1284 * The test file being run.
1285 * @type {string}
1286 * @private
1287 */
1288 goog.testing.MultiTestRunner.TestFrame.prototype.testFile_ = '';
1289
1290
1291 /**
1292 * The report returned from the test.
1293 * @type {string}
1294 * @private
1295 */
1296 goog.testing.MultiTestRunner.TestFrame.prototype.report_ = '';
1297
1298
1299 /**
1300 * The total time loading and running the test in milliseconds.
1301 * @type {number}
1302 * @private
1303 */
1304 goog.testing.MultiTestRunner.TestFrame.prototype.totalTime_ = 0;
1305
1306
1307 /**
1308 * The actual runtime of the test in milliseconds.
1309 * @type {number}
1310 * @private
1311 */
1312 goog.testing.MultiTestRunner.TestFrame.prototype.runTime_ = 0;
1313
1314
1315 /**
1316 * The number of files loaded by the test.
1317 * @type {number}
1318 * @private
1319 */
1320 goog.testing.MultiTestRunner.TestFrame.prototype.numFilesLoaded_ = 0;
1321
1322
1323 /**
1324 * Whether the test was successful, null if no result has been returned yet.
1325 * @type {?boolean}
1326 * @private
1327 */
1328 goog.testing.MultiTestRunner.TestFrame.prototype.isSuccess_ = null;
1329
1330
1331 /**
1332 * Timestamp for the when the test was started.
1333 * @type {number}
1334 * @private
1335 */
1336 goog.testing.MultiTestRunner.TestFrame.prototype.startTime_ = 0;
1337
1338
1339 /**
1340 * Timestamp for the last state, used to determine timeouts.
1341 * @type {number}
1342 * @private
1343 */
1344 goog.testing.MultiTestRunner.TestFrame.prototype.lastStateTime_ = 0;
1345
1346
1347 /**
1348 * The state of the active test.
1349 * @type {number}
1350 * @private
1351 */
1352 goog.testing.MultiTestRunner.TestFrame.prototype.currentState_ = 0;
1353
1354
1355 /** @override */
1356 goog.testing.MultiTestRunner.TestFrame.prototype.disposeInternal = function() {
1357 goog.testing.MultiTestRunner.TestFrame.superClass_.disposeInternal.call(this);
1358 this.dom_.removeNode(this.iframeEl_);
1359 this.eh_.dispose();
1360 this.iframeEl_ = null;
1361 };
1362
1363
1364 /**
1365 * Runs a test file in this test frame.
1366 * @param {string} testFile The test to run.
1367 */
1368 goog.testing.MultiTestRunner.TestFrame.prototype.runTest = function(testFile) {
1369 this.lastStateTime_ = this.startTime_ = goog.now();
1370
1371 if (!this.iframeEl_) {
1372 this.createIframe_();
1373 }
1374
1375 this.iframeLoaded_ = false;
1376 this.currentState_ = 0;
1377 this.isSuccess_ = null;
1378 this.report_ = '';
1379 this.testResults_ = {};
1380 this.testFile_ = testFile;
1381
1382 try {
1383 this.iframeEl_.src = this.basePath_ + testFile;
1384 } catch (e) {
1385 // Failures will trigger a JS exception on the local file system.
1386 this.report_ = this.testFile_ + ' failed to load : ' + e.message;
1387 this.isSuccess_ = false;
1388 this.finish_();
1389 return;
1390 }
1391
1392 this.checkForCompletion_();
1393 };
1394
1395
1396 /**
1397 * @return {string} The test file the TestFrame is running.
1398 */
1399 goog.testing.MultiTestRunner.TestFrame.prototype.getTestFile = function() {
1400 return this.testFile_;
1401 };
1402
1403
1404 /**
1405 * @return {!Object} Stats about the test run.
1406 */
1407 goog.testing.MultiTestRunner.TestFrame.prototype.getStats = function() {
1408 return {
1409 'testFile': this.testFile_,
1410 'success': this.isSuccess_,
1411 'runTime': this.runTime_,
1412 'totalTime': this.totalTime_,
1413 'numFilesLoaded': this.numFilesLoaded_
1414 };
1415 };
1416
1417
1418 /**
1419 * @return {string} The report for the test run.
1420 */
1421 goog.testing.MultiTestRunner.TestFrame.prototype.getReport = function() {
1422 return this.report_;
1423 };
1424
1425
1426 /**
1427 * @return {!Object<string,!Array<!goog.testing.TestCase.IResult>>} The results
1428 * per individual test in the file. Key is the test filename concatenated
1429 * with the test name, and the array holds failures.
1430 */
1431 goog.testing.MultiTestRunner.TestFrame.prototype.getTestResults = function() {
1432 var results = {};
1433 for (var testName in this.testResults_) {
1434 var testKey = this.testFile_.replace(/\.html$/, '');
1435 // Concatenate with ":<testName>" unless the testName is equivalent to
1436 // testFile_, which means the test timed out or had no test methods and
1437 // there's no way to get the test method name.
1438 if (testName != this.testFile_) {
1439 testKey += ':' + testName;
1440 }
1441 results[testKey] = this.testResults_[testName];
1442 }
1443 return results;
1444 };
1445
1446
1447 /**
1448 * @return {?boolean} Whether the test frame had a success.
1449 */
1450 goog.testing.MultiTestRunner.TestFrame.prototype.isSuccess = function() {
1451 return this.isSuccess_;
1452 };
1453
1454
1455 /**
1456 * Handles the TestFrame finishing a single test.
1457 * @private
1458 */
1459 goog.testing.MultiTestRunner.TestFrame.prototype.finish_ = function() {
1460 this.totalTime_ = goog.now() - this.startTime_;
1461 // TODO(user): Fire an event instead?
1462 if (this.getParent() && this.getParent().processResult) {
1463 this.getParent().processResult(this);
1464 }
1465 };
1466
1467
1468 /**
1469 * Creates an iframe to run the tests in. For overriding in unit tests.
1470 * @private
1471 */
1472 goog.testing.MultiTestRunner.TestFrame.prototype.createIframe_ = function() {
1473 this.iframeEl_ = this.dom_.createDom(goog.dom.TagName.IFRAME);
1474 this.getElement().appendChild(this.iframeEl_);
1475 this.eh_.listen(this.iframeEl_, 'load', this.onIframeLoaded_);
1476 };
1477
1478
1479 /**
1480 * Handles the iframe loading.
1481 * @param {goog.events.BrowserEvent} e The load event.
1482 * @private
1483 */
1484 goog.testing.MultiTestRunner.TestFrame.prototype.onIframeLoaded_ = function(e) {
1485 this.iframeLoaded_ = true;
1486 };
1487
1488
1489 /**
1490 * Checks the active test for completion, keeping track of the tests' various
1491 * execution stages.
1492 * @private
1493 */
1494 goog.testing.MultiTestRunner.TestFrame.prototype.checkForCompletion_ =
1495 function() {
1496 var js = goog.dom.getFrameContentWindow(this.iframeEl_);
1497 switch (this.currentState_) {
1498 case 0:
1499 if (this.iframeLoaded_ && js['G_testRunner']) {
1500 this.lastStateTime_ = goog.now();
1501 this.currentState_++;
1502 }
1503 break;
1504 case 1:
1505 if (js['G_testRunner']['isInitialized']()) {
1506 this.lastStateTime_ = goog.now();
1507 this.currentState_++;
1508 }
1509 break;
1510 case 2:
1511 if (js['G_testRunner']['isFinished']()) {
1512 var tr = js['G_testRunner'];
1513 this.isSuccess_ = tr['isSuccess']();
1514 this.report_ = tr['getReport'](this.verbosePasses_);
1515 this.testResults_ = tr['getTestResults']();
1516 // If there is a syntax error, or no tests, it's not possible to get the
1517 // individual test method results from TestCase. So just create one here
1518 // based on the test report and filename.
1519 if (goog.object.isEmpty(this.testResults_)) {
1520 // Existence of a report is a signal of a test failure by the test
1521 // runner.
1522 this.testResults_[this.testFile_] = this.isSuccess_ ? [] : [{
1523 'message': this.report_,
1524 'source': this.testFile_,
1525 'stacktrace': ''
1526 }];
1527 }
1528 this.runTime_ = tr['getRunTime']();
1529 this.numFilesLoaded_ = tr['getNumFilesLoaded']();
1530 this.finish_();
1531 return;
1532 }
1533 }
1534
1535 // Check to see if the test has timed out.
1536 if (goog.now() - this.lastStateTime_ > this.timeoutMs_) {
1537 this.report_ = this.testFile_ + ' timed out ' +
1538 goog.testing.MultiTestRunner.STATES[this.currentState_];
1539 this.testResults_[this.testFile_] =
1540 [{'message': this.report_, 'source': this.testFile_, 'stacktrace': ''}];
1541 this.isSuccess_ = false;
1542 this.finish_();
1543 return;
1544 }
1545
1546 // Check again in 100ms.
1547 goog.Timer.callOnce(this.checkForCompletion_, 100, this);
1548 };