Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_data_protocol.js
blob484ad469de591df1931afef6939ba52cda49bd02
1 /* run some tests on the data: protocol handler */
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
8 "use strict";
10 var urls = [
11 ["data:,", "text/plain", ""],
12 ["data:,foo", "text/plain", "foo"],
14 "data:application/octet-stream,foo bar",
15 "application/octet-stream",
16 "foo bar",
19 "data:application/octet-stream,foo%20bar",
20 "application/octet-stream",
21 "foo bar",
23 ["data:application/xhtml+xml,foo bar", "application/xhtml+xml", "foo bar"],
24 ["data:application/xhtml+xml,foo%20bar", "application/xhtml+xml", "foo bar"],
25 ["data:text/plain,foo%00 bar", "text/plain", "foo\x00 bar"],
26 ["data:text/plain;x=y,foo%00 bar", "text/plain", "foo\x00 bar"],
27 ["data:;x=y,foo%00 bar", "text/plain", "foo\x00 bar"],
28 ["data:text/plain;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
29 ["DATA:TEXT/PLAIN;BASE64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
30 ["DaTa:;BaSe64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
31 ["data:;x=y;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
32 // Bug 774240
34 "data:application/octet-stream;base64=y,foobar",
35 "application/octet-stream",
36 "foobar",
38 ["data:text/plain;base64;x=y,dGVzdA==", "text/plain", "dGVzdA=="],
39 ["data:text/plain;x=y;base64,dGVzdA==", "text/plain", "test"],
40 ["data:text/plain;x=y;base64,", "text/plain", ""],
41 ["data: ;charset=x ; base64,WA", "text/plain", "X", "x"],
42 ["data:base64,WA", "text/plain", "WA", "US-ASCII"],
45 function run_test() {
46 dump("*** run_test\n");
48 function on_read_complete(request, data, idx) {
49 dump("*** run_test.on_read_complete\n");
51 if (request.nsIChannel.contentType != urls[idx][1]) {
52 do_throw(
53 "Type mismatch! Is <" +
54 chan.contentType +
55 ">, should be <" +
56 urls[idx][1] +
57 ">"
61 if (urls[idx][3] && request.nsIChannel.contentCharset !== urls[idx][3]) {
62 do_throw(
63 `Charset mismatch! Test <${urls[idx][0]}> - Is <${request.nsIChannel.contentCharset}>, should be <${urls[idx][3]}>`
67 /* read completed successfully. now compare the data. */
68 if (data != urls[idx][2]) {
69 do_throw(
70 "Stream contents do not match with direct read! Is <" +
71 data +
72 ">, should be <" +
73 urls[idx][2] +
74 ">"
77 do_test_finished();
80 for (var i = 0; i < urls.length; ++i) {
81 dump("*** opening channel " + i + "\n");
82 do_test_pending();
83 var chan = NetUtil.newChannel({
84 uri: urls[i][0],
85 loadUsingSystemPrincipal: true,
86 });
87 chan.contentType = "foo/bar"; // should be ignored
88 chan.asyncOpen(new ChannelListener(on_read_complete, i));