1 /* run some tests on the data: protocol handler */
3 const Cc
= Components
.classes
;
4 const Ci
= Components
.interfaces
;
5 const Cr
= Components
.results
;
7 // The behaviour wrt spaces is:
8 // - Textual content keeps all spaces
9 // - Other content strips unescaped spaces
10 // - Base64 content strips escaped and unescaped spaces
12 ["data:,foo", "text/plain", "foo"],
13 ["data:application/octet-stream,foo bar", "application/octet-stream", "foobar"],
14 ["data:application/octet-stream,foo%20bar", "application/octet-stream", "foo bar"],
15 ["data:application/xhtml+xml,foo bar", "application/xhtml+xml", "foo bar"],
16 ["data:application/xhtml+xml,foo%20bar", "application/xhtml+xml", "foo bar"],
17 ["data:text/plain,foo%00 bar", "text/plain", "foo\x00 bar"],
18 ["data:text/plain;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"]
21 function run_next_test() {
22 test_array
[test_index
++]();
26 dump("*** run_test\n");
28 function on_read_complete(request
, data
, idx
) {
29 dump("*** run_test.on_read_complete\n");
31 if (request
.nsIChannel
.contentType
!= urls
[idx
][1])
32 do_throw("Type mismatch! Is <" + chan
.contentType
+ ">, should be <" + urls
[idx
][1] + ">");
34 /* read completed successfully. now compare the data. */
35 if (data
!= urls
[idx
][2])
36 do_throw("Stream contents do not match with direct read!");
40 var ios
= Cc
["@mozilla.org/network/io-service;1"].
41 getService(Ci
.nsIIOService
);
42 for (var i
= 0; i
< urls
.length
; ++i
) {
43 dump("*** opening channel " + i
+ "\n");
45 var chan
= ios
.newChannel(urls
[i
][0], "", null);
46 chan
.contentType
= "foo/bar"; // should be ignored
47 chan
.asyncOpen(new ChannelListener(on_read_complete
, i
), null);