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.

michael@0 1 /* run some tests on the data: protocol handler */
michael@0 2
michael@0 3 // The behaviour wrt spaces is:
michael@0 4 // - Textual content keeps all spaces
michael@0 5 // - Other content strips unescaped spaces
michael@0 6 // - Base64 content strips escaped and unescaped spaces
michael@0 7 var urls = [
michael@0 8 ["data:,foo", "text/plain", "foo"],
michael@0 9 ["data:application/octet-stream,foo bar", "application/octet-stream", "foobar"],
michael@0 10 ["data:application/octet-stream,foo%20bar", "application/octet-stream", "foo bar"],
michael@0 11 ["data:application/xhtml+xml,foo bar", "application/xhtml+xml", "foo bar"],
michael@0 12 ["data:application/xhtml+xml,foo%20bar", "application/xhtml+xml", "foo bar"],
michael@0 13 ["data:text/plain,foo%00 bar", "text/plain", "foo\x00 bar"],
michael@0 14 ["data:text/plain;base64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
michael@0 15 ["DATA:TEXT/PLAIN;BASE64,Zm9 vI%20GJ%0Dhc%0Ag==", "text/plain", "foo bar"],
michael@0 16 // Bug 774240
michael@0 17 ["data:application/octet-stream;base64=y,foobar", "application/octet-stream", "foobar"],
michael@0 18 // Bug 781693
michael@0 19 ["data:text/plain;base64;x=y,dGVzdA==", "text/plain", "test"]
michael@0 20 ];
michael@0 21
michael@0 22 function run_test() {
michael@0 23 dump("*** run_test\n");
michael@0 24
michael@0 25 function on_read_complete(request, data, idx) {
michael@0 26 dump("*** run_test.on_read_complete\n");
michael@0 27
michael@0 28 if (request.nsIChannel.contentType != urls[idx][1])
michael@0 29 do_throw("Type mismatch! Is <" + chan.contentType + ">, should be <" + urls[idx][1] + ">");
michael@0 30
michael@0 31 /* read completed successfully. now compare the data. */
michael@0 32 if (data != urls[idx][2])
michael@0 33 do_throw("Stream contents do not match with direct read! Is <" + data + ">, should be <" + urls[idx][2] + ">");
michael@0 34 do_test_finished();
michael@0 35 }
michael@0 36
michael@0 37 var ios = Cc["@mozilla.org/network/io-service;1"].
michael@0 38 getService(Ci.nsIIOService);
michael@0 39 for (var i = 0; i < urls.length; ++i) {
michael@0 40 dump("*** opening channel " + i + "\n");
michael@0 41 do_test_pending();
michael@0 42 var chan = ios.newChannel(urls[i][0], "", null);
michael@0 43 chan.contentType = "foo/bar"; // should be ignored
michael@0 44 chan.asyncOpen(new ChannelListener(on_read_complete, i), null);
michael@0 45 }
michael@0 46 }
michael@0 47

mercurial