B2G/gecko/testing/marionette/marionette-listener.js
/**
 * Returns a content sandbox that can be used by the execute_foo functions.
 */
Returns a content sandbox that can be used by the execute_foo functions.
Returns a content sandbox that can be used by the execute_foo functions .
function createExecuteContentSandbox(aWindow, timeout) {
  let sandbox = new Cu.Sandbox(aWindow, {sandboxPrototype: aWindow});
  sandbox.global = sandbox;
  sandbox.window = aWindow;
  sandbox.document = sandbox.window.document;
  sandbox.navigator = sandbox.window.navigator;
  sandbox.testUtils = utils;
  sandbox.asyncTestCommandId = asyncTestCommandId;
  let marionette = new Marionette(this, aWindow, "content",
                                  marionetteLogObj,
                                  timeout, marionetteTestName);
  sandbox.marionette = marionette;
  marionette.exports.forEach(function(fn) {
    try {
      sandbox[fn] = marionette[fn].bind(marionette);
    }
    catch(e) {
      sandbox[fn] = marionette[fn];
    }
  });
  XPCOMUtils.defineLazyGetter(sandbox, 'SpecialPowers', function() {
    return new SpecialPowers(aWindow);
  });
  sandbox.asyncComplete = function sandbox_asyncComplete(value, status, stack, commandId) {
    if (commandId == asyncTestCommandId) {
      curWindow.removeEventListener("unload", onunload, false);
      curWindow.clearTimeout(asyncTestTimeoutId);
      sendSyncMessage("Marionette:shareData", {log: elementManager.wrapValue(marionetteLogObj.getLogs())});
      marionetteLogObj.clearLogs();
      if (status == 0){
        if (Object.keys(_emu_cbs).length) {
          _emu_cbs = {};
          sendError("Emulator callback still pending when finish() called",
                    500, null, commandId);
        }
        else {
          sendResponse({value: elementManager.wrapValue(value), status: status},
                       commandId);
        }
      }
      else {
        sendError(value, status, stack, commandId);
      }
      asyncTestRunning = false;
      asyncTestTimeoutId = undefined;
      asyncTestCommandId = undefined;
    }
  };
  sandbox.finish = function sandbox_finish() {
    if (asyncTestRunning) {
      sandbox.asyncComplete(marionette.generate_results(), 0, null, sandbox.asyncTestCommandId);
    } else {
      return marionette.generate_results();
    }
  };
  sandbox.marionetteScriptFinished = function sandbox_marionetteScriptFinished(value) {
    return sandbox.asyncComplete(value, 0, null, sandbox.asyncTestCommandId);
  };
  return sandbox;
}
function createExecuteContentSandbox ( aWindow , timeout ) { let sandbox = new Cu . Sandbox ( aWindow , { sandboxPrototype : aWindow } ) ; sandbox . global = sandbox ; sandbox . window = aWindow ; sandbox . document = sandbox . window . document ; sandbox . navigator = sandbox . window . navigator ; sandbox . testUtils = utils ; sandbox . asyncTestCommandId = asyncTestCommandId ; let marionette = new Marionette ( this , aWindow , "content" , marionetteLogObj , timeout , marionetteTestName ) ; sandbox . marionette = marionette ; marionette . exports . forEach ( function ( fn ) { try { sandbox [ fn ] = marionette [ fn ] . bind ( marionette ) ; } catch ( e ) { sandbox [ fn ] = marionette [ fn ] ; } } ) ; XPCOMUtils . defineLazyGetter ( sandbox , 'SpecialPowers' , function ( ) { return new SpecialPowers ( aWindow ) ; } ) ; sandbox . asyncComplete = function sandbox_asyncComplete ( value , status , stack , commandId ) { if ( commandId == asyncTestCommandId ) { curWindow . removeEventListener ( "unload" , onunload , false ) ; curWindow . clearTimeout ( asyncTestTimeoutId ) ; sendSyncMessage ( "Marionette:shareData" , { log : elementManager . wrapValue ( marionetteLogObj . getLogs ( ) ) } ) ; marionetteLogObj . clearLogs ( ) ; if ( status == 0 ) { if ( Object . keys ( _emu_cbs ) . length ) { _emu_cbs = { } ; sendError ( "Emulator callback still pending when finish() called" , 500 , null , commandId ) ; } else { sendResponse ( { value : elementManager . wrapValue ( value ) , status : status } , commandId ) ; } } else { sendError ( value , status , stack , commandId ) ; } asyncTestRunning = false ; asyncTestTimeoutId = undefined ; asyncTestCommandId = undefined ; } } ; sandbox . finish = function sandbox_finish ( ) { if ( asyncTestRunning ) { sandbox . asyncComplete ( marionette . generate_results ( ) , 0 , null , sandbox . asyncTestCommandId ) ; } else { return marionette . generate_results ( ) ; } } ; sandbox . marionetteScriptFinished = function sandbox_marionetteScriptFinished ( value ) { return sandbox . asyncComplete ( value , 0 , null , sandbox . asyncTestCommandId ) ; } ; return sandbox ; }
Returns a content sandbox that can be used by the execute_foo functions.
Returns a content sandbox that can be used by the execute_foo functions .