Index: chrome/test/data/webui/async_gen.js |
diff --git a/chrome/test/data/webui/async_gen.js b/chrome/test/data/webui/async_gen.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0ccbf4b7a93df36719a19734b6d1496920ec5a4c |
--- /dev/null |
+++ b/chrome/test/data/webui/async_gen.js |
@@ -0,0 +1,143 @@ |
+// 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. |
+ |
+/** |
+ * Test fixture for generated async tests. |
+ * @extends {testing.Test} |
+ */ |
+function WebUIBrowserAsyncGenTest() {} |
+ |
+WebUIBrowserAsyncGenTest.prototype = { |
+ __proto__: testing.Test.prototype, |
+ |
+ /** |
+ * Define the C++ class and include it. |
+ * @type {?string} |
+ * @override |
+ */ |
+ typedefCppFixture: null, |
+ |
+ /** @inheritDoc */ |
+ tearDown: function() { |
+ expectFalse(this.tornDown); |
+ expectFalse(this.running); |
+ this.tornDown = true; |
+ chrome.send('tornDown'); |
+ testing.Test.prototype.tearDown.call(this); |
+ }, |
+ |
+ /** @inheritDoc */ |
+ browsePreload: DUMMY_URL, |
+ |
+ /** @inheritDoc */ |
+ isAsync: true, |
+ |
+ /** |
+ * True when the tearDown method is called. |
+ * @type {boolean} |
+ */ |
+ tornDown: false, |
+ |
+ /** |
+ * True when running sync portion of test. |
+ * @type {boolean} |
+ */ |
+ running: false, |
+}; |
+ |
+GEN('#include "chrome/test/data/webui/async_gen-inl.h"'); |
+GEN(''); |
+GEN('WebUIBrowserAsyncGenTest::WebUIBrowserAsyncGenTest() {}'); |
+GEN('WebUIBrowserAsyncGenTest::~WebUIBrowserAsyncGenTest() {}'); |
+GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::'); |
+GEN(' AsyncWebUIMessageHandler() {}'); |
+GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::'); |
+GEN(' ~AsyncWebUIMessageHandler() {}'); |
mmenke
2011/08/23 15:26:29
Couldn't these go in the inl file?
Sheridan Rawlins
2011/08/24 02:33:53
Sadly, clang bots hork it up unless it's in a .cc
mmenke
2011/08/24 15:27:50
Might want to add a comment along those lines.
On
Sheridan Rawlins
2011/08/24 21:15:45
Done.
|
+GEN(''); |
+ |
+/** |
+ * Will be set to continuation test #1. |
+ * @type {Function} |
+ * @this {WebUIBrowserAsyncGenTest} |
+ */ |
+var continueTest; |
+ |
+/** |
+ * Will be set to continuation test #2. |
+ * @type {Function} |
+ * @this {WebUIBrowserAsyncGenTest} |
+ */ |
+var continueTest2; |
+ |
+// Test that tearDown isn't called until the callback test runs. |
+TEST_F('WebUIBrowserAsyncGenTest', 'TestTearDown', function() { |
+ assertFalse(this.tornDown); |
+ this.running = true; |
+ continueTest = this.continueTest(WhenTestDone.ALWAYS, function() { |
+ this.running = false; |
+ }); |
+ chrome.send('callJS', ['continueTest']); |
+}); |
+ |
+// Test that continuing can be done multiple times and have access to closure |
+// variables. |
+TEST_F('WebUIBrowserAsyncGenTest', 'TestContinue', function() { |
+ var xyz = false; |
+ continueTest = this.continueTest(WhenTestDone.DEFAULT, function() { |
+ assertFalse(xyz); |
+ xyz = true; |
+ chrome.send('callJS', ['continueTest2']); |
+ }); |
+ continueTest2 = this.continueTest(WhenTestDone.ALWAYS, function() { |
+ assertTrue(xyz); |
+ }); |
+ chrome.send('callJS', ['continueTest']); |
+}); |
+ |
+/** |
+ * Will be set to the runTest continuation by the following test fixture. |
+ * @type {Function} |
+ */ |
+var deferRunTest; |
+ |
+/** |
+ * Test fixture for testing deferred async tests. |
+ * @extends {WebUIBrowserAsyncGenTest} |
+ */ |
+function WebUIBrowserAsyncGenDeferredTest() {} |
+ |
+WebUIBrowserAsyncGenDeferredTest.prototype = { |
+ __proto__: WebUIBrowserAsyncGenTest.prototype, |
+ |
+ /** @inheritDoc */ |
+ typedefCppFixture: 'WebUIBrowserAsyncGenTest', |
+ |
+ /** |
+ * True when runTest is called. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ ranTest_: false, |
+ |
+ /** @inheritDoc */ |
+ setUp: function() { |
+ deferRunTest = this.deferRunTest(WhenTestDone.DEFAULT); |
+ continueTest = this.continueTest(WhenTestDone.DEFAULT, function() { |
+ expectFalse(this.ranTest_); |
+ chrome.send('callJS', ['deferRunTest']); |
+ }); |
+ chrome.send('callJS', ['continueTest']); |
+ }, |
+ |
+ /** @inheritDoc */ |
+ runTest: function() { |
+ this.ranTest_ = true; |
+ WebUIBrowserAsyncGenTest.prototype.runTest.apply(this, arguments); |
+ }, |
+}; |
+ |
+// Test that the test can be deferred appropriately. |
+TEST_F('WebUIBrowserAsyncGenDeferredTest', 'TestDeferRunTest', function() { |
+ expectTrue(this.ranTest_); |
+}); |