netwerk/test/unit/test_data_protocol.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_data_protocol.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +/* run some tests on the data: protocol handler */
     1.5 +
     1.6 +// The behaviour wrt spaces is:
     1.7 +// - Textual content keeps all spaces
     1.8 +// - Other content strips unescaped spaces
     1.9 +// - Base64 content strips escaped and unescaped spaces
    1.10 +var urls = [
    1.11 +  ["data:,foo",                                     "text/plain",               "foo"],
    1.12 +  ["data:application/octet-stream,foo bar",         "application/octet-stream", "foobar"],
    1.13 +  ["data:application/octet-stream,foo%20bar",       "application/octet-stream", "foo bar"],
    1.14 +  ["data:application/xhtml+xml,foo bar",            "application/xhtml+xml",    "foo bar"],
    1.15 +  ["data:application/xhtml+xml,foo%20bar",          "application/xhtml+xml",    "foo bar"],
    1.16 +  ["data:text/plain,foo%00 bar",                    "text/plain",               "foo\x00 bar"],
    1.17 +  ["data:text/plain;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain",               "foo bar"],
    1.18 +  ["DATA:TEXT/PLAIN;BASE64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain",               "foo bar"],
    1.19 +  // Bug 774240
    1.20 +  ["data:application/octet-stream;base64=y,foobar", "application/octet-stream", "foobar"],
    1.21 +  // Bug 781693
    1.22 +  ["data:text/plain;base64;x=y,dGVzdA==",           "text/plain",               "test"]
    1.23 +];
    1.24 +
    1.25 +function run_test() {
    1.26 +  dump("*** run_test\n");
    1.27 +
    1.28 +  function on_read_complete(request, data, idx) {
    1.29 +    dump("*** run_test.on_read_complete\n");
    1.30 +
    1.31 +    if (request.nsIChannel.contentType != urls[idx][1])
    1.32 +      do_throw("Type mismatch! Is <" + chan.contentType + ">, should be <" + urls[idx][1] + ">");
    1.33 +
    1.34 +    /* read completed successfully.  now compare the data. */
    1.35 +    if (data != urls[idx][2])
    1.36 +      do_throw("Stream contents do not match with direct read! Is <" + data + ">, should be <" + urls[idx][2] + ">");
    1.37 +    do_test_finished();
    1.38 +  }
    1.39 +
    1.40 +  var ios = Cc["@mozilla.org/network/io-service;1"].
    1.41 +            getService(Ci.nsIIOService);
    1.42 +  for (var i = 0; i < urls.length; ++i) {
    1.43 +    dump("*** opening channel " + i + "\n");
    1.44 +    do_test_pending();
    1.45 +    var chan = ios.newChannel(urls[i][0], "", null);
    1.46 +    chan.contentType = "foo/bar"; // should be ignored
    1.47 +    chan.asyncOpen(new ChannelListener(on_read_complete, i), null);
    1.48 +  }
    1.49 +}
    1.50 +

mercurial