Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / netwerk / test / unit / test_data_protocol.js
blob06f6b0e96d394bc760c0636042a86ffe48b22e12
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
11 var urls = [
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++]();
25 function run_test() {
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!");
37 do_test_finished();
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");
44 do_test_pending();
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);