netwerk/test/unit/test_bug282432.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_bug282432.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,38 @@
     1.4 +function run_test() {
     1.5 +  do_test_pending();
     1.6 +
     1.7 +  function StreamListener() {}
     1.8 +
     1.9 +  StreamListener.prototype = {
    1.10 +    QueryInterface: function(aIID) {
    1.11 +      if (aIID.equals(Components.interfaces.nsIStreamListener) ||
    1.12 +          aIID.equals(Components.interfaces.nsIRequestObserver) ||
    1.13 +          aIID.equals(Components.interfaces.nsISupports))
    1.14 +        return this;
    1.15 +      throw Components.results.NS_NOINTERFACE;
    1.16 +    },
    1.17 +
    1.18 +    onStartRequest: function(aRequest, aContext) {},
    1.19 +
    1.20 +    onStopRequest: function(aRequest, aContext, aStatusCode) {
    1.21 +      // Make sure we can catch the error NS_ERROR_FILE_NOT_FOUND here.
    1.22 +      do_check_eq(aStatusCode, Components.results.NS_ERROR_FILE_NOT_FOUND);
    1.23 +      do_test_finished();
    1.24 +    },
    1.25 +
    1.26 +    onDataAvailable: function(aRequest, aContext, aStream, aOffset, aCount) {
    1.27 +      do_throw("The channel must not call onDataAvailable().");
    1.28 +    }
    1.29 +  };
    1.30 +
    1.31 +  let listener = new StreamListener();
    1.32 +  let ios = Components.classes["@mozilla.org/network/io-service;1"]
    1.33 +                      .getService(Components.interfaces.nsIIOService);
    1.34 +
    1.35 +  // This file does not exist.
    1.36 +  let file = do_get_file("_NOT_EXIST_.txt", true);
    1.37 +  do_check_false(file.exists());
    1.38 +
    1.39 +  let channel = ios.newChannelFromURI(ios.newFileURI(file));
    1.40 +  channel.asyncOpen(listener, null);
    1.41 +}

mercurial