Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 var testStr = "This is a test. ";
2 for (var i = 0; i < 10; ++i) {
3 testStr += testStr;
4 }
6 function run_test() {
7 // Set up our stream to copy
8 var inStr = Cc["@mozilla.org/io/string-input-stream;1"]
9 .createInstance(Ci.nsIStringInputStream);
10 inStr.setData(testStr, testStr.length);
12 // Set up our destination stream. Make sure to use segments a good
13 // bit smaller than our data length.
14 do_check_true(testStr.length > 1024*10);
15 var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
16 pipe.init(true, true, 1024, 0xffffffff, null);
18 var streamCopier = Cc["@mozilla.org/network/async-stream-copier;1"]
19 .createInstance(Ci.nsIAsyncStreamCopier);
20 streamCopier.init(inStr, pipe.outputStream, null, true, true, 1024, true, true);
22 var ctx = {
23 };
24 ctx.wrappedJSObject = ctx;
26 var observer = {
27 onStartRequest: function(aRequest, aContext) {
28 do_check_eq(aContext.wrappedJSObject, ctx);
29 },
30 onStopRequest: function(aRequest, aContext, aStatusCode) {
31 do_check_eq(aStatusCode, 0);
32 do_check_eq(aContext.wrappedJSObject, ctx);
33 var sis =
34 Cc["@mozilla.org/scriptableinputstream;1"]
35 .createInstance(Ci.nsIScriptableInputStream);
36 sis.init(pipe.inputStream);
37 var result = "";
38 var temp;
39 try { // Need this because read() can throw at EOF
40 while ((temp = sis.read(1024))) {
41 result += temp;
42 }
43 } catch(e) {
44 do_check_eq(e.result, Components.results.NS_BASE_STREAM_CLOSED);
45 }
46 do_check_eq(result, testStr);
47 do_test_finished();
48 }
49 };
51 streamCopier.asyncCopy(observer, ctx);
52 do_test_pending();
53 }