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

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

Issue 16831021: Convert asynchronous closure test in cr.ui framework to a browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge trunk Created 7 years, 6 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
« no previous file with comments | « chrome/test/data/webui/webui_resource_browsertest.cc ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/webui/webui_resource_test.js
diff --git a/chrome/test/data/webui/webui_resource_test.js b/chrome/test/data/webui/webui_resource_test.js
index 1e1205360290e7dea1957e567435e9be773358cd..175f2f6dc6a2061c879ce618a7319fbd266136d3 100644
--- a/chrome/test/data/webui/webui_resource_test.js
+++ b/chrome/test/data/webui/webui_resource_test.js
@@ -96,35 +96,79 @@ function assertArrayEquals(expected, observed) {
}
/**
- * Runs all functions starting with test and reports success or
- * failure of the test suite.
+ * Defines runTests.
*/
-function runTests() {
- var tests = [];
- var success = true;
- for (var name in window) {
- if (typeof window[name] == 'function' && /^test/.test(name))
- tests.push(name);
- }
- if (!tests.length) {
- console.error('\nFailed to find test cases.');
- success = false;
- }
- for (var i = 0; i < tests.length; i++) {
- try {
- if (window.setUp)
- window.setUp();
- window[tests[i]]();
- } catch (err) {
- console.error('Failure in test ' + tests[i] + '\n' + err);
- console.log(err.stack);
- success = false;
+(function(exports) {
+ /**
+ * List of test cases.
+ * @type {Array.<string>} List of function names for tests to run.
+ */
+ var testCases = [];
+
+ /**
+ * Indicates if all tests have run successfully.
+ * @type {boolean}
+ */
+ var cleanTestRun = true;
+
+ /**
+ * Armed during setup of a test to call the matching tear down code.
+ * @type {Function}
+ */
+ var pendingTearDown = null;
+
+ /**
+ * Runs all functions starting with test and reports success or
+ * failure of the test suite.
+ */
+ function runTests() {
+ for (var name in window) {
+ if (typeof window[name] == 'function' && /^test/.test(name))
+ testCases.push(name);
+ }
+ if (!testCases.length) {
+ console.error('Failed to find test cases.');
+ cleanTestRun = false;
}
- if (window.tearDown)
- window.tearDown();
+ continueTesting();
}
- endTests(success);
-}
+
+ /**
+ * Runs the next test in the queue. Reports the test results if the queue is
+ * empty.
+ */
+ function continueTesting() {
+ if (pendingTearDown) {
+ pendingTearDown();
+ pendingTearDown = null;
+ }
+ if (testCases.length > 0) {
+ var fn = testCases.pop();
+ var isAsyncTest = window[fn].length;
+ try {
+ if (window.setUp)
+ window.setUp();
+ pendingTearDown = window.tearDown;
+ window[fn](continueTesting);
+ } catch(err) {
+ console.error('Failure in test ' + fn + '\n' + err);
+ console.log(err.stack);
+ cleanTestRun = false;
+ }
+ // Asynchronous tests must manually call continueTesting when complete.
+ if (!isAsyncTest)
+ continueTesting();
+ } else {
+ endTests(cleanTestRun);
+ }
+ if (testCases.length) {
+ domAutomationController.setAutomationId(1);
+ domAutomationController.send('PENDING');
+ }
+ };
+
+ exports.runTests = runTests;
+})(this);
/**
* Signals completion of a test.
« no previous file with comments | « chrome/test/data/webui/webui_resource_browsertest.cc ('k') | content/public/test/browser_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698