gecko-dev/netwerk/test/unit/test_separate_connections.js
Ehsan Akhgari 868c13b5e5 Bug 1547397 - Part 2: Move some xpcshell tests for cookies out of extensions/cookies; r=baku
Differential Revision: https://phabricator.services.mozilla.com/D29115

--HG--
rename : extensions/cookie/test/unit/head_cookies.js => netwerk/test/unit/head_cookies.js
rename : extensions/cookie/test/unit/test_bug526789.js => netwerk/test/unit/test_bug526789.js
rename : extensions/cookie/test/unit/test_bug650522.js => netwerk/test/unit/test_bug650522.js
rename : extensions/cookie/test/unit/test_bug667087.js => netwerk/test/unit/test_bug667087.js
rename : extensions/cookie/test/unit/test_cookies_async_failure.js => netwerk/test/unit/test_cookies_async_failure.js
rename : extensions/cookie/test/unit/test_cookies_persistence.js => netwerk/test/unit/test_cookies_persistence.js
rename : extensions/cookie/test/unit/test_cookies_privatebrowsing.js => netwerk/test/unit/test_cookies_privatebrowsing.js
rename : extensions/cookie/test/unit/test_cookies_profile_close.js => netwerk/test/unit/test_cookies_profile_close.js
rename : extensions/cookie/test/unit/test_cookies_read.js => netwerk/test/unit/test_cookies_read.js
rename : extensions/cookie/test/unit/test_cookies_sync_failure.js => netwerk/test/unit/test_cookies_sync_failure.js
rename : extensions/cookie/test/unit/test_cookies_thirdparty.js => netwerk/test/unit/test_cookies_thirdparty.js
rename : extensions/cookie/test/unit/test_cookies_thirdparty_nonsecure_session.js => netwerk/test/unit/test_cookies_thirdparty_nonsecure_session.js
rename : extensions/cookie/test/unit/test_cookies_thirdparty_session.js => netwerk/test/unit/test_cookies_thirdparty_session.js
rename : extensions/cookie/test/unit/test_domain_eviction.js => netwerk/test/unit/test_domain_eviction.js
rename : extensions/cookie/test/unit/test_eviction.js => netwerk/test/unit/test_eviction.js
rename : extensions/cookie/test/unit/test_schema_2_migration.js => netwerk/test/unit/test_schema_2_migration.js
rename : extensions/cookie/test/unit/test_schema_3_migration.js => netwerk/test/unit/test_schema_3_migration.js
extra : moz-landing-system : lando
2019-04-30 14:06:27 +00:00

97 lines
2.9 KiB
JavaScript

const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
XPCOMUtils.defineLazyGetter(this, "URL", function() {
return "http://localhost:" + httpserv.identity.primaryPort;
});
// This unit test ensures each container has its own connection pool.
// We verify this behavior by opening channels with different userContextId,
// and their connection info's hash keys should be different.
// In the first round of this test, we record the hash key in each container.
// In the second round, we check if each container's hash key is consistent
// and different from other container's hash key.
let httpserv = null;
let gSecondRoundStarted = false;
function handler(metadata, response) {
response.setHeader("Content-Type", "text/plain", false);
response.setHeader("Cache-Control", "no-cache", false);
response.setStatusLine(metadata.httpVersion, 200, "OK");
let body = "0123456789";
response.bodyOutputStream.write(body, body.length);
}
function makeChan(url, userContextId) {
let chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
chan.loadInfo.originAttributes = { userContextId: userContextId };
return chan;
}
let previousHashKeys = [];
function Listener(userContextId) {
this.userContextId = userContextId;
}
let gTestsRun = 0;
Listener.prototype = {
onStartRequest: function(request) {
request.QueryInterface(Ci.nsIHttpChannel)
.QueryInterface(Ci.nsIHttpChannelInternal);
Assert.equal(request.loadInfo.originAttributes.userContextId, this.userContextId);
let hashKey = request.connectionInfoHashKey;
if (gSecondRoundStarted) {
// Compare the hash keys with the previous set ones.
// Hash keys should match if and only if their userContextId are the same.
for (let userContextId = 0; userContextId < 3; userContextId++) {
if (userContextId == this.userContextId) {
Assert.equal(hashKey, previousHashKeys[userContextId]);
} else {
Assert.notEqual(hashKey, previousHashKeys[userContextId]);
}
}
} else {
// Set the hash keys in the first round.
previousHashKeys[this.userContextId] = hashKey;
}
},
onDataAvailable: function(request, stream, off, cnt) {
read_stream(stream, cnt);
},
onStopRequest: function() {
gTestsRun++;
if (gTestsRun == 3) {
gTestsRun = 0;
if (gSecondRoundStarted) {
// The second round finishes.
httpserv.stop(do_test_finished);
} else {
// The first round finishes. Do the second round.
gSecondRoundStarted = true;
doTest();
}
}
},
};
function doTest() {
for (let userContextId = 0; userContextId < 3; userContextId++) {
let chan = makeChan(URL, userContextId);
let listener = new Listener(userContextId);
chan.asyncOpen(listener);
}
}
function run_test() {
do_test_pending();
httpserv = new HttpServer();
httpserv.registerPathHandler("/", handler);
httpserv.start(-1);
doTest();
}