head_utils.js File Reference

Go to the source code of this file.

Functions

 do_load_httpd_js ()
 
function createServer ()
 
function makeChannel (url)
 
function makeBIS (stream)
 
function fileContents (file)
 
function LineIterator (data)
 
function expectLines (iter, expectedLines)
 
function writeDetails (request, response)
 
function skipHeaders (iter)
 
function isException (e, code)
 
function callLater (msecs, callback)
 
function testComplete (srv)
 
function Test (path, initChannel, onStartRequest, onStopRequest)
 
function runHttpTests (testArray, done)
 
function RawTest (host, port, data, responseCheck)
 
function runRawTests (testArray, done)
 

Variables

 DEBUG = true
 
const Timer = CC("@mozilla.org/timer;1", "nsITimer", "initWithCallback")
 
var __pendingTimers = []
 
const __timerFuzz = 15
 

Function Documentation

function callLater (   msecs,
  callback 
)

Calls the given function at least the specified number of milliseconds later. The callback will not undershoot the given time, but it might overshoot – don't expect precision!

Parameters
milliseconds: uint the number of milliseconds to delay
callback: function() : void the function to call

Definition at line 237 of file head_utils.js.

Here is the call graph for this function:

Here is the caller graph for this function:

function createServer ( )

Constructs a new nsHttpServer instance. This function is intended to encapsulate construction of a server so that at some point in the future it is possible to run these tests (with at most slight modifications) against the server when used as an XPCOM component (not as an inline script).

Definition at line 53 of file head_utils.js.

Here is the call graph for this function:

Here is the caller graph for this function:

do_load_httpd_js ( )
function expectLines (   iter,
  expectedLines 
)

Throws if iter does not contain exactly the CRLF-separated lines in the array expectedLines.

Parameters
iter: Iterator an Iterator which returns lines of text
expectedLines: [string] an array of the expected lines of text
Exceptions
stringan error message if iter doesn't agree with expectedLines

Definition at line 142 of file head_utils.js.

Here is the caller graph for this function:

function fileContents (   file)

Returns the contents of the file as a string.

Parameters
file: nsILocalFile the file whose contents are to be read
Returns
string the contents of the file

Definition at line 94 of file head_utils.js.

Here is the caller graph for this function:

function isException (   e,
  code 
)

Checks that the exception e (which may be an XPConnect-created exception object or a raw nsresult number) is the given nsresult.

Parameters
e: Exception or nsresult the actual exception
code: nsresult the expected exception

Definition at line 207 of file head_utils.js.

Here is the caller graph for this function:

function LineIterator (   data)

Iterates over the lines, delimited by CRLF, in data, returning each line without the trailing line separator.

Parameters
data: string a string consisting of lines of data separated by CRLFs
Returns
Iterator an Iterator which returns each line from data in turn; note that this includes a final empty line if data ended with a CRLF

Definition at line 115 of file head_utils.js.

Here is the call graph for this function:

Here is the caller graph for this function:

function makeBIS (   stream)

Make a binary input stream wrapper for the given stream.

Parameters
streamthe nsIInputStream to wrap

Definition at line 80 of file head_utils.js.

Here is the caller graph for this function:

function makeChannel (   url)

Creates a new HTTP channel.

Parameters
urlthe URL of the channel to create

Definition at line 64 of file head_utils.js.

Here is the call graph for this function:

Here is the caller graph for this function:

function RawTest (   host,
  port,
  data,
  responseCheck 
)

Sends a raw string of bytes to the given host and port and checks that the response is acceptable.

Parameters
host: string the host to which a connection should be made
port: PRUint16 the port to use for the connection
data: string or [string...] either:
  • the raw data to send, as a string of characters with codes in the range 0-255, or
  • an array of such strings whose concatenation forms the raw data
responseCheck: function(string) : void a function which is provided with the data sent by the remote host which conducts whatever tests it wants on that data; useful for tweaking the test environment between tests

Definition at line 476 of file head_utils.js.

function runHttpTests (   testArray,
  done 
)

Runs all the tests in testArray.

Parameters
testArraya non-empty array of Tests to run, in order
donefunction to call when all tests have run (e.g. to shut down the server)

Kicks off running the next test in the array.

Index of the test being run.

Stream listener for the channels.

Array of bytes of data in body of response.

Definition at line 340 of file head_utils.js.

Here is the call graph for this function:

Here is the caller graph for this function:

function runRawTests (   testArray,
  done 
)

Runs all the tests in testArray, an array of RawTests.

Parameters
testArray: [RawTest] an array of RawTests to run, in order
donefunction to call when all tests have run (e.g. to shut down the server)

Kicks off running the next test in the array.

Index of the test being run.

Index of remaining data strings to be written to the socket in current test.

Data received so far from the server.

Reads data from the socket.

Writes data to the socket.

Definition at line 501 of file head_utils.js.

Here is the caller graph for this function:

function skipHeaders (   iter)

Advances iter past all non-blank lines and a single blank line, after which point the body of the response will be returned next from the iterator.

Parameters
iter: Iterator an iterator over the CRLF-delimited lines in an HTTP response, currently just after the Request-Line

Definition at line 191 of file head_utils.js.

Here is the caller graph for this function:

function Test (   path,
  initChannel,
  onStartRequest,
  onStopRequest 
)

Represents a path to load from the tested HTTP server, along with actions to take before, during, and after loading the associated page.

Parameters
paththe URL to load from the server
initChannela function which takes as a single parameter a channel created for path and initializes its state, or null if no additional initialization is needed
onStartRequestcalled during onStartRequest for the load of the URL, with the same parameters; the request parameter has been QI'd to nsIHttpChannel and nsIHttpChannelInternal for convenience; may be null if nothing needs to be done
onStopRequestcalled during onStopRequest for the channel, with the same parameters plus a trailing parameter containing an array of the bytes of data downloaded in the body of the channel response; the request parameter has been QI'd to nsIHttpChannel and nsIHttpChannelInternal for convenience; may be null if nothing needs to be done

Definition at line 322 of file head_utils.js.

Here is the caller graph for this function:

function testComplete (   srv)

Create a completion callback which will stop the given server and end the test, assuming nothing else remains to be done at that point.

Definition at line 292 of file head_utils.js.

Here is the caller graph for this function:

function writeDetails (   request,
  response 
)

Spew a bunch of HTTP metadata from request into the body of response.

Parameters
request: nsIHttpRequestMetadata the request whose metadata should be output
response: nsIHttpResponse the response to which the metadata is written

Definition at line 172 of file head_utils.js.

Here is the caller graph for this function:

Variable Documentation

var __pendingTimers = []

Pending timers used by callLater, which must store them to avoid the timer being canceled and destroyed. Stupid API...

Definition at line 217 of file head_utils.js.

const __timerFuzz = 15

Date.now() is not necessarily monotonically increasing (insert sob story about times not being the right tool to use for measuring intervals of time, robarnold can tell all), so be wary of error by erring by at least __timerFuzz ms.

Definition at line 225 of file head_utils.js.

DEBUG = true

Definition at line 42 of file head_utils.js.

const Timer = CC("@mozilla.org/timer;1", "nsITimer", "initWithCallback")

Definition at line 44 of file head_utils.js.