netwerk/test/unit/test_private_necko_channel.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 //
michael@0 2 // Private channel test
michael@0 3 //
michael@0 4
michael@0 5 Cu.import("resource://testing-common/httpd.js");
michael@0 6
michael@0 7 var httpserver = new HttpServer();
michael@0 8 var testpath = "/simple";
michael@0 9 var httpbody = "0123456789";
michael@0 10
michael@0 11 function run_test() {
michael@0 12 // Simulate a profile dir for xpcshell
michael@0 13 do_get_profile();
michael@0 14
michael@0 15 // Start off with an empty cache
michael@0 16 evict_cache_entries();
michael@0 17
michael@0 18 httpserver.registerPathHandler(testpath, serverHandler);
michael@0 19 httpserver.start(-1);
michael@0 20
michael@0 21 var channel = setupChannel(testpath);
michael@0 22 channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance();
michael@0 23
michael@0 24 channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
michael@0 25 channel.setPrivate(true);
michael@0 26
michael@0 27 channel.asyncOpen(new ChannelListener(checkRequest, channel), null);
michael@0 28
michael@0 29 do_test_pending();
michael@0 30 }
michael@0 31
michael@0 32 function setupChannel(path) {
michael@0 33 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
michael@0 34 return chan = ios.newChannel("http://localhost:" +
michael@0 35 httpserver.identity.primaryPort + path, "", null)
michael@0 36 .QueryInterface(Ci.nsIHttpChannel);
michael@0 37 }
michael@0 38
michael@0 39 function serverHandler(metadata, response) {
michael@0 40 response.setHeader("Content-Type", "text/plain", false);
michael@0 41 response.bodyOutputStream.write(httpbody, httpbody.length);
michael@0 42 }
michael@0 43
michael@0 44 function checkRequest(request, data, context) {
michael@0 45 get_device_entry_count("disk", null, function(count) {
michael@0 46 do_check_eq(count, 0)
michael@0 47 get_device_entry_count("disk", LoadContextInfo.private, function(count) {
michael@0 48 do_check_eq(count, 1);
michael@0 49 httpserver.stop(do_test_finished);
michael@0 50 });
michael@0 51 });
michael@0 52 }

mercurial