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

Unified Diff: dart/pkg/unittest/lib/test_controller.js

Issue 36913002: test.py: Sending JSON between test_controller.js <-> browser_controller (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: dart/pkg/unittest/lib/test_controller.js
diff --git a/dart/pkg/unittest/lib/test_controller.js b/dart/pkg/unittest/lib/test_controller.js
index 68b83bfe0a33f260a8ec4bcc9285d8c2b7868975..4e719f66e550491ebb3916f2134ac3a4f0fc1945 100644
--- a/dart/pkg/unittest/lib/test_controller.js
+++ b/dart/pkg/unittest/lib/test_controller.js
@@ -7,11 +7,49 @@
* conent shell.
ricow1 2013/10/23 11:42:32 conent -> content + this comment is outdated
*/
-// Clear the console before every test run - this is Firebug specific code.
-if (typeof console == "object" && typeof console.clear == "function") {
- console.clear();
+/*
+ * We will collect testing driver specific messages here instead of printing
+ * them to the DOM.
+ * Every entry will look like this:
+ * {
+ * 'type' : 'test_outcome' / 'print' / 'debug' / 'message_received' / 'dom'
+ * 'value' : 'some content',
+ * }
+ */
+var MESSAGES = [];
+
+function recordMessage(type, value) {
+ var message = {
+ type: type,
+ value: value
+ };
+ MESSAGES.push(message);
+ if (usingBrowserController()) {
+ printToConsole(JSON.stringify(message, null, 2));
+ }
+}
+
+function clearConsole() {
+ // Clear the console before every test run - this is Firebug specific code.
+ if (typeof console == 'object' && typeof console.clear == 'function') {
+ console.clear();
+ }
}
+function printToConsole(message) {
+ if (typeof console === 'object') {
+ console.log(message);
+ }
+ if (!usingBrowserController()) {
+ var pre = document.createElement('pre');
+ pre.appendChild(document.createTextNode(String(message)));
+ document.body.appendChild(pre);
+ document.body.appendChild(document.createTextNode('\n'));
+ }
+}
+
+clearConsole();
+
// Some tests may expect and have no way to suppress global errors.
var testExpectsGlobalError = false;
var testSuppressedGlobalErrors = [];
@@ -64,6 +102,10 @@ function getDriverWindow() {
return null;
}
+function usingBrowserController() {
ricow1 2013/10/23 11:42:32 I am not sure we should special case on the browse
+ return getDriverWindow() != null;
+}
+
function notifyStart() {
var driver = getDriverWindow();
if (driver) {
@@ -73,30 +115,38 @@ function notifyStart() {
// We call notifyStart here to notify the encapsulating browser.
notifyStart();
-function notifyDone() {
- if (testRunner) testRunner.notifyDone();
-
- // TODO(ricow): REMOVE, debug info, see issue 13292
- if (!testRunner) {
- printMessage('Calling notifyDone()');
+function notifyDone(test_outcome) {
+ recordMessage('debug', 'Test outcome: ' + test_outcome);
+ // If we are not using the browser controller (i.e. in the none-drt
ricow1 2013/10/23 11:42:32 again, I think this comment is bound to much to ou
+ // configuration), we need to print 'test_outcome' as it is.
+ if (!usingBrowserController()) {
+ printToConsole(test_outcome);
}
+
+ if (testRunner) testRunner.notifyDone();
// To support in browser launching of tests we post back start and result
// messages to the window.opener.
var driver = getDriverWindow();
if (driver) {
- driver.postMessage(window.document.body.innerHTML, "*");
+ // FIXME: we have to post the dom and all recorded messages
+ var messages = MESSAGES.slice(0);
+ messages.push({
+ type: 'dom',
+ value: '' + window.document.documentElement.innerHTML
+ });
+ messages.push({
+ type: 'test_outcome',
+ value: test_outcome
+ });
+
+ driver.postMessage(JSON.stringify(messages), '*');
}
}
function processMessage(msg) {
- // TODO(ricow): REMOVE, debug info, see issue 13292
- if (!testRunner) {
- printMessage('processMessage(): ' + msg);
- }
+ recordMessage('message_received', '' + msg);
if (typeof msg != 'string') return;
- if (msg == 'unittest-suite-done') {
- notifyDone();
- } else if (msg == 'unittest-suite-wait-for-done') {
+ if (msg == 'unittest-suite-wait-for-done') {
waitForDone = true;
if (testRunner) {
testRunner.startedDartTest = true;
@@ -107,14 +157,12 @@ function processMessage(msg) {
}
} else if (msg == 'dart-main-done') {
if (!waitForDone) {
- printMessage('PASS');
- notifyDone();
+ notifyDone('PASS');
}
} else if (msg == 'unittest-suite-success') {
- printMessage('PASS');
- notifyDone();
+ notifyDone('PASS');
} else if (msg == 'unittest-suite-fail') {
- showErrorAndExit('Some tests failed.');
+ notifyDone('FAIL');
}
}
@@ -130,12 +178,9 @@ window.addEventListener("message", onReceive, false);
function showErrorAndExit(message) {
if (message) {
- printMessage('Error: ' + String(message));
+ recordMessage('debug', 'Error: ' + String(message));
}
- // dart/tools/testing/run_selenium.py is looking for either PASS or
- // FAIL and will continue polling until one of these words show up.
- printMessage('FAIL');
- notifyDone();
+ notifyDone('FAIL');
}
function onLoad(e) {
@@ -167,7 +212,7 @@ document.addEventListener('readystatechange', function () {
// posted message.
setTimeout(function() {
if (testRunner && !testRunner.startedDartTest) {
- notifyDone();
+ notifyDone('NOT_STARTED');
}
}, 0);
}, 50);
@@ -192,26 +237,15 @@ document.addEventListener('readystatechange', function () {
//
// These messages are used to communicate with the test and will be posted so
// [processMessage] above can see it.
-function dartPrint(msg) {
- if ((msg === 'unittest-suite-success')
- || (msg === 'unittest-suite-done')
- || (msg === 'unittest-suite-wait-for-done')
- || (msg === 'dart-calling-main')
- || (msg === 'dart-main-done')) {
- window.postMessage(msg, '*');
+function dartPrint(message) {
+ recordMessage('print', message);
+ if ((message === 'unittest-suite-success')
+ || (message === 'unittest-suite-wait-for-done')
+ || (message === 'dart-calling-main')
+ || (message === 'dart-main-done')) {
+ window.postMessage(message, '*');
return;
}
- printMessage(msg);
-}
-
-// Prints 'msg' to the console (if available) and to the body of the html
-// document.
-function printMessage(msg) {
- if (typeof console === 'object') console.warn(msg);
- var pre = document.createElement('pre');
- pre.appendChild(document.createTextNode(String(msg)));
- document.body.appendChild(pre);
- document.body.appendChild(document.createTextNode('\n'));
}
// dart2js will generate code to call this function instead of calling
@@ -221,9 +255,7 @@ function dartMainRunner(main) {
try {
main();
} catch (e) {
- dartPrint(e);
- if (e.stack) dartPrint(e.stack);
- window.postMessage('unittest-suite-fail', '*');
+ showErrorAndExit('Exception: ' + e + '\nStack: ' + e.stack);
return;
}
dartPrint('dart-main-done');

Powered by Google App Engine
This is Rietveld 408576698