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
11 ["data:,", "text/plain", ""],
12 ["data:,foo", "text/plain", "foo"],
14 "data:application/octet-stream,foo bar",
15 "application/octet-stream",
19 "data:application/octet-stream,foo%20bar",
20 "application/octet-stream",
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"],
34 "data:application/octet-stream;base64=y,foobar",
35 "application/octet-stream",
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"],
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]) {
53 "Type mismatch! Is <" +
61 if (urls[idx][3] && request.nsIChannel.contentCharset !== urls[idx][3]) {
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]) {
70 "Stream contents do not match with direct read! Is <" +
80 for (var i = 0; i < urls.length; ++i) {
81 dump("*** opening channel " + i + "\n");
83 var chan = NetUtil.newChannel({
85 loadUsingSystemPrincipal: true,
87 chan.contentType = "foo/bar"; // should be ignored
88 chan.asyncOpen(new ChannelListener(on_read_complete, i));