Chromium Code Reviews| 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 */ | 108 var mockHandler = this.mockHandler; |
| 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 | 109 |
| 120 // Bind some arguments. | 110 // Bind some arguments. |
| 121 var var1, var2; | 111 var var1, var2; |
| 122 mockHandler.expects(once()).testBoundArgs(). | 112 mockHandler.expects(once()).testBoundArgs(). |
| 123 will(runAllActionsAsync(WhenTestDone.DEFAULT, | 113 will(runAllActionsAsync(WhenTestDone.DEFAULT, |
| 124 callFunction(function(args) { | 114 callFunction(function(args) { |
| 125 var1 = args[0]; | 115 var1 = args[0]; |
| 126 }, ['val1']), | 116 }, ['val1']), |
| 127 callFunction(function(args) { | 117 callFunction(function(args) { |
| 128 var2 = args[0]; | 118 var2 = args[0]; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 181 |
| 192 /** | 182 /** |
| 193 * Set |testRan| to true. | 183 * Set |testRan| to true. |
| 194 */ | 184 */ |
| 195 function setTestRanTrue() { | 185 function setTestRanTrue() { |
| 196 testRan = true; | 186 testRan = true; |
| 197 } | 187 } |
| 198 | 188 |
| 199 // Test overriding globals. | 189 // Test overriding globals. |
| 200 TEST_F('WebUIBrowserAsyncGenTest', 'TestRegisterMockGlobals', function() { | 190 TEST_F('WebUIBrowserAsyncGenTest', 'TestRegisterMockGlobals', function() { |
| 201 /** | 191 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 | 192 |
| 211 // Mock the setTestRanTrue global function. | 193 // Mock the setTestRanTrue global function. |
| 212 var mockGlobals = mock(MockGlobals); | 194 var mockGlobals = this.mockGlobals; |
| 213 registerMockGlobals(mockGlobals, MockGlobals); | |
| 214 mockGlobals.expects(once()).setTestRanTrue(). | 195 mockGlobals.expects(once()).setTestRanTrue(). |
| 215 will(runAllActionsAsync( | 196 will(runAllActionsAsync( |
| 216 WhenTestDone.ALWAYS, | 197 WhenTestDone.ALWAYS, |
| 217 callGlobalWithSavedArgs(null, 'setTestRanTrue'), | 198 callGlobalWithSavedArgs(null, 'setTestRanTrue'), |
| 218 callFunction(function() { | 199 callFunction(function() { |
| 219 assertTrue(testRan); | 200 assertTrue(testRan); |
| 220 }))); | 201 }))); |
| 221 | 202 |
| 222 // Cause setTestRanTrue to be invoked asynchronously. | 203 // Cause setTestRanTrue to be invoked asynchronously. |
| 223 chrome.send('callJS', ['setTestRanTrue']); | 204 chrome.send('callJS', ['setTestRanTrue']); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 * Test fixture for testing async tests are deferred until global is called. | 262 * Test fixture for testing async tests are deferred until global is called. |
| 282 * @constructor | 263 * @constructor |
| 283 */ | 264 */ |
| 284 function WebUIBrowserAsyncGenDeferredToGlobalTest() {} | 265 function WebUIBrowserAsyncGenDeferredToGlobalTest() {} |
| 285 | 266 |
| 286 WebUIBrowserAsyncGenDeferredToGlobalTest.prototype = { | 267 WebUIBrowserAsyncGenDeferredToGlobalTest.prototype = { |
| 287 __proto__: WebUIBrowserAsyncGenDeferredTest.prototype, | 268 __proto__: WebUIBrowserAsyncGenDeferredTest.prototype, |
| 288 | 269 |
| 289 /** @inheritDoc */ | 270 /** @inheritDoc */ |
| 290 setUp: function() { | 271 setUp: function() { |
| 291 /** | 272 this.makeAndRegisterMockGlobals(['setTestRanTrue']); |
| 292 * Create a mock class to describe the globals to mock. | 273 var mockGlobals = this.mockGlobals; |
|
James Hawkins
2011/11/09 17:15:56
Why are you using both this.mockGlobals and local
James Hawkins
2011/11/10 00:24:43
Is there a reason you keep ignoring this question?
Sheridan Rawlins
2011/11/10 02:02:12
no & done.
| |
| 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(). | 274 mockGlobals.expects(once()).setTestRanTrue(). |
| 305 will(runAllActionsAsync( | 275 will(runAllActionsAsync( |
| 306 WhenTestDone.ALWAYS, | 276 WhenTestDone.ALWAYS, |
| 307 callGlobalWithSavedArgs(null, 'setTestRanTrue'), | 277 callGlobalWithSavedArgs(null, 'setTestRanTrue'), |
| 308 callFunction(deferRunTest))); | 278 callFunction(deferRunTest))); |
| 309 | 279 |
| 310 // Cause setTestRanTrue to be invoked asynchronously. | 280 // Cause setTestRanTrue to be invoked asynchronously. |
| 311 chrome.send('callJS', ['setTestRanTrue']); | 281 chrome.send('callJS', ['setTestRanTrue']); |
| 312 }, | 282 }, |
| 313 }; | 283 }; |
| 314 | 284 |
| 315 TEST_F('WebUIBrowserAsyncGenDeferredToGlobalTest', 'TestDeferRunTestToGlobal', | 285 TEST_F('WebUIBrowserAsyncGenDeferredToGlobalTest', 'TestDeferRunTestToGlobal', |
| 316 function() { | 286 function() { |
| 317 this.ranTest_ = true; | 287 this.ranTest_ = true; |
| 318 assertTrue(testRan); | 288 assertTrue(testRan); |
| 319 }); | 289 }); |
| OLD | NEW |