1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
7 { data: "", chunks: [], status: Cr.NS_OK, consume: [], dataChunks: [""] },
13 dataChunks: ["TWO-", "PARTS", ""],
20 dataChunks: ["TWO-", "TWO-PARTS", "TWO-PARTS"],
27 dataChunks: ["3", "3-", "PARTS", ""],
34 dataChunks: ["ALL-AT-ONCE", "ALL-AT-ONCE"],
41 dataChunks: ["ALL-AT-ONCE", ""],
46 status: Cr.NS_ERROR_OUT_OF_MEMORY,
48 dataChunks: ["E", "E"],
54 * @property {string} data - data for the test.
55 * @property {Array} chunks - lengths of the chunks that are incrementally sent
57 * @property {number} status - final status sent on onStopRequest.
58 * @property {Array} consume - lengths of consumed data that is reported at
59 * the onIncrementalData callback.
60 * @property {Array} dataChunks - data chunks that are reported at the
61 * onIncrementalData and onStreamComplete callbacks.
64 function execute_test(test) {
65 let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
66 Ci.nsIStringInputStream
68 stream.data = test.data;
72 QueryInterface: ChromeUtils.generateQI(["nsIChannel"]),
78 onStreamComplete(loader, context, status, length, data) {
79 equal(chunkIndex, test.dataChunks.length - 1);
80 var expectedChunk = test.dataChunks[chunkIndex];
81 equal(length, expectedChunk.length);
82 equal(String.fromCharCode.apply(null, data), expectedChunk);
84 equal(status, test.status);
86 onIncrementalData(loader, context, length, data, consumed) {
87 Assert.less(chunkIndex, test.dataChunks.length - 1);
88 var expectedChunk = test.dataChunks[chunkIndex];
89 equal(length, expectedChunk.length);
90 equal(String.fromCharCode.apply(null, data), expectedChunk);
92 consumed.value = test.consume[chunkIndex];
95 QueryInterface: ChromeUtils.generateQI([
96 "nsIIncrementalStreamLoaderObserver",
101 "@mozilla.org/network/incremental-stream-loader;1"
102 ].createInstance(Ci.nsIIncrementalStreamLoader);
103 listener.init(observer);
105 listener.onStartRequest(channel);
107 test.chunks.forEach(function (chunkLength) {
108 listener.onDataAvailable(channel, stream, offset, chunkLength);
109 offset += chunkLength;
111 listener.onStopRequest(channel, test.status);
114 function run_test() {
115 tests.forEach(execute_test);