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

Unified Diff: chrome/test/data/webui/test_api.js

Issue 7576024: Provide ability for WebUIBrowserTests to run asynchronous tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't need to expose isAsyncTestDone. Created 9 years, 4 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: chrome/test/data/webui/test_api.js
diff --git a/chrome/test/data/webui/test_api.js b/chrome/test/data/webui/test_api.js
index 72de125013fd6830d488d5c1cb467aa5f679dd07..3d384cdb52b6133747d77a467ba984abc77d9c14 100644
--- a/chrome/test/data/webui/test_api.js
+++ b/chrome/test/data/webui/test_api.js
@@ -18,6 +18,17 @@ var testing = {};
**/
var currentTestCase = null;
+/**
+ * @type {?string} The string representation of the currently running test
+ * function.
+ */
+var currentTestFunction = null;
+
+/**
+ * @type {?Array} The arguments of the currently running test.
+ */
+var currentTestArguments = null;
+
(function() {
// Provide global objects for generation case.
if (this['window'] === undefined)
@@ -309,6 +320,43 @@ var currentTestCase = null;
**/
var helper = new CallHelper();
+ /**
+ * true when asyncTestDone has been called.
+ * @type {boolean}
+ */
+ var asyncTestIsDone = false;
+
+ /**
+ * Notifies the running browser test that any async javascript is complete.
+ * @param {Array.<boolean, string>=} result When passed, this is used for the
+ * asyncTestResult message.
+ **/
+ function asyncTestDone(result) {
+ if (!asyncTestIsDone) {
+ asyncTestIsDone = true;
+ chrome.send('asyncTestResult', result ? result : testResult());
+ }
+ }
+
+ /**
+ * Returns [success, message] & clears |errors|.
+ * @return {Array.<boolean, string>}
+ **/
+ function testResult() {
+ var result = [true, ''];
+ if (errors.length) {
+ var message = '';
+ for (var i = 0; i < errors.length; ++i) {
+ message += 'Failed: ' + currentTestFunction + '(' +
+ currentTestArguments.map(JSON.stringify) +
+ ')\n' + errors[i].stack;
+ }
+ errors.splice(0, errors.length);
+ result = [false, message];
+ }
+ return result;
+ }
+
// Asserts.
// Use the following assertions to verify a condition within a test.
// If assertion fails, the C++ backend will be immediately notified.
@@ -512,20 +560,10 @@ var currentTestCase = null;
**/
function runTestFunction(testFunction, testBody, testArguments) {
errors.splice(0, errors.length);
+ currentTestFunction = testFunction;
+ currentTestArguments = testArguments;
createExpect(testBody).apply(null, testArguments);
-
- var result = [true];
- if (errors.length) {
- var message = '';
- for (var i = 0; i < errors.length; ++i) {
- message += 'Failed: ' + testFunction + '(' +
- testArguments.map(JSON.stringify) +
- ')\n' + errors[i].stack;
- }
- errors.splice(0, errors.length);
- result = [false, message];
- }
- return result;
+ return testResult();
}
/**
@@ -710,6 +748,7 @@ var currentTestCase = null;
// Exports.
testing.Test = Test;
+ window.asyncTestDone = asyncTestDone;
window.assertTrue = assertTrue;
window.assertFalse = assertFalse;
window.assertGE = assertGE;

Powered by Google App Engine
This is Rietveld 408576698