B2G/gecko/netwerk/test/httpserver/test/head_utils.js
/**
 * Runs all the tests in testArray.
 *
 * @param testArray
 *   a non-empty array of Tests to run, in order
 * @param done
 *   function to call when all tests have run (e.g. to shut down the server)
 */
Runs all the tests in testArray.
@param testArray
a non-empty array of Tests to run, in order
@param done
function to call when all tests have run
Runs all the tests in testArray . @param testArray a non - empty array of Tests to run in order @param done function to call when all tests have run
function runHttpTests(testArray, done)
{
  function performNextTest()
  {
    if (++testIndex == testArray.length)
    {
      try
      {
        done();
      }
      catch (e)
      {
        do_report_unexpected_exception(e, "running test-completion callback");
      }
      return;
    }
    do_test_pending();
    var test = testArray[testIndex];
    var ch = makeChannel(test.path);
    try
    {
      test.initChannel(ch);
    }
    catch (e)
    {
      try
      {
        do_report_unexpected_exception(e, "testArray[" + testIndex + "].initChannel(ch)");
      }
      catch (e)
      {
      }
    }
    listener._channel = ch;
    ch.asyncOpen(listener, null);
  }
  var testIndex = -1;
  var listener =
    {
      _channel: null,
      _data: [],
      onStartRequest: function(request, cx)
      {
        do_check_true(request === this._channel);
        var ch = request.QueryInterface(Ci.nsIHttpChannel)
                        .QueryInterface(Ci.nsIHttpChannelInternal);
        this._data.length = 0;
        try
        {
          try
          {
            testArray[testIndex].onStartRequest(ch, cx);
          }
          catch (e)
          {
            do_report_unexpected_exception(e, "testArray[" + testIndex + "].onStartRequest");
          }
        }
        catch (e)
        {
          do_note_exception(e, "!!! swallowing onStartRequest exception so onStopRequest is " +
                "called...");
        }
      },
      onDataAvailable: function(request, cx, inputStream, offset, count)
      {
        var quantum = 262144; 
        var bis = makeBIS(inputStream);
        for (var start = 0; start < count; start += quantum)
        {
          var newData = bis.readByteArray(Math.min(quantum, count - start));
          Array.prototype.push.apply(this._data, newData);
        }
      },
      onStopRequest: function(request, cx, status)
      {
        this._channel = null;
        var ch = request.QueryInterface(Ci.nsIHttpChannel)
                        .QueryInterface(Ci.nsIHttpChannelInternal);
        try
        {
          testArray[testIndex].onStopRequest(ch, cx, status, this._data);
        }
        finally
        {
          try
          {
            performNextTest();
          }
          finally
          {
            do_test_finished();
          }
        }
      },
      QueryInterface: function(aIID)
      {
        if (aIID.equals(Ci.nsIStreamListener) ||
            aIID.equals(Ci.nsIRequestObserver) ||
            aIID.equals(Ci.nsISupports))
          return this;
        throw Cr.NS_ERROR_NO_INTERFACE;
      }
    };
  performNextTest();
}
function runHttpTests ( testArray , done ) { function performNextTest ( ) { if ( ++ testIndex == testArray . length ) { try { done ( ) ; } catch ( e ) { do_report_unexpected_exception ( e , "running test-completion callback" ) ; } return ; } do_test_pending ( ) ; var test = testArray [ testIndex ] ; var ch = makeChannel ( test . path ) ; try { test . initChannel ( ch ) ; } catch ( e ) { try { do_report_unexpected_exception ( e , "testArray[" + testIndex + "].initChannel(ch)" ) ; } catch ( e ) { } } listener . _channel = ch ; ch . asyncOpen ( listener , null ) ; } var testIndex = - 1 ; var listener = { _channel : null , _data : [ ] , onStartRequest : function ( request , cx ) { do_check_true ( request === this . _channel ) ; var ch = request . QueryInterface ( Ci . nsIHttpChannel ) . QueryInterface ( Ci . nsIHttpChannelInternal ) ; this . _data . length = 0 ; try { try { testArray [ testIndex ] . onStartRequest ( ch , cx ) ; } catch ( e ) { do_report_unexpected_exception ( e , "testArray[" + testIndex + "].onStartRequest" ) ; } } catch ( e ) { do_note_exception ( e , "!!! swallowing onStartRequest exception so onStopRequest is " + "called..." ) ; } } , onDataAvailable : function ( request , cx , inputStream , offset , count ) { var quantum = 262144 ; var bis = makeBIS ( inputStream ) ; for ( var start = 0 ; start < count ; start += quantum ) { var newData = bis . readByteArray ( Math . min ( quantum , count - start ) ) ; Array . prototype . push . apply ( this . _data , newData ) ; } } , onStopRequest : function ( request , cx , status ) { this . _channel = null ; var ch = request . QueryInterface ( Ci . nsIHttpChannel ) . QueryInterface ( Ci . nsIHttpChannelInternal ) ; try { testArray [ testIndex ] . onStopRequest ( ch , cx , status , this . _data ) ; } finally { try { performNextTest ( ) ; } finally { do_test_finished ( ) ; } } } , QueryInterface : function ( aIID ) { if ( aIID . equals ( Ci . nsIStreamListener ) || aIID . equals ( Ci . nsIRequestObserver ) || aIID . equals ( Ci . nsISupports ) ) return this ; throw Cr . NS_ERROR_NO_INTERFACE ; } } ; performNextTest ( ) ; }
Runs all the tests in testArray.
Runs all the tests in testArray .
/** Kicks off running the next test in the array. */ /* swallow and let tests continue */ /** Index of the test being run. */ /** Stream listener for the channels. */ /** Current channel being observed by this. */ /** Array of bytes of data in body of response. */ // just above half the argument-count limit // NB: The onStopRequest callback must run before performNextTest here, //     because the latter runs the next test's initChannel callback, and //     we want one test to be sequentially processed before the next //     one.