chrome/os/inputview/testing/mock_extension_api.js
/**
 * Adds mocks for chrome extension API calls.
 *
 * @param {goog.testing.MockControl} mockControl Controller for validating
 *     calls with expectations.
 */
Adds mocks for chrome extension API calls.
@param {goog.testing.MockControl} mockControl Controller for validating
calls with expectations.
Adds mocks for chrome extension API calls . @param { goog . testing . MockControl } mockControl Controller for validating calls with expectations .
function mockExtensionApis(mockControl) {
  var addMocks = function(base, name, methods) {
    base[name] = {};
    methods.forEach(function(m) {
      var fn = base[name][m] = mockControl.createFunctionMock(m);
      fn.$callbackData = function(args) {
        fn().$anyTimes().$does(function(callback) {
          callback.call(undefined, args);
        });
        fn.$verifyCall = function(currentExpectation, name, args) {
          return args.length == 1 && typeof args[0] == 'function';
        };
      };
    });
  };
  addMocks(chrome, 'virtualKeyboardPrivate', ['getKeyboardConfig']);
  addMocks(chrome, 'inputMethodPrivate', ['getInputMethods',
      'setCurrentInputMethod']);
  addMocks(chrome, 'runtime', ['getBackgroundPage']);
  addMocks(chrome.runtime, 'onMessage', ['addListener']);
  chrome.runtime.sendMessage = function(msg) {};
  chrome.runtime.onMessage.addListener = function() {};
}
function mockExtensionApis ( mockControl ) { var addMocks = function ( base , name , methods ) { base [ name ] = { } ; methods . forEach ( function ( m ) { var fn = base [ name ] [ m ] = mockControl . createFunctionMock ( m ) ; fn . $callbackData = function ( args ) { fn ( ) . $anyTimes ( ) . $does ( function ( callback ) { callback . call ( undefined , args ) ; } ) ; fn . $verifyCall = function ( currentExpectation , name , args ) { return args . length == 1 && typeof args [ 0 ] == 'function' ; } ; } ; } ) ; } ; addMocks ( chrome , 'virtualKeyboardPrivate' , [ 'getKeyboardConfig' ] ) ; addMocks ( chrome , 'inputMethodPrivate' , [ 'getInputMethods' , 'setCurrentInputMethod' ] ) ; addMocks ( chrome , 'runtime' , [ 'getBackgroundPage' ] ) ; addMocks ( chrome . runtime , 'onMessage' , [ 'addListener' ] ) ; chrome . runtime . sendMessage = function ( msg ) { } ; chrome . runtime . onMessage . addListener = function ( ) { } ; }
Adds mocks for chrome extension API calls.
Adds mocks for chrome extension API calls .
// Method to arm triggering a callback function with the specified // arguments. As it is awkward to require an exact signature match for // methods with a callback, the verification process is relaxed to simply // require that the sole argument is a function for each recorded call. // Ignore the sendMessage first, added it back when we need to check the // message calls. // Ignore calls to addListener. Reevaluate if important to properly track the // flow of events.