44 const Timer =
CC(
"@mozilla.org/timer;1",
"nsITimer",
"initWithCallback");
66 var
ios =
Cc[
"@mozilla.org/network/io-service;1"]
67 .getService(
Ci.nsIIOService);
69 .QueryInterface(
Ci.nsIHttpChannel);
98 Ci.nsIFileInputStream.CLOSE_ON_EOF);
100 var contents = sis.read(
file.fileSize);
117 var
start = 0, index = 0;
120 index =
data.indexOf(
"\r\n");
122 yield
data.substring(0, index);
126 data = data.substring(index + 2);
145 for (var line in iter)
147 if (expectedLines.length == index)
148 throw "Error: got more than " + expectedLines.length +
" expected lines!";
150 var
expected = expectedLines[index++];
151 if (expected !== line)
152 throw "Error on line " + index +
"!\n" +
153 " actual: '" + line +
"',\n" +
154 " expect: '" + expected +
"'";
157 if (expectedLines.length !== index)
159 throw "Expected more lines! Got " + index +
160 ", expected " + expectedLines.length;
174 response.write(
"Method: " + request.method +
"\r\n");
175 response.write(
"Path: " + request.path +
"\r\n");
176 response.write(
"Query: " + request.queryString +
"\r\n");
177 response.write(
"Version: " + request.httpVersion +
"\r\n");
178 response.write(
"Scheme: " + request.scheme +
"\r\n");
179 response.write(
"Host: " + request.host +
"\r\n");
180 response.write(
"Port: " + request.port);
193 var line = iter.next();
209 if (e !== code && e.result !== code)
210 do_throw(
"unexpected error: " + e);
239 do_check_true(msecs >= 0);
241 var
start = Date.now();
246 do_check_true(index >= 0);
253 var end = Date.now();
254 var elapsed = end -
start;
255 if (elapsed >= msecs)
257 dumpn(
"*** TIMER FIRE " + elapsed +
"ms (" + msecs +
"ms requested)");
264 do_throw(
"exception thrown from callLater callback: " + e);
271 var newDelay = msecs - elapsed;
272 dumpn(
"*** TIMER UNDERSHOOT " + newDelay +
"ms " +
273 "(" + msecs +
"ms requested, delaying)");
294 return function complete()
297 srv.stop(
function quit() { do_test_finished(); });
322 function Test(
path, initChannel, onStartRequest, onStopRequest)
327 this.initChannel = initChannel || nil;
328 this.onStartRequest = onStartRequest || nil;
329 this.onStopRequest = onStopRequest || nil;
343 function performNextTest()
353 do_throw(
"error running test-completion callback: " + e);
364 test.initChannel(ch);
370 do_throw(
"testArray[" +
testIndex +
"].initChannel(ch) failed: " + e);
387 onStartRequest:
function(request, cx)
389 var ch = request.QueryInterface(
Ci.nsIHttpChannel)
390 .QueryInterface(
Ci.nsIHttpChannelInternal);
392 this._data.length = 0;
397 testArray[
testIndex].onStartRequest(ch, cx);
401 do_throw(
"testArray[" + testIndex +
"].onStartRequest: " + e);
406 dumpn(
"!!! swallowing onStartRequest exception so onStopRequest is " +
410 onDataAvailable:
function(request, cx, inputStream,
offset,
count)
412 Array.prototype.push.apply(this._data,
415 onStopRequest:
function(request, cx, status)
417 var ch = request.QueryInterface(
Ci.nsIHttpChannel)
418 .QueryInterface(
Ci.nsIHttpChannelInternal);
426 testArray[
testIndex].onStopRequest(ch, cx, status, this._data);
442 if (aIID.equals(
Ci.nsIStreamListener) ||
443 aIID.equals(
Ci.nsIRequestObserver) ||
444 aIID.equals(
Ci.nsISupports))
446 throw Cr.NS_ERROR_NO_INTERFACE;
478 if (0 > port || 65535 < port || port % 1 !== 0)
482 if (
data.length <= 0)
483 throw "bad data length";
484 if (!
data.every(
function(v) {
return /^[\x00-\xff]*$/.test(
data); }))
485 throw "bad data contained non-byte-valued character";
490 this.responseCheck = responseCheck;
505 var sts =
Cc[
"@mozilla.org/network/socket-transport-service;1"]
506 .getService(
Ci.nsISocketTransportService);
513 function performNextTest()
524 do_throw(
"error running test-completion callback: " + e);
533 sts.createTransport(
null, 0, rawTest.host, rawTest.port,
null);
535 var inStream = transport.openInputStream(0, 0, 0)
536 .QueryInterface(
Ci.nsIAsyncInputStream);
537 var outStream = transport.openOutputStream(0, 0, 0)
538 .QueryInterface(
Ci.nsIAsyncOutputStream);
544 waitForMoreInput(inStream);
545 waitToWriteOutput(outStream);
548 function waitForMoreInput(stream)
550 stream.asyncWait(reader, 0, 0, currentThread);
553 function waitToWriteOutput(stream)
555 stream.asyncWait(writer, 0, testArray[
testIndex].
data[dataIndex].length,
574 onInputStreamReady:
function(stream)
581 av = bis.available();
587 received +=
String.fromCharCode.apply(
null, bis.readByteArray(av));
588 waitForMoreInput(stream);
595 rawTest.responseCheck(received);
599 do_throw(
"error thrown by responseCheck: " + e);
612 onOutputStreamReady:
function(stream)
619 written = stream.write(data, data.length);
620 if (written == data.length)
623 testArray[
testIndex].data = data.substring(written);
629 waitToWriteOutput(stream);
GeneratorThread currentThread
do_check_eq(typeof PlacesUtils,"object")
function runHttpTests(testArray, done)
function skipHeaders(iter)
sbOSDControlService prototype QueryInterface
function expectLines(iter, expectedLines)
function runRawTests(testArray, done)
function fileContents(file)
function writeDetails(request, response)
function makeChannel(url)
function RawTest(host, port, data, responseCheck)
function testComplete(srv)
function Test(path, initChannel, onStartRequest, onStopRequest)
const ScriptableInputStream
function callLater(msecs, callback)
function LineIterator(data)
function isException(e, code)