Bug 1857386 [wpt PR 42383] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / test / unit / test_private_necko_channel.js
blobdc6a73e1459112383215504891a712bbd9dfcfed
1 //
2 // Private channel test
3 //
5 "use strict";
7 const { HttpServer } = ChromeUtils.importESModule(
8   "resource://testing-common/httpd.sys.mjs"
9 );
11 var httpserver = new HttpServer();
12 var testpath = "/simple";
13 var httpbody = "0123456789";
15 function run_test() {
16   // Simulate a profile dir for xpcshell
17   do_get_profile();
19   // Start off with an empty cache
20   evict_cache_entries();
22   httpserver.registerPathHandler(testpath, serverHandler);
23   httpserver.start(-1);
25   var channel = setupChannel(testpath);
26   channel.loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance();
28   channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);
29   channel.setPrivate(true);
31   channel.asyncOpen(new ChannelListener(checkRequest, channel));
33   do_test_pending();
36 function setupChannel(path) {
37   return NetUtil.newChannel({
38     uri: "http://localhost:" + httpserver.identity.primaryPort + path,
39     loadUsingSystemPrincipal: true,
40   }).QueryInterface(Ci.nsIHttpChannel);
43 function serverHandler(metadata, response) {
44   response.setHeader("Content-Type", "text/plain", false);
45   response.bodyOutputStream.write(httpbody, httpbody.length);
48 function checkRequest(request, data, context) {
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   });