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..01a3c57d35c5b4ce1e9c3d90f094d96e5b41cbf4 |
--- /dev/null |
+++ b/chrome/test/data/webui/async_gen.js |
@@ -0,0 +1,145 @@ |
+// 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() { |
arv (Not doing code reviews)
2011/08/22 20:57:18
this should have been tearDown. Only constructors
Sheridan Rawlins
2011/08/23 01:06:15
Done.
|
+ expectFalse(this.tornDown); |
+ expectFalse(this.running); |
+ this.tornDown = true; |
+ chrome.send('tornDown'); |
+ testing.Test.prototype.TearDown.call(this); |
+ }, |
+ |
+ /** @inheritDoc */ |
+ browsePreload: 'chrome://history/', |
arv (Not doing code reviews)
2011/08/22 20:57:18
This seems a bit arbitrary. Care to add a comment?
Sheridan Rawlins
2011/08/23 01:06:15
Moved kDummyURL into WebUIBrowserTest and made DUM
|
+ |
+ /** @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() {}'); |
+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() { |
+ self = this; |
arv (Not doing code reviews)
2011/08/22 20:57:18
missing var
arv (Not doing code reviews)
2011/08/22 20:57:18
self is not used
Sheridan Rawlins
2011/08/23 01:06:15
Done.
|
+ assertFalse(this.tornDown); |
+ this.running = true; |
+ continueTest = this.continueTest(true, 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(false, function() { |
+ assertFalse(xyz); |
+ xyz = true; |
+ chrome.send('callJS', ['continueTest2']); |
+ }); |
+ continueTest2 = this.continueTest(true, 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() { |
arv (Not doing code reviews)
2011/08/22 20:57:18
setUp
Sheridan Rawlins
2011/08/23 01:06:15
Done.
|
+ deferRunTest = this.deferRunTest(); |
+ continueTest = this.continueTest(false, function() { |
+ expectFalse(this.ranTest_); |
+ chrome.send('callJS', ['deferRunTest']); |
+ }); |
+ chrome.send('callJS', ['continueTest']); |
+ }, |
+ |
+ /** @inheritDoc */ |
+ RunTest: function() { |
arv (Not doing code reviews)
2011/08/22 20:57:18
runTest
Sheridan Rawlins
2011/08/23 01:06:15
Done.
|
+ this.ranTest_ = true; |
+ WebUIBrowserAsyncGenTest.prototype.RunTest.apply( |
+ this, Array.prototype.slice.call(arguments)); |
arv (Not doing code reviews)
2011/08/22 20:57:18
this slice is not needed. apply is arguments aware
Sheridan Rawlins
2011/08/23 01:06:15
Done.
|
+ }, |
+}; |
+ |
+// Test that the test can be deferred appropriately. |
+TEST_F('WebUIBrowserAsyncGenDeferredTest', 'TestDeferRunTest', function() { |
+ expectTrue(this.ranTest_); |
+}); |