netwerk/test/unit/test_data_protocol.js

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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
     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 ];
    22 function run_test() {
    23   dump("*** run_test\n");
    25   function on_read_complete(request, data, idx) {
    26     dump("*** run_test.on_read_complete\n");
    28     if (request.nsIChannel.contentType != urls[idx][1])
    29       do_throw("Type mismatch! Is <" + chan.contentType + ">, should be <" + urls[idx][1] + ">");
    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   }
    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 }

mercurial