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.

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

mercurial