1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
Cu.import("resource://gre/modules/NetUtil.jsm");
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)
{
return "us-ascii";
},
onStreamComplete : function onStreamComplete (loader, context, status, data)
{
try {
if (this.expect_failure)
do_check_false(Components.isSuccessCode(status));
else
do_check_eq(status, Components.results.NS_OK);
do_check_eq(data, "");
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);
var chan = NetUtil.newChannel({
uri: "data:text/plain,",
loadUsingSystemPrincipal: true
});
chan.asyncOpen2(f);
do_test_pending();
}
function test2() {
var f =
Cc["@mozilla.org/network/unichar-stream-loader;1"].
createInstance(Ci.nsIUnicharStreamLoader);
f.init(listener);
var chan = NetUtil.newChannel({
uri: "http://localhost:0/",
loadUsingSystemPrincipal: true
});
listener.expect_failure = true;
chan.asyncOpen2(f);
do_test_pending();
}
function done() {
}
|