OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * Test fixture for generated async tests. | |
7 * @extends {testing.Test} | |
8 */ | |
9 function WebUIBrowserAsyncGenTest() {} | |
10 | |
11 WebUIBrowserAsyncGenTest.prototype = { | |
12 __proto__: testing.Test.prototype, | |
13 | |
14 /** | |
15 * Define the C++ class and include it. | |
16 * @type {?string} | |
17 * @override | |
18 */ | |
19 typedefCppFixture: null, | |
20 | |
21 /** @inheritDoc */ | |
22 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.
| |
23 expectFalse(this.tornDown); | |
24 expectFalse(this.running); | |
25 this.tornDown = true; | |
26 chrome.send('tornDown'); | |
27 testing.Test.prototype.TearDown.call(this); | |
28 }, | |
29 | |
30 /** @inheritDoc */ | |
31 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
| |
32 | |
33 /** @inheritDoc */ | |
34 isAsync: true, | |
35 | |
36 /** | |
37 * True when the TearDown method is called. | |
38 * @type {boolean} | |
39 */ | |
40 tornDown: false, | |
41 | |
42 /** | |
43 * True when running sync portion of test. | |
44 * @type {boolean} | |
45 */ | |
46 running: false, | |
47 }; | |
48 | |
49 GEN('#include "chrome/test/data/webui/async_gen-inl.h"'); | |
50 GEN(''); | |
51 GEN('WebUIBrowserAsyncGenTest::WebUIBrowserAsyncGenTest() {}'); | |
52 GEN('WebUIBrowserAsyncGenTest::~WebUIBrowserAsyncGenTest() {}'); | |
53 GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::'); | |
54 GEN(' AsyncWebUIMessageHandler() {}'); | |
55 GEN('WebUIBrowserAsyncGenTest::AsyncWebUIMessageHandler::'); | |
56 GEN(' ~AsyncWebUIMessageHandler() {}'); | |
57 GEN(''); | |
58 | |
59 /** | |
60 * Will be set to continuation test #1. | |
61 * @type {Function} | |
62 * @this {WebUIBrowserAsyncGenTest} | |
63 */ | |
64 var continueTest; | |
65 | |
66 /** | |
67 * Will be set to continuation test #2. | |
68 * @type {Function} | |
69 * @this {WebUIBrowserAsyncGenTest} | |
70 */ | |
71 var continueTest2; | |
72 | |
73 // Test that TearDown isn't called until the callback test runs. | |
74 TEST_F('WebUIBrowserAsyncGenTest', 'TestTearDown', function() { | |
75 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.
| |
76 assertFalse(this.tornDown); | |
77 this.running = true; | |
78 continueTest = this.continueTest(true, function() { | |
79 this.running = false; | |
80 }); | |
81 chrome.send('callJS', ['continueTest']); | |
82 }); | |
83 | |
84 // Test that continuing can be done multiple times and have access to closure | |
85 // variables. | |
86 TEST_F('WebUIBrowserAsyncGenTest', 'TestContinue', function() { | |
87 var xyz = false; | |
88 continueTest = this.continueTest(false, function() { | |
89 assertFalse(xyz); | |
90 xyz = true; | |
91 chrome.send('callJS', ['continueTest2']); | |
92 }); | |
93 continueTest2 = this.continueTest(true, function() { | |
94 assertTrue(xyz); | |
95 }); | |
96 chrome.send('callJS', ['continueTest']); | |
97 }); | |
98 | |
99 /** | |
100 * Will be set to the RunTest continuation by the following test fixture. | |
101 * @type {Function} | |
102 */ | |
103 var deferRunTest; | |
104 | |
105 /** | |
106 * Test fixture for testing deferred async tests. | |
107 * @extends {WebUIBrowserAsyncGenTest} | |
108 */ | |
109 function WebUIBrowserAsyncGenDeferredTest() {} | |
110 | |
111 WebUIBrowserAsyncGenDeferredTest.prototype = { | |
112 __proto__: WebUIBrowserAsyncGenTest.prototype, | |
113 | |
114 /** @inheritDoc */ | |
115 typedefCppFixture: 'WebUIBrowserAsyncGenTest', | |
116 | |
117 /** | |
118 * True when RunTest is called. | |
119 * @type {boolean} | |
120 * @private | |
121 */ | |
122 ranTest_: false, | |
123 | |
124 /** @inheritDoc */ | |
125 SetUp: function() { | |
arv (Not doing code reviews)
2011/08/22 20:57:18
setUp
Sheridan Rawlins
2011/08/23 01:06:15
Done.
| |
126 deferRunTest = this.deferRunTest(); | |
127 continueTest = this.continueTest(false, function() { | |
128 expectFalse(this.ranTest_); | |
129 chrome.send('callJS', ['deferRunTest']); | |
130 }); | |
131 chrome.send('callJS', ['continueTest']); | |
132 }, | |
133 | |
134 /** @inheritDoc */ | |
135 RunTest: function() { | |
arv (Not doing code reviews)
2011/08/22 20:57:18
runTest
Sheridan Rawlins
2011/08/23 01:06:15
Done.
| |
136 this.ranTest_ = true; | |
137 WebUIBrowserAsyncGenTest.prototype.RunTest.apply( | |
138 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.
| |
139 }, | |
140 }; | |
141 | |
142 // Test that the test can be deferred appropriately. | |
143 TEST_F('WebUIBrowserAsyncGenDeferredTest', 'TestDeferRunTest', function() { | |
144 expectTrue(this.ranTest_); | |
145 }); | |
OLD | NEW |