netwerk/test/unit/test_bug376660.js

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 var Cc = Components.classes;
michael@0 2 var Ci = Components.interfaces;
michael@0 3
michael@0 4 var listener = {
michael@0 5 expect_failure: false,
michael@0 6 QueryInterface: function listener_qi(iid) {
michael@0 7 if (iid.equals(Ci.nsISupports) ||
michael@0 8 iid.equals(Ci.nsIUnicharStreamLoaderObserver)) {
michael@0 9 return this;
michael@0 10 }
michael@0 11 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 12 },
michael@0 13 onDetermineCharset : function onDetermineCharset(loader, context, data)
michael@0 14 {
michael@0 15 return "us-ascii";
michael@0 16 },
michael@0 17 onStreamComplete : function onStreamComplete (loader, context, status, data)
michael@0 18 {
michael@0 19 try {
michael@0 20 if (this.expect_failure)
michael@0 21 do_check_false(Components.isSuccessCode(status));
michael@0 22 else
michael@0 23 do_check_eq(status, Components.results.NS_OK);
michael@0 24 do_check_eq(data, "");
michael@0 25 do_check_neq(loader.channel, null);
michael@0 26 tests[current_test++]();
michael@0 27 } finally {
michael@0 28 do_test_finished();
michael@0 29 }
michael@0 30 }
michael@0 31 };
michael@0 32
michael@0 33 var current_test = 0;
michael@0 34 var tests = [test1, test2, done];
michael@0 35
michael@0 36 function run_test() {
michael@0 37 tests[current_test++]();
michael@0 38 }
michael@0 39
michael@0 40 function test1() {
michael@0 41 var f =
michael@0 42 Cc["@mozilla.org/network/unichar-stream-loader;1"].
michael@0 43 createInstance(Ci.nsIUnicharStreamLoader);
michael@0 44 f.init(listener);
michael@0 45
michael@0 46 var ios = Components.classes["@mozilla.org/network/io-service;1"]
michael@0 47 .getService(Components.interfaces.nsIIOService);
michael@0 48 var chan = ios.newChannel("data:text/plain,", null, null);
michael@0 49 chan.asyncOpen(f, null);
michael@0 50 do_test_pending();
michael@0 51 }
michael@0 52
michael@0 53 function test2() {
michael@0 54 var f =
michael@0 55 Cc["@mozilla.org/network/unichar-stream-loader;1"].
michael@0 56 createInstance(Ci.nsIUnicharStreamLoader);
michael@0 57 f.init(listener);
michael@0 58
michael@0 59 var ios = Components.classes["@mozilla.org/network/io-service;1"]
michael@0 60 .getService(Components.interfaces.nsIIOService);
michael@0 61 var chan = ios.newChannel("http://localhost:0/", null, null);
michael@0 62 listener.expect_failure = true;
michael@0 63 chan.asyncOpen(f, null);
michael@0 64 do_test_pending();
michael@0 65 }
michael@0 66
michael@0 67 function done() {
michael@0 68 }

mercurial