| 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 * @fileoverview Tests to ensure that chrome.send mocking works as expected. | 6 * @fileoverview Tests to ensure that chrome.send mocking works as expected. |
| 7 * @author scr@chromium.org (Sheridan Rawlins) | 7 * @author scr@chromium.org (Sheridan Rawlins) |
| 8 * @see test_api.js | 8 * @see test_api.js |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * @type {?string} | 25 * @type {?string} |
| 26 * @override | 26 * @override |
| 27 */ | 27 */ |
| 28 typedefCppFixture: null, | 28 typedefCppFixture: null, |
| 29 | 29 |
| 30 /** @inheritDoc */ | 30 /** @inheritDoc */ |
| 31 browsePreload: DUMMY_URL, | 31 browsePreload: DUMMY_URL, |
| 32 | 32 |
| 33 /** @inheritDoc */ | 33 /** @inheritDoc */ |
| 34 setUp: function() { | 34 setUp: function() { |
| 35 // Set up a mock handler class to catch the 'checkSend' message. | 35 this.makeAndRegisterMockHandler(['checkSend']); |
| 36 function MockHandler() {} | |
| 37 MockHandler.prototype = { | |
| 38 checkSend: function() {}, | |
| 39 }; | |
| 40 this.mockHandler = mock(MockHandler); | |
| 41 registerMockMessageCallbacks(this.mockHandler, MockHandler); | |
| 42 } | 36 } |
| 43 }; | 37 }; |
| 44 | 38 |
| 45 // Test that chrome.send can be mocked outside the preLoad method. | 39 // Test that chrome.send can be mocked outside the preLoad method. |
| 46 TEST_F('ChromeSendWebUITest', 'NotInPreload', function() { | 40 TEST_F('ChromeSendWebUITest', 'NotInPreload', function() { |
| 47 this.mockHandler.expects(once()).checkSend(); | 41 this.mockHandler.expects(once()).checkSend(); |
| 48 chrome.send('checkSend'); | 42 chrome.send('checkSend'); |
| 49 }); | 43 }); |
| 50 | 44 |
| 51 /** | 45 /** |
| 52 * Test fixture for chrome send WebUI testing with passthrough. | 46 * Test fixture for chrome send WebUI testing with passthrough. |
| 53 * @constructor | 47 * @constructor |
| 54 * @extends {ChromeSendWebUITest} | 48 * @extends {ChromeSendWebUITest} |
| 55 */ | 49 */ |
| 56 function ChromeSendPassthroughWebUITest() {} | 50 function ChromeSendPassthroughWebUITest() {} |
| 57 | 51 |
| 58 ChromeSendPassthroughWebUITest.prototype = { | 52 ChromeSendPassthroughWebUITest.prototype = { |
| 59 __proto__: ChromeSendWebUITest.prototype, | 53 __proto__: ChromeSendWebUITest.prototype, |
| 60 }; | 54 }; |
| 61 | 55 |
| 62 // Test that the mocked chrome.send can call the original. | 56 // Test that the mocked chrome.send can call the original. |
| 63 TEST_F('ChromeSendPassthroughWebUITest', 'CanCallOriginal', function() { | 57 TEST_F('ChromeSendPassthroughWebUITest', 'CanCallOriginal', function() { |
| 64 chrome.send('expectCheckSend'); | 58 chrome.send('expectCheckSend'); |
| 65 this.mockHandler.expects(once()).checkSend(). | 59 this.mockHandler.expects(once()).checkSend(). |
| 66 will(callFunction(function() { | 60 will(callFunction(function() { |
| 67 chrome.originalSend('checkSend'); | 61 chrome.originalSend('checkSend'); |
| 68 })); | 62 })); |
| 69 chrome.send('checkSend'); | 63 chrome.send('checkSend'); |
| 70 }); | 64 }); |
| OLD | NEW |