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

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: Remove global variable runningAsynchronousTest. 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 1cd3aececc419ad5a203ebd29e5c470051e5fc48..32b4769fddf034eede24746030f7462f43784f2f 100644
--- a/chrome/test/data/webui/webui_resource_test.js
+++ b/chrome/test/data/webui/webui_resource_test.js
@@ -3,6 +3,24 @@
// found in the LICENSE file.
/**
+ * List of test cases.
+ * @type {Array.<strring>} List of function names for tests to run.
arv (Not doing code reviews) 2013/06/20 17:45:15 Do we want to hide these in an IIFE?
kevers 2013/06/20 18:22:12 Done.
+ */
+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;
+
+/**
* Tests that an observation matches the expected value.
* @param {Object} expected The expected value.
* @param {Object} observed The actual value.
@@ -57,7 +75,7 @@ function assertNotEqual(reference, observed, opt_message) {
}
/**
- * Verifies that a test evaluation results in an assertion failure.
+ * Verifies that a test evaluation results in an exception.
* @param {!Function} f The test function.
*/
function assertThrows(f) {
@@ -72,38 +90,77 @@ function assertThrows(f) {
}
/**
+ * Verifies that the contents of the expected and observed arrays match.
+ * @param {Array} expected The expected result.
+ * @param {Array} observed The actual result.
+ */
+function assertArrayEquals(expected, observed) {
+ var v1 = Array.prototype.slice.call(expected);
+ var v2 = Array.prototype.slice.call(observed);
+ var equal = v1.length == v2.length;
+ if (equal) {
+ for (var i = 0; i < v1.length; i++) {
+ if (v1[i] !== v2[i]) {
+ equal = false;
+ break;
+ }
+ }
+ }
+ if (!equal) {
+ var message = 'Assertion Failed\n Observed: ' + v1 +
+ '\n Expected: ' + v2;
+ throw new Error(message);
+ }
+}
+
+/**
* Runs all functions starting with test and reports success or
* failure of the test suite.
*/
function runTests() {
- var tests = [];
-
- if (window.setUp)
- window.setUp();
-
- var success = true;
for (var name in window) {
if (typeof window[name] == 'function' && /^test/.test(name))
- tests.push(name);
+ testCases.push(name);
}
- if (!tests.length) {
+ if (!testCases.length) {
console.error('\nFailed to find test cases.');
- success = false;
+ cleanTestRun = false;
}
- for (var i = 0; i < tests.length; i++) {
+ continueTesting();
+}
+
+/**
+ * Runs the next test in the queue. Reports the test results if the queue is
+ * empty.
+ */
+function continueTesting() {
arv (Not doing code reviews) 2013/06/20 17:45:15 Does continueTesting need to be a global?
kevers 2013/06/20 18:22:12 Mo longer a global.
+ if (pendingTearDown) {
+ pendingTearDown();
+ pendingTearDown = null;
+ }
+ if(testCases.length > 0) {
arv (Not doing code reviews) 2013/06/20 17:45:15 if (
kevers 2013/06/20 18:22:12 Done.
+ var fn = testCases.pop();
+ var isAsyncTest = /Async$/.test(fn);
arv (Not doing code reviews) 2013/06/20 17:45:15 I still prefer fn.length instead
kevers 2013/06/20 18:22:12 Done.
try {
- window[tests[i]]();
- } catch (err) {
- console.error('Failure in test ' + tests[i] + '\n' + err);
+ 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);
- success = false;
+ 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');
}
-
- if (window.tearDown)
- window.tearDown();
-
- endTests(success);
}
/**
« 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