3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 ChromeUtils.defineLazyGetter(this, "URL", function () {
8 return "http://localhost:" + httpserv.identity.primaryPort;
11 // This unit test ensures each container has its own connection pool.
12 // We verify this behavior by opening channels with different userContextId,
13 // and their connection info's hash keys should be different.
15 // In the first round of this test, we record the hash key in each container.
16 // In the second round, we check if each container's hash key is consistent
17 // and different from other container's hash key.
20 let gSecondRoundStarted = false;
22 function handler(metadata, response) {
23 response.setHeader("Content-Type", "text/plain", false);
24 response.setHeader("Cache-Control", "no-cache", false);
25 response.setStatusLine(metadata.httpVersion, 200, "OK");
26 let body = "0123456789";
27 response.bodyOutputStream.write(body, body.length);
30 function makeChan(url, userContextId) {
31 let chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
32 chan.loadInfo.originAttributes = { userContextId };
36 let previousHashKeys = [];
38 function Listener(userContextId) {
39 this.userContextId = userContextId;
43 Listener.prototype = {
44 onStartRequest(request) {
46 .QueryInterface(Ci.nsIHttpChannel)
47 .QueryInterface(Ci.nsIHttpChannelInternal);
50 request.loadInfo.originAttributes.userContextId,
54 let hashKey = request.connectionInfoHashKey;
55 if (gSecondRoundStarted) {
56 // Compare the hash keys with the previous set ones.
57 // Hash keys should match if and only if their userContextId are the same.
58 for (let userContextId = 0; userContextId < 3; userContextId++) {
59 if (userContextId == this.userContextId) {
60 Assert.equal(hashKey, previousHashKeys[userContextId]);
62 Assert.notEqual(hashKey, previousHashKeys[userContextId]);
66 // Set the hash keys in the first round.
67 previousHashKeys[this.userContextId] = hashKey;
70 onDataAvailable(request, stream, off, cnt) {
71 read_stream(stream, cnt);
77 if (gSecondRoundStarted) {
78 // The second round finishes.
79 httpserv.stop(do_test_finished);
81 // The first round finishes. Do the second round.
82 gSecondRoundStarted = true;
90 for (let userContextId = 0; userContextId < 3; userContextId++) {
91 let chan = makeChan(URL, userContextId);
92 let listener = new Listener(userContextId);
93 chan.asyncOpen(listener);
99 httpserv = new HttpServer();
100 httpserv.registerPathHandler("/", handler);