netwerk/test/unit/test_private_necko_channel.js

changeset 1
ca08bd8f51b2
equal deleted inserted replaced
-1:000000000000 0:e310cc75ba06
1 //
2 // Private channel test
3 //
4
5 Cu.import("resource://testing-common/httpd.js");
6
7 var httpserver = new HttpServer();
8 var testpath = "/simple";
9 var httpbody = "0123456789";
10
11 function run_test() {
12 // Simulate a profile dir for xpcshell
13 do_get_profile();
14
15 // Start off with an empty cache
16 evict_cache_entries();
17
18 httpserver.registerPathHandler(testpath, serverHandler);
19 httpserver.start(-1);
20
21 var channel = setupChannel(testpath);
22 channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance();
23
24 channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
25 channel.setPrivate(true);
26
27 channel.asyncOpen(new ChannelListener(checkRequest, channel), null);
28
29 do_test_pending();
30 }
31
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 }
38
39 function serverHandler(metadata, response) {
40 response.setHeader("Content-Type", "text/plain", false);
41 response.bodyOutputStream.write(httpbody, httpbody.length);
42 }
43
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