extend test for bug 376660: also test failure cases. r=bz
authorcbiesinger@web.de
Sun, 22 Apr 2007 13:00:17 -0700
changeset 708 ee4af732416abe896081272be0717d1fd6c671e5
parent 707 b0d73580fb9df99e11d938fdbb0d83c984c39eff
child 709 d3c6d0b570dd4999ad81334bcdc4ed8327a222c6
push idunknown
push userunknown
push dateunknown
reviewersbz
bugs376660
milestone1.9a4pre
extend test for bug 376660: also test failure cases. r=bz
netwerk/test/unit/test_bug376660.js
--- a/netwerk/test/unit/test_bug376660.js
+++ b/netwerk/test/unit/test_bug376660.js
@@ -1,37 +1,69 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
 var listener = {
+  expect_failure: false,
   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();
+    try {
+      if (this.expect_failure)
+        do_check_false(Components.isSuccessCode(status));
+      else
+        do_check_eq(status, Components.results.NS_OK);
+      do_check_eq(data, null);
+      do_check_neq(loader.channel, null);
+      tests[current_test++]();
+    } finally {
+      do_test_finished();
+    }
   }
 };
 
+var current_test = 0;
+var tests = [test1, test2, done];
+
 function run_test() {
+  tests[current_test++]();
+}
+
+function test1() {
   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();
 }
+
+function test2() {
+  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("http://localhost:0/", null, null);
+  listener.expect_failure = true;
+  chan.asyncOpen(f, null);
+  do_test_pending();
+}
+
+function done() {
+}