From 0a0e3223a803419353c1c2950ca8d3d8119d9a17 Mon Sep 17 00:00:00 2001 From: Dietrich Ayala Date: Wed, 16 Dec 2009 11:02:10 -0800 Subject: [PATCH] Backout of bug 532147 and bug 532146 due to test failure. --- netwerk/base/src/NetUtil.jsm | 60 ++--------- netwerk/test/unit/test_NetUtil.js | 173 +----------------------------- 2 files changed, 12 insertions(+), 221 deletions(-) diff --git a/netwerk/base/src/NetUtil.jsm b/netwerk/base/src/NetUtil.jsm index 46381237ae4e..d620d2324cc9 100644 --- a/netwerk/base/src/NetUtil.jsm +++ b/netwerk/base/src/NetUtil.jsm @@ -128,23 +128,23 @@ const NetUtil = { }, /** - * Asynchronously opens a source and fetches the response. A source can be - * an nsIURI, nsIFile, string spec, or nsIChannel. The provided callback - * will get an input stream containing the response, and the result code. + * Asynchronously opens a channel and fetches the response. The provided + * callback will get an input stream containing the response, and the result + * code. * - * @param aSource - * The nsIURI, nsIFile, string spec, or nsIChannel to open. + * @param aChannel + * The nsIChannel to open. * @param aCallback * The callback function that will be notified upon completion. It * will get two arguments: * 1) An nsIInputStream containing the data from the channel, if any. - * 2) The status code from opening the source. + * 2) The status code from opening the channel. */ - asyncFetch: function NetUtil_asyncOpen(aSource, aCallback) + asyncFetch: function NetUtil_asyncOpen(aChannel, aCallback) { - if (!aSource || !aCallback) { + if (!aChannel || !aCallback) { let exception = new Components.Exception( - "Must have a source and a callback", + "Must have a channel and a callback", Cr.NS_ERROR_INVALID_ARG, Components.stack.caller ); @@ -168,12 +168,7 @@ const NetUtil = { } }); - let channel = aSource; - if (!(channel instanceof Ci.nsIChannel)) { - channel = this.newChannel(aSource); - } - - channel.asyncOpen(listener, null); + aChannel.asyncOpen(listener, null); }, /** @@ -209,41 +204,6 @@ const NetUtil = { return this.ioService.newURI(aTarget, aOriginCharset, aBaseURI); }, - /** - * Constructs a new channel for the given spec, character set, and base URI, - * or nsIURI, or nsIFile. - * - * @param aWhatToLoad - * The string spec for the desired URI, an nsIURI, or an nsIFile. - * @param aOriginCharset [optional] - * The character set for the URI. Only used if aWhatToLoad is a - * string. - * @param aBaseURI [optional] - * The base URI for the spec. Only used if aWhatToLoad is a string. - * - * @return an nsIChannel object. - */ - newChannel: function NetUtil_newChannel(aWhatToLoad, aOriginCharset, - aBaseURI) - { - if (!aWhatToLoad) { - let exception = new Components.Exception( - "Must have a non-null string spec, nsIURI, or nsIFile object", - Cr.NS_ERROR_INVALID_ARG, - Components.stack.caller - ); - throw exception; - } - - let uri = aWhatToLoad; - if (!(aWhatToLoad instanceof Ci.nsIURI)) { - // We either have a string or an nsIFile that we'll need a URI for. - uri = this.newURI(aWhatToLoad, aOriginCharset, aBaseURI); - } - - return this.ioService.newChannelFromURI(uri); - }, - /** * Returns a reference to nsIIOService. * diff --git a/netwerk/test/unit/test_NetUtil.js b/netwerk/test/unit/test_NetUtil.js index 5d2824264553..670e112cb41e 100644 --- a/netwerk/test/unit/test_NetUtil.js +++ b/netwerk/test/unit/test_NetUtil.js @@ -224,7 +224,7 @@ function test_asyncFetch_no_callback() run_next_test(); } -function test_asyncFetch_with_nsIChannel() +function test_asyncFetch() { const TEST_DATA = "this is a test string"; @@ -258,110 +258,6 @@ function test_asyncFetch_with_nsIChannel() }); } -function test_asyncFetch_with_nsIURI() -{ - const TEST_DATA = "this is a test string"; - - // Start the http server, and register our handler. - let server = new nsHttpServer(); - server.registerPathHandler("/test", function(aRequest, aResponse) { - aResponse.setStatusLine(aRequest.httpVersion, 200, "OK"); - aResponse.setHeader("Content-Type", "text/plain", false); - aResponse.write(TEST_DATA); - }); - server.start(4444); - - // Create our URI. - let uri = NetUtil.newURI("http://localhost:4444/test"); - - // Open our URI asynchronously. - NetUtil.asyncFetch(uri, function(aInputStream, aResult) { - // Check that we had success. - do_check_true(Components.isSuccessCode(aResult)); - - // Check that we got the right data. - do_check_eq(aInputStream.available(), TEST_DATA.length); - let is = Cc["@mozilla.org/scriptableinputstream;1"]. - createInstance(Ci.nsIScriptableInputStream); - is.init(aInputStream); - let result = is.read(TEST_DATA.length); - do_check_eq(TEST_DATA, result); - - server.stop(run_next_test); - }); -} - -function test_asyncFetch_with_string() -{ - const TEST_DATA = "this is a test string"; - - // Start the http server, and register our handler. - let server = new nsHttpServer(); - server.registerPathHandler("/test", function(aRequest, aResponse) { - aResponse.setStatusLine(aRequest.httpVersion, 200, "OK"); - aResponse.setHeader("Content-Type", "text/plain", false); - aResponse.write(TEST_DATA); - }); - server.start(4444); - - // Open our location asynchronously. - NetUtil.asyncFetch("http://localhost:4444/test", function(aInputStream, - aResult) { - // Check that we had success. - do_check_true(Components.isSuccessCode(aResult)); - - // Check that we got the right data. - do_check_eq(aInputStream.available(), TEST_DATA.length); - let is = Cc["@mozilla.org/scriptableinputstream;1"]. - createInstance(Ci.nsIScriptableInputStream); - is.init(aInputStream); - let result = is.read(TEST_DATA.length); - do_check_eq(TEST_DATA, result); - - server.stop(run_next_test); - }); -} - -function test_asyncFetch_with_nsIFile() -{ - const TEST_DATA = "this is a test string"; - - // First we need a file to read from. - let file = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties). - get("TmpD", Ci.nsIFile); - file.append("NetUtil-asyncFetch-test-file.tmp"); - file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); - - // Write the test data to the file. - let ostream = Cc["@mozilla.org/network/file-output-stream;1"]. - createInstance(Ci.nsIFileOutputStream); - ostream.init(file, -1, -1, 0); - ostream.write(TEST_DATA, TEST_DATA.length); - - // Sanity check to make sure the data was written. - do_check_eq(TEST_DATA, getFileContents(file)); - - // Open our file asynchronously. - NetUtil.asyncFetch(file, function(aInputStream, aResult) { - // Check that we had success. - do_check_true(Components.isSuccessCode(aResult)); - - // Check that we got the right data. - do_check_eq(aInputStream.available(), TEST_DATA.length); - let is = Cc["@mozilla.org/scriptableinputstream;1"]. - createInstance(Ci.nsIScriptableInputStream); - is.init(aInputStream); - let result = is.read(TEST_DATA.length); - do_check_eq(TEST_DATA, result); - - // Remove our test file. - file.remove(false); - - run_next_test(); - }); -} - function test_asyncFetch_does_not_block() { // Create our channel that has no data. @@ -390,64 +286,6 @@ function test_asyncFetch_does_not_block() }); } -function test_newChannel_no_specifier() -{ - try { - NetUtil.newChannel(); - do_throw("should throw!"); - } - catch (e) { - do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); - } - - run_next_test(); -} - -function test_newChannel_with_string() -{ - const TEST_SPEC = "http://mozilla.org"; - - // Check that we get the same URI back from channel the IO service creates and - // the channel the utility method creates. - let ios = NetUtil.ioService; - let iosChannel = ios.newChannel(TEST_SPEC, null, null); - let NetUtilChannel = NetUtil.newChannel(TEST_SPEC); - do_check_true(iosChannel.URI.equals(NetUtilChannel.URI)); - - run_next_test(); -} - -function test_newChannel_with_nsIURI() -{ - const TEST_SPEC = "http://mozilla.org"; - - // Check that we get the same URI back from channel the IO service creates and - // the channel the utility method creates. - let uri = NetUtil.newURI(TEST_SPEC); - let iosChannel = NetUtil.ioService.newChannelFromURI(uri); - let NetUtilChannel = NetUtil.newChannel(uri); - do_check_true(iosChannel.URI.equals(NetUtilChannel.URI)); - - run_next_test(); -} - -function test_newChannel_with_nsIFile() -{ - let file = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties). - get("TmpD", Ci.nsIFile); - file.append("NetUtil-test-file.tmp"); - - // Check that we get the same URI back from channel the IO service creates and - // the channel the utility method creates. - let uri = NetUtil.newURI(file); - let iosChannel = NetUtil.ioService.newChannelFromURI(uri); - let NetUtilChannel = NetUtil.newChannel(uri); - do_check_true(iosChannel.URI.equals(NetUtilChannel.URI)); - - run_next_test(); -} - //////////////////////////////////////////////////////////////////////////////// //// Test Runner @@ -460,15 +298,8 @@ let tests = [ test_ioService, test_asyncFetch_no_channel, test_asyncFetch_no_callback, - test_asyncFetch_with_nsIChannel, - test_asyncFetch_with_nsIURI, - test_asyncFetch_with_string, - test_asyncFetch_with_nsIFile, + test_asyncFetch, test_asyncFetch_does_not_block, - test_newChannel_no_specifier, - test_newChannel_with_string, - test_newChannel_with_nsIURI, - test_newChannel_with_nsIFile, ]; let index = 0;