B2G/gecko/testing/mochitest/tests/SimpleTest/MockObjects.js
/**
   * Replaces the current factory with one that returns a new mock object.
   *
   * After register() has been called, it is mandatory to call unregister() to
   * restore the original component. Usually, you should use a try-catch block
   * to ensure that unregister() is called.
   */
Replaces the current factory with one that returns a new mock object.
After register() has been called, it is mandatory to call unregister() to
restore the original component. Usually, you should use a try-catch block
to ensure that unregister() is called.
Replaces the current factory with one that returns a new mock object . After register () has been called it is mandatory to call unregister () to restore the original component . Usually you should use a try - catch block to ensure that unregister () is called .
function MOR_register() {
    if (this._originalFactory)
      throw new Exception("Invalid object state when calling register()");
    var providedConstructor = this._replacementCtor;
    this._mockFactory = {
      createInstance: function MF_createInstance(aOuter, aIid) {
        if (aOuter != null)
          throw SpecialPowers.Cr.NS_ERROR_NO_AGGREGATION;
        return new providedConstructor().QueryInterface(aIid);
      }
    };
    var retVal = SpecialPowers.swapFactoryRegistration(this._cid, this._contractID, this._mockFactory, this._originalFactory);
    if ('error' in retVal) {
      throw new Exception("ERROR: " + retVal.error);
    } else {
      this._cid = retVal.cid;
      this._originalFactory = retVal.originalFactory;
    }
  }
function MOR_register ( ) { if ( this . _originalFactory ) throw new Exception ( "Invalid object state when calling register()" ) ; var providedConstructor = this . _replacementCtor ; this . _mockFactory = { createInstance : function MF_createInstance ( aOuter , aIid ) { if ( aOuter != null ) throw SpecialPowers . Cr . NS_ERROR_NO_AGGREGATION ; return new providedConstructor ( ) . QueryInterface ( aIid ) ; } } ; var retVal = SpecialPowers . swapFactoryRegistration ( this . _cid , this . _contractID , this . _mockFactory , this . _originalFactory ) ; if ( 'error' in retVal ) { throw new Exception ( "ERROR: " + retVal . error ) ; } else { this . _cid = retVal . cid ; this . _originalFactory = retVal . originalFactory ; } }
Replaces the current factory with one that returns a new mock object.
Replaces the current factory with one that returns a new mock object .
// Define a factory that creates a new object using the given constructor.