michael@0: /* run some tests on the data: protocol handler */ michael@0: michael@0: // The behaviour wrt spaces is: michael@0: // - Textual content keeps all spaces michael@0: // - Other content strips unescaped spaces michael@0: // - Base64 content strips escaped and unescaped spaces michael@0: var urls = [ michael@0: ["data:,foo", "text/plain", "foo"], michael@0: ["data:application/octet-stream,foo bar", "application/octet-stream", "foobar"], michael@0: ["data:application/octet-stream,foo%20bar", "application/octet-stream", "foo bar"], michael@0: ["data:application/xhtml+xml,foo bar", "application/xhtml+xml", "foo bar"], michael@0: ["data:application/xhtml+xml,foo%20bar", "application/xhtml+xml", "foo bar"], michael@0: ["data:text/plain,foo%00 bar", "text/plain", "foo\x00 bar"], michael@0: ["data:text/plain;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"], michael@0: ["DATA:TEXT/PLAIN;BASE64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"], michael@0: // Bug 774240 michael@0: ["data:application/octet-stream;base64=y,foobar", "application/octet-stream", "foobar"], michael@0: // Bug 781693 michael@0: ["data:text/plain;base64;x=y,dGVzdA==", "text/plain", "test"] michael@0: ]; michael@0: michael@0: function run_test() { michael@0: dump("*** run_test\n"); michael@0: michael@0: function on_read_complete(request, data, idx) { michael@0: dump("*** run_test.on_read_complete\n"); michael@0: michael@0: if (request.nsIChannel.contentType != urls[idx][1]) michael@0: do_throw("Type mismatch! Is <" + chan.contentType + ">, should be <" + urls[idx][1] + ">"); michael@0: michael@0: /* read completed successfully. now compare the data. */ michael@0: if (data != urls[idx][2]) michael@0: do_throw("Stream contents do not match with direct read! Is <" + data + ">, should be <" + urls[idx][2] + ">"); michael@0: do_test_finished(); michael@0: } michael@0: michael@0: var ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: for (var i = 0; i < urls.length; ++i) { michael@0: dump("*** opening channel " + i + "\n"); michael@0: do_test_pending(); michael@0: var chan = ios.newChannel(urls[i][0], "", null); michael@0: chan.contentType = "foo/bar"; // should be ignored michael@0: chan.asyncOpen(new ChannelListener(on_read_complete, i), null); michael@0: } michael@0: } michael@0: