/** * @typedef TestData * @property {string} data - data for the test. * @property {Array} chunks - lengths of the chunks that are incrementally sent * to the loader. * @property {number} status - final status sent on onStopRequest. * @property {Array} consume - lengths of consumed data that is reported at * the onIncrementalData callback. * @property {Array} dataChunks - data chunks that are reported at the * onIncrementalData and onStreamComplete callbacks.
*/
function execute_test(test) {
let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
Ci.nsIStringInputStream
);
stream.setByteStringData(test.data);
let contentTypeCalled = 0;
let channel = {
contentLength: -1,
QueryInterface: ChromeUtils.generateQI(["nsIChannel"]),
get contentType() {
contentTypeCalled++; return"application/test";
},
};
let chunkIndex = 0;
let observer = {
onStartRequest(request) { const chan = request.QueryInterface(Ci.nsIChannel); const before = contentTypeCalled; const type = chan.contentType; const after = contentTypeCalled;
equal(type, "application/test");
equal(after, before + 1);
},
onStreamComplete(loader, context, status, length, data) {
equal(chunkIndex, test.dataChunks.length - 1); var expectedChunk = test.dataChunks[chunkIndex];
equal(length, expectedChunk.length);
equal(String.fromCharCode.apply(null, data), expectedChunk);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.