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