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

Side by Side Diff: pkg/unittest/lib/test_controller.js

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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 4
5 /** 5 /**
6 * Test controller logic - used by unit test harness to embed tests in 6 * Test controller logic - used by unit test harness to embed tests in
7 * DumpRenderTree. 7 * DumpRenderTree.
8 */ 8 */
9 9
10 // Clear the console before every test run - this is Firebug specific code. 10 // Clear the console before every test run - this is Firebug specific code.
(...skipping 15 matching lines...) Expand all
26 if (navigator.webkitStartDart) { 26 if (navigator.webkitStartDart) {
27 navigator.webkitStartDart(); 27 navigator.webkitStartDart();
28 } 28 }
29 29
30 // testRunner is provided by DRT or WebKit's layout tests. 30 // testRunner is provided by DRT or WebKit's layout tests.
31 // It is not available in selenium tests. 31 // It is not available in selenium tests.
32 var testRunner = window.testRunner || window.layoutTestController; 32 var testRunner = window.testRunner || window.layoutTestController;
33 33
34 var waitForDone = false; 34 var waitForDone = false;
35 35
36 function sendDomToTestDriver() { 36 function start() {
kustermann 2013/05/22 17:08:50 For symmetry reasons, I'd call it 'notifyStart()'.
ricow1 2013/05/22 17:36:12 Done.
37 if (testRunner) testRunner.startedDartTest = true;
38 if (window.opener) {
39 window.opener.postMessage("STARTING", "*");
40 }
41 }
42
43 function notifyDone() {
44 if (testRunner) testRunner.notifyDone();
45 // To support in browser launching of tests we post back start and result
46 // messages to the window.opener.
37 if (window.opener) { 47 if (window.opener) {
38 window.opener.postMessage(window.document.body.innerHTML, "*"); 48 window.opener.postMessage(window.document.body.innerHTML, "*");
39 } 49 }
40 } 50 }
41 51
42 function processMessage(msg) { 52 function processMessage(msg) {
43 if (typeof msg != 'string') return; 53 if (typeof msg != 'string') return;
44 if (msg == 'unittest-suite-done') { 54 if (msg == 'unittest-suite-done') {
45 if (testRunner) testRunner.notifyDone(); 55 notifyDone();
46 sendDomToTestDriver();
47 } else if (msg == 'unittest-suite-wait-for-done') { 56 } else if (msg == 'unittest-suite-wait-for-done') {
48 waitForDone = true; 57 waitForDone = true;
49 if (testRunner) testRunner.startedDartTest = true; 58 start();
50 } else if (msg == 'dart-calling-main') { 59 } else if (msg == 'dart-calling-main') {
51 if (testRunner) testRunner.startedDartTest = true; 60 start();
kustermann 2013/05/22 17:08:50 When we reach this point, the test has already bee
ricow1 2013/05/22 17:36:12 That is fine, we do 2 postmessage there, they will
52 } else if (msg == 'dart-main-done') { 61 } else if (msg == 'dart-main-done') {
53 if (!waitForDone) { 62 if (!waitForDone) {
54 window.postMessage('unittest-suite-success', '*'); 63 window.postMessage('unittest-suite-success', '*');
55 } 64 }
56 } else if (msg == 'unittest-suite-success') { 65 } else if (msg == 'unittest-suite-success') {
57 dartPrint('PASS'); 66 dartPrint('PASS');
58 if (testRunner) testRunner.notifyDone(); 67 notifyDone();
59 sendDomToTestDriver();
60 } else if (msg == 'unittest-suite-fail') { 68 } else if (msg == 'unittest-suite-fail') {
61 showErrorAndExit('Some tests failed.'); 69 showErrorAndExit('Some tests failed.');
62 } 70 }
63 } 71 }
64 72
65 function onReceive(e) { 73 function onReceive(e) {
66 processMessage(e.data); 74 processMessage(e.data);
67 } 75 }
68 76
69 if (testRunner) { 77 if (testRunner) {
70 testRunner.dumpAsText(); 78 testRunner.dumpAsText();
71 testRunner.waitUntilDone(); 79 testRunner.waitUntilDone();
72 } 80 }
73 window.addEventListener("message", onReceive, false); 81 window.addEventListener("message", onReceive, false);
74 82
75 function showErrorAndExit(message) { 83 function showErrorAndExit(message) {
76 if (message) { 84 if (message) {
77 dartPrint('Error: ' + String(message)); 85 dartPrint('Error: ' + String(message));
78 } 86 }
79 // dart/tools/testing/run_selenium.py is looking for either PASS or 87 // dart/tools/testing/run_selenium.py is looking for either PASS or
80 // FAIL and will continue polling until one of these words show up. 88 // FAIL and will continue polling until one of these words show up.
81 dartPrint('FAIL'); 89 dartPrint('FAIL');
82 if (testRunner) testRunner.notifyDone(); 90 nofityDone();
83 sendDomToTestDriver();
84 } 91 }
85 92
86 function onLoad(e) { 93 function onLoad(e) {
87 // needed for dartium compilation errors. 94 // needed for dartium compilation errors.
88 if (window.compilationError) { 95 if (window.compilationError) {
89 showErrorAndExit(window.compilationError); 96 showErrorAndExit(window.compilationError);
90 } 97 }
91 } 98 }
92 99
93 window.addEventListener("DOMContentLoaded", onLoad, false); 100 window.addEventListener("DOMContentLoaded", onLoad, false);
(...skipping 14 matching lines...) Expand all
108 if (document.readyState != "loaded") return; 115 if (document.readyState != "loaded") return;
109 // If 'startedDartTest' is not set, that means that the test did not have 116 // If 'startedDartTest' is not set, that means that the test did not have
110 // a chance to load. This will happen when a load error occurs in the VM. 117 // a chance to load. This will happen when a load error occurs in the VM.
111 // Give the machine time to start up. 118 // Give the machine time to start up.
112 setTimeout(function() { 119 setTimeout(function() {
113 // A window.postMessage might have been enqueued after this timeout. 120 // A window.postMessage might have been enqueued after this timeout.
114 // Just sleep another time to give the browser the time to process the 121 // Just sleep another time to give the browser the time to process the
115 // posted message. 122 // posted message.
116 setTimeout(function() { 123 setTimeout(function() {
117 if (testRunner && !testRunner.startedDartTest) { 124 if (testRunner && !testRunner.startedDartTest) {
118 testRunner.notifyDone(); 125 notifyDone();
119 sendDomToTestDriver();
120 } 126 }
121 }, 0); 127 }, 0);
122 }, 50); 128 }, 50);
123 }); 129 });
124 130
125 // dart2js will generate code to call this function to handle the Dart 131 // dart2js will generate code to call this function to handle the Dart
126 // [print] method. The base [Configuration] (config.html) calls 132 // [print] method. The base [Configuration] (config.html) calls
127 // [print] with the secret messages "unittest-suite-success" and 133 // [print] with the secret messages "unittest-suite-success" and
128 // "unittest-suite-wait-for-done". These messages are then posted so 134 // "unittest-suite-wait-for-done". These messages are then posted so
129 // processMessage above will see them. 135 // processMessage above will see them.
(...skipping 15 matching lines...) Expand all
145 try { 151 try {
146 main(); 152 main();
147 } catch (e) { 153 } catch (e) {
148 dartPrint(e); 154 dartPrint(e);
149 if (e.stack) dartPrint(e.stack); 155 if (e.stack) dartPrint(e.stack);
150 window.postMessage('unittest-suite-fail', '*'); 156 window.postMessage('unittest-suite-fail', '*');
151 return; 157 return;
152 } 158 }
153 window.postMessage('dart-main-done', '*'); 159 window.postMessage('dart-main-done', '*');
154 } 160 }
OLDNEW
« no previous file with comments | « no previous file | tools/testing/dart/browser_controller.dart » ('j') | tools/testing/dart/browser_controller.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698