tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_private_necko_channel.js (1459B)


      1 //
      2 // Private channel test
      3 //
      4 
      5 "use strict";
      6 
      7 const { HttpServer } = ChromeUtils.importESModule(
      8  "resource://testing-common/httpd.sys.mjs"
      9 );
     10 
     11 var httpserver = new HttpServer();
     12 var testpath = "/simple";
     13 var httpbody = "0123456789";
     14 
     15 function run_test() {
     16  // Simulate a profile dir for xpcshell
     17  do_get_profile();
     18 
     19  // Start off with an empty cache
     20  evict_cache_entries();
     21 
     22  httpserver.registerPathHandler(testpath, serverHandler);
     23  httpserver.start(-1);
     24 
     25  var channel = setupChannel(testpath);
     26  channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance();
     27 
     28  channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
     29  channel.setPrivate(true);
     30 
     31  channel.asyncOpen(new ChannelListener(checkRequest, channel));
     32 
     33  do_test_pending();
     34 }
     35 
     36 function setupChannel(path) {
     37  return NetUtil.newChannel({
     38    uri: "http://localhost:" + httpserver.identity.primaryPort + path,
     39    loadUsingSystemPrincipal: true,
     40  }).QueryInterface(Ci.nsIHttpChannel);
     41 }
     42 
     43 function serverHandler(metadata, response) {
     44  response.setHeader("Content-Type", "text/plain", false);
     45  response.bodyOutputStream.write(httpbody, httpbody.length);
     46 }
     47 
     48 function checkRequest() {
     49  get_device_entry_count("disk", null, function (count) {
     50    Assert.equal(count, 0);
     51    get_device_entry_count(
     52      "disk",
     53      Services.loadContextInfo.private,
     54      function (count1) {
     55        Assert.equal(count1, 1);
     56        httpserver.stop(do_test_finished);
     57      }
     58    );
     59  });
     60 }