OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Test fixture for generated async tests. | 6 * Test fixture for generated async tests. |
7 * @extends {testing.Test} | 7 * @extends {testing.Test} |
8 */ | 8 */ |
9 function WebUIBrowserAsyncGenTest() {} | 9 function WebUIBrowserAsyncGenTest() {} |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 }); | 94 }); |
95 continueTest2 = this.continueTest(WhenTestDone.ALWAYS, function() { | 95 continueTest2 = this.continueTest(WhenTestDone.ALWAYS, function() { |
96 assertTrue(xyz); | 96 assertTrue(xyz); |
97 }); | 97 }); |
98 chrome.send('callJS', ['continueTest']); | 98 chrome.send('callJS', ['continueTest']); |
99 }); | 99 }); |
100 | 100 |
101 // Test that runAllActionsAsync can be called with multiple functions, and with | 101 // Test that runAllActionsAsync can be called with multiple functions, and with |
102 // bound, saved, or mixed arguments. | 102 // bound, saved, or mixed arguments. |
103 TEST_F('WebUIBrowserAsyncGenTest', 'TestRunAllActionsAsyncMock', function() { | 103 TEST_F('WebUIBrowserAsyncGenTest', 'TestRunAllActionsAsyncMock', function() { |
104 /** | 104 this.makeAndRegisterMockHandler(['testBoundArgs', |
105 * Create a handler class with empty methods to allow mocking to register | 105 'testSavedArgs', |
106 * expectations and for registration of handlers with chrome.send. | 106 'testMixedArgs', |
107 * @constructor | 107 ]); |
108 */ | |
109 function MockHandler() {} | |
110 | |
111 MockHandler.prototype = { | |
112 testBoundArgs: function() {}, | |
113 testSavedArgs: function() {}, | |
114 testMixedArgs: function() {}, | |
115 }; | |
116 | |
117 var mockHandler = mock(MockHandler); | |
118 registerMockMessageCallbacks(mockHandler, MockHandler); | |
119 | |
120 // Bind some arguments. | 108 // Bind some arguments. |
121 var var1, var2; | 109 var var1, var2; |
122 mockHandler.expects(once()).testBoundArgs(). | 110 this.mockHandler.expects(once()).testBoundArgs(). |
123 will(runAllActionsAsync(WhenTestDone.DEFAULT, | 111 will(runAllActionsAsync(WhenTestDone.DEFAULT, |
124 callFunction(function(args) { | 112 callFunction(function(args) { |
125 var1 = args[0]; | 113 var1 = args[0]; |
126 }, ['val1']), | 114 }, ['val1']), |
127 callFunction(function(args) { | 115 callFunction(function(args) { |
128 var2 = args[0]; | 116 var2 = args[0]; |
129 }, ['val2']))); | 117 }, ['val2']))); |
130 | 118 |
131 // Receive some saved arguments. | 119 // Receive some saved arguments. |
132 var var3, var4; | 120 var var3, var4; |
133 var savedArgs = new SaveMockArguments(); | 121 var savedArgs = new SaveMockArguments(); |
134 var savedArgs2 = new SaveMockArguments(); | 122 var savedArgs2 = new SaveMockArguments(); |
135 mockHandler.expects(once()).testSavedArgs( | 123 this.mockHandler.expects(once()).testSavedArgs( |
136 savedArgs.match(savedArgs2.match(eq(['passedVal1'])))). | 124 savedArgs.match(savedArgs2.match(eq(['passedVal1'])))). |
137 will(runAllActionsAsync( | 125 will(runAllActionsAsync( |
138 WhenTestDone.DEFAULT, | 126 WhenTestDone.DEFAULT, |
139 callFunctionWithSavedArgs(savedArgs, function(args) { | 127 callFunctionWithSavedArgs(savedArgs, function(args) { |
140 var3 = args[0]; | 128 var3 = args[0]; |
141 }), | 129 }), |
142 callFunctionWithSavedArgs(savedArgs2, function(args) { | 130 callFunctionWithSavedArgs(savedArgs2, function(args) { |
143 var4 = args[0]; | 131 var4 = args[0]; |
144 }))); | 132 }))); |
145 | 133 |
146 // Receive some saved arguments and some bound arguments. | 134 // Receive some saved arguments and some bound arguments. |
147 var var5, var6, var7, var8; | 135 var var5, var6, var7, var8; |
148 mockHandler.expects(once()).testMixedArgs( | 136 this.mockHandler.expects(once()).testMixedArgs( |
149 savedArgs.match(savedArgs2.match(eq('passedVal2')))). | 137 savedArgs.match(savedArgs2.match(eq('passedVal2')))). |
150 will(runAllActionsAsync( | 138 will(runAllActionsAsync( |
151 WhenTestDone.DEFAULT, | 139 WhenTestDone.DEFAULT, |
152 callFunctionWithSavedArgs( | 140 callFunctionWithSavedArgs( |
153 savedArgs, function(passedArgs, boundArgs) { | 141 savedArgs, function(passedArgs, boundArgs) { |
154 var5 = passedArgs[0]; | 142 var5 = passedArgs[0]; |
155 var6 = boundArgs[0]; | 143 var6 = boundArgs[0]; |
156 }, ['val6']), | 144 }, ['val6']), |
157 callFunctionWithSavedArgs( | 145 callFunctionWithSavedArgs( |
158 savedArgs2, function(passedArgs, boundArgs) { | 146 savedArgs2, function(passedArgs, boundArgs) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 179 |
192 /** | 180 /** |
193 * Set |testRan| to true. | 181 * Set |testRan| to true. |
194 */ | 182 */ |
195 function setTestRanTrue() { | 183 function setTestRanTrue() { |
196 testRan = true; | 184 testRan = true; |
197 } | 185 } |
198 | 186 |
199 // Test overriding globals. | 187 // Test overriding globals. |
200 TEST_F('WebUIBrowserAsyncGenTest', 'TestRegisterMockGlobals', function() { | 188 TEST_F('WebUIBrowserAsyncGenTest', 'TestRegisterMockGlobals', function() { |
201 /** | 189 this.makeAndRegisterMockGlobals(['setTestRanTrue']); |
202 * Create a mock class to describe the globals to mock. | |
203 * @constructor | |
204 */ | |
205 function MockGlobals() {} | |
206 | |
207 MockGlobals.prototype = { | |
208 setTestRanTrue: function() {}, | |
209 }; | |
210 | 190 |
211 // Mock the setTestRanTrue global function. | 191 // Mock the setTestRanTrue global function. |
212 var mockGlobals = mock(MockGlobals); | 192 this.mockGlobals.expects(once()).setTestRanTrue(). |
213 registerMockGlobals(mockGlobals, MockGlobals); | |
214 mockGlobals.expects(once()).setTestRanTrue(). | |
215 will(runAllActionsAsync( | 193 will(runAllActionsAsync( |
216 WhenTestDone.ALWAYS, | 194 WhenTestDone.ALWAYS, |
217 callGlobalWithSavedArgs(null, 'setTestRanTrue'), | 195 callGlobalWithSavedArgs(null, 'setTestRanTrue'), |
218 callFunction(function() { | 196 callFunction(function() { |
219 assertTrue(testRan); | 197 assertTrue(testRan); |
220 }))); | 198 }))); |
221 | 199 |
222 // Cause setTestRanTrue to be invoked asynchronously. | 200 // Cause setTestRanTrue to be invoked asynchronously. |
223 chrome.send('callJS', ['setTestRanTrue']); | 201 chrome.send('callJS', ['setTestRanTrue']); |
224 | 202 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 * Test fixture for testing async tests are deferred until global is called. | 259 * Test fixture for testing async tests are deferred until global is called. |
282 * @constructor | 260 * @constructor |
283 */ | 261 */ |
284 function WebUIBrowserAsyncGenDeferredToGlobalTest() {} | 262 function WebUIBrowserAsyncGenDeferredToGlobalTest() {} |
285 | 263 |
286 WebUIBrowserAsyncGenDeferredToGlobalTest.prototype = { | 264 WebUIBrowserAsyncGenDeferredToGlobalTest.prototype = { |
287 __proto__: WebUIBrowserAsyncGenDeferredTest.prototype, | 265 __proto__: WebUIBrowserAsyncGenDeferredTest.prototype, |
288 | 266 |
289 /** @inheritDoc */ | 267 /** @inheritDoc */ |
290 setUp: function() { | 268 setUp: function() { |
291 /** | 269 this.makeAndRegisterMockGlobals(['setTestRanTrue']); |
292 * Create a mock class to describe the globals to mock. | 270 this.mockGlobals.expects(once()).setTestRanTrue(). |
293 * @constructor | |
294 */ | |
295 function MockGlobals() {} | |
296 | |
297 MockGlobals.prototype = { | |
298 setTestRanTrue: function() {}, | |
299 }; | |
300 | |
301 // Mock the setTestRanTrue global function. | |
302 var mockGlobals = mock(MockGlobals); | |
303 registerMockGlobals(mockGlobals, MockGlobals); | |
304 mockGlobals.expects(once()).setTestRanTrue(). | |
305 will(runAllActionsAsync( | 271 will(runAllActionsAsync( |
306 WhenTestDone.ALWAYS, | 272 WhenTestDone.ALWAYS, |
307 callGlobalWithSavedArgs(null, 'setTestRanTrue'), | 273 callGlobalWithSavedArgs(null, 'setTestRanTrue'), |
308 callFunction(deferRunTest))); | 274 callFunction(deferRunTest))); |
309 | 275 |
310 // Cause setTestRanTrue to be invoked asynchronously. | 276 // Cause setTestRanTrue to be invoked asynchronously. |
311 chrome.send('callJS', ['setTestRanTrue']); | 277 chrome.send('callJS', ['setTestRanTrue']); |
312 }, | 278 }, |
313 }; | 279 }; |
314 | 280 |
315 TEST_F('WebUIBrowserAsyncGenDeferredToGlobalTest', 'TestDeferRunTestToGlobal', | 281 TEST_F('WebUIBrowserAsyncGenDeferredToGlobalTest', 'TestDeferRunTestToGlobal', |
316 function() { | 282 function() { |
317 this.ranTest_ = true; | 283 this.ranTest_ = true; |
318 assertTrue(testRan); | 284 assertTrue(testRan); |
319 }); | 285 }); |
OLD | NEW |