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