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

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

Issue 7576024: Provide ability for WebUIBrowserTests to run asynchronous tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added failure and test when asyncTestDone() is called for non-async tests. 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/async.js
diff --git a/chrome/test/data/webui/async.js b/chrome/test/data/webui/async.js
new file mode 100644
index 0000000000000000000000000000000000000000..76e913d27392efc20b7e509b91313d333c1369ab
--- /dev/null
+++ b/chrome/test/data/webui/async.js
@@ -0,0 +1,59 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Fails always.
+ * @throw {Error}
+ */
+function testFailsAssert() {
+ assertNotReached();
+ chrome.send('testContinues');
+ assertNotReached();
+}
+
+/**
+ * Records failure.
+ */
+function testFailsExpect() {
+ expectNotReached();
+ chrome.send('testContinues');
+ expectNotReached();
+}
+
+/**
+ * Passes and sends asyncTestDone message for browser_test to call
+ * asyncTestDone().
+ */
+function testPasses() {
+ expectTrue(true);
+ chrome.send('testContinues');
+ assertFalse(false);
+}
+
+/**
+ * Wraps the function represented by |name| similar to the way net_internals
+ * tests are wrapped.
+ * @param {string} name The name of the function to run.
+ */
+function runAsync(name) {
+ // Strip |name| from arguments.
+ var testArguments = Array.prototype.slice.call(arguments, 1);
+
+ // call async function.
+ var result = runTestFunction(name, this[name], testArguments);
+
+ // Pass on success; bail on errors.
+ if (result[0])
+ chrome.send('testPasses');
+ else
+ asyncTestDone(result);
+}
+
+/**
+ * Sends a message to handler to start |testName| and returns.
+ * @param {string} testName The name of the test to run.
+ */
+function startAsyncTest(testName) {
+ chrome.send('startAsyncTest', [testName]);
+}

Powered by Google App Engine
This is Rietveld 408576698