From 8d38ea0f4bf805ab7d04b9355910a0e15149da42 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 17 Apr 2007 01:47:58 +0000 Subject: [PATCH] Add test and some docs for bug 376660. r=biesi --- .../base/public/nsIUnicharStreamLoader.idl | 6 +++ netwerk/test/unit/test_bug376660.js | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 netwerk/test/unit/test_bug376660.js diff --git a/netwerk/base/public/nsIUnicharStreamLoader.idl b/netwerk/base/public/nsIUnicharStreamLoader.idl index 6de2465bd5b..50ddca2859c 100644 --- a/netwerk/base/public/nsIUnicharStreamLoader.idl +++ b/netwerk/base/public/nsIUnicharStreamLoader.idl @@ -54,6 +54,9 @@ interface nsIUnicharStreamLoaderObserver : nsISupports * @param aLength the length of aFirstSegment * * @return charset corresponding to this stream + * + * @note this method will only be called if the stream loader receives an + * OnDataAvailable call. */ ACString onDetermineCharset(in nsIUnicharStreamLoader aLoader, in nsISupports aContext, @@ -72,6 +75,9 @@ interface nsIUnicharStreamLoaderObserver : nsISupports * This method will always be called asynchronously by the * nsUnicharIStreamLoader involved, on the thread that called the * loader's init() method. + * + * @note If the stream loader does not receive an OnDataAvailable call, + * aUnicharData will be null, and aStatus will be a success value. */ void onStreamComplete(in nsIUnicharStreamLoader aLoader, in nsISupports aContext, diff --git a/netwerk/test/unit/test_bug376660.js b/netwerk/test/unit/test_bug376660.js new file mode 100644 index 00000000000..d68f1342100 --- /dev/null +++ b/netwerk/test/unit/test_bug376660.js @@ -0,0 +1,37 @@ +var Cc = Components.classes; +var Ci = Components.interfaces; + +var listener = { + QueryInterface: function listener_qi(iid) { + if (iid.equals(Ci.nsISupports) || + iid.equals(Ci.nsIUnicharStreamLoaderObserver)) { + return this; + } + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + onDetermineCharset : function onDetermineCharset(loader, context, + data, length) + { + return "us-ascii"; + }, + onStreamComplete : function onStreamComplete (loader, context, status, data) + { + do_check_eq(status, Components.results.NS_OK); + do_check_eq(data, null); + do_check_neq(loader.channel, null); + do_test_finished(); + } +}; + +function run_test() { + var f = + Cc["@mozilla.org/network/unichar-stream-loader;1"]. + createInstance(Ci.nsIUnicharStreamLoader); + f.init(listener, 4096); + + var ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var chan = ios.newChannel("data:text/plain,", null, null); + chan.asyncOpen(f, null); + do_test_pending(); +}