netwerk/test/unit/test_private_necko_channel.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_private_necko_channel.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +//
     1.5 +// Private channel test
     1.6 +//
     1.7 +
     1.8 +Cu.import("resource://testing-common/httpd.js");
     1.9 +
    1.10 +var httpserver = new HttpServer();
    1.11 +var testpath = "/simple";
    1.12 +var httpbody = "0123456789";
    1.13 +
    1.14 +function run_test() {
    1.15 +  // Simulate a profile dir for xpcshell
    1.16 +  do_get_profile();
    1.17 +
    1.18 +  // Start off with an empty cache
    1.19 +  evict_cache_entries();
    1.20 +
    1.21 +  httpserver.registerPathHandler(testpath, serverHandler);
    1.22 +  httpserver.start(-1);
    1.23 +
    1.24 +  var channel = setupChannel(testpath);
    1.25 +  channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance();
    1.26 +
    1.27 +  channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
    1.28 +  channel.setPrivate(true);
    1.29 +
    1.30 +  channel.asyncOpen(new ChannelListener(checkRequest, channel), null);
    1.31 +
    1.32 +  do_test_pending();
    1.33 +}
    1.34 +
    1.35 +function setupChannel(path) {
    1.36 +  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    1.37 +  return chan = ios.newChannel("http://localhost:" +
    1.38 +                               httpserver.identity.primaryPort + path, "", null)
    1.39 +                   .QueryInterface(Ci.nsIHttpChannel);
    1.40 +}
    1.41 +
    1.42 +function serverHandler(metadata, response) {
    1.43 +  response.setHeader("Content-Type", "text/plain", false);
    1.44 +  response.bodyOutputStream.write(httpbody, httpbody.length);
    1.45 +}
    1.46 +
    1.47 +function checkRequest(request, data, context) {
    1.48 +  get_device_entry_count("disk", null, function(count) {
    1.49 +    do_check_eq(count, 0)
    1.50 +    get_device_entry_count("disk", LoadContextInfo.private, function(count) {
    1.51 +      do_check_eq(count, 1);
    1.52 +      httpserver.stop(do_test_finished);
    1.53 +    });
    1.54 +  });
    1.55 +}

mercurial