Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Mocks for globals needed for loading background.js. | 5 // Mocks for globals needed for loading background.js. |
| 6 | 6 |
| 7 function emptyMock() {} | 7 function emptyMock() {} |
| 8 function buildTaskManager() { | 8 function buildTaskManager() { |
| 9 return {instrumentApiFunction: emptyMock}; | 9 return { |
| 10 debugSetStepName: emptyMock, | |
| 11 instrumentApiFunction: emptyMock, | |
| 12 }; | |
| 10 } | 13 } |
| 11 var instrumentApiFunction = emptyMock; | 14 var instrumentApiFunction = emptyMock; |
| 12 var buildAttemptManager = emptyMock; | 15 var buildAttemptManager = emptyMock; |
| 13 var emptyListener = {addListener: emptyMock}; | 16 var emptyListener = {addListener: emptyMock}; |
| 14 chrome['location'] = {onLocationUpdate: emptyListener}; | 17 chrome['location'] = { |
| 18 onLocationUpdate: emptyListener, | |
| 19 }; | |
| 15 chrome['notifications'] = { | 20 chrome['notifications'] = { |
| 16 onButtonClicked: emptyListener, | 21 onButtonClicked: emptyListener, |
| 17 onClicked: emptyListener, | 22 onClicked: emptyListener, |
| 18 onClosed: emptyListener | 23 onClosed: emptyListener |
| 19 }; | 24 }; |
| 20 chrome['omnibox'] = {onInputEntered: emptyListener}; | 25 chrome['omnibox'] = {onInputEntered: emptyListener}; |
| 26 chrome['preferencesPrivate'] = { | |
| 27 googleGeolocationAccessEnabled: { | |
| 28 onChange: emptyListener | |
| 29 } | |
| 30 }; | |
| 21 chrome['runtime'] = { | 31 chrome['runtime'] = { |
| 22 onInstalled: emptyListener, | 32 onInstalled: emptyListener, |
| 23 onStartup: emptyListener | 33 onStartup: emptyListener |
| 24 }; | 34 }; |
| 25 | 35 |
| 26 var storage = {}; | 36 var storage = {}; |
| 27 | 37 |
| 28 /** | 38 /** |
| 29 * Syntactic sugar for use with will() on a Mock4JS.Mock. | 39 * Syntactic sugar for use with will() on a Mock4JS.Mock. |
| 30 * Creates an action for will() that invokes a callback that the tested code | 40 * Creates an action for will() that invokes a callback that the tested code |
| 31 * passes to a mocked function. | 41 * passes to a mocked function. |
| 32 * @param {SaveMockArguments} savedArgs Arguments that will contain the | 42 * @param {SaveMockArguments} savedArgs Arguments that will contain the |
| 33 * callback once the mocked function is called. | 43 * callback once the mocked function is called. |
| 34 * @param {number} callbackParameter Index of the callback parameter in | 44 * @param {number} callbackParameter Index of the callback parameter in |
| 35 * |savedArgs|. | 45 * |savedArgs|. |
| 36 * @param {...Object} var_args Arguments to pass to the callback. | 46 * @param {...Object} var_args Arguments to pass to the callback. |
| 37 * @return {CallFunctionAction} Action for use in will(). | 47 * @return {CallFunctionAction} Action for use in will(). |
| 38 */ | 48 */ |
| 39 function invokeCallback(savedArgs, callbackParameter, var_args) { | 49 function invokeCallback(savedArgs, callbackParameter, var_args) { |
| 40 var callbackArguments = Array.prototype.slice.call(arguments, 2); | 50 var callbackArguments = Array.prototype.slice.call(arguments, 2); |
| 41 return callFunction(function() { | 51 return callFunction(function() { |
| 42 savedArgs.arguments[callbackParameter].apply(null, callbackArguments); | 52 savedArgs.arguments[callbackParameter].apply(null, callbackArguments); |
| 53 | |
| 54 // Mock4JS does not clear the saved args after invocation. | |
| 55 // To allow reuse of the same SaveMockArguments for multiple | |
| 56 // invocations with similar arguments, clear them here. | |
| 57 savedArgs.arguments.splice(0, savedArgs.arguments.length); | |
|
vadimt
2013/07/26 01:54:01
Why not savedArgs.arguments = []?
robliao
2013/07/26 08:11:23
It is tempting to do that, but savedArgs.arguments
| |
| 43 }); | 58 }); |
| 44 } | 59 } |
| 45 | 60 |
| 46 /** | 61 /** |
| 47 * Mock4JS matcher object that matches the actual agrument and the expected | 62 * Mock4JS matcher object that matches the actual agrument and the expected |
| 48 * value iff their JSON represenations are same. | 63 * value iff their JSON represenations are same. |
| 49 * @param {Object} expectedValue Expected value. | 64 * @param {Object} expectedValue Expected value. |
| 50 * @constructor | 65 * @constructor |
| 51 */ | 66 */ |
| 52 function MatchJSON(expectedValue) { | 67 function MatchJSON(expectedValue) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 75 }; | 90 }; |
| 76 | 91 |
| 77 /** | 92 /** |
| 78 * Builds a MatchJSON agrument matcher for a given expected value. | 93 * Builds a MatchJSON agrument matcher for a given expected value. |
| 79 * @param {Object} expectedValue Expected value. | 94 * @param {Object} expectedValue Expected value. |
| 80 * @return {MatchJSON} Resulting Mock4JS matcher. | 95 * @return {MatchJSON} Resulting Mock4JS matcher. |
| 81 */ | 96 */ |
| 82 function eqJSON(expectedValue) { | 97 function eqJSON(expectedValue) { |
| 83 return new MatchJSON(expectedValue); | 98 return new MatchJSON(expectedValue); |
| 84 } | 99 } |
| OLD | NEW |