diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /netwerk/test/unit/test_cookies_purge_counting.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_cookies_purge_counting.js')
-rw-r--r-- | netwerk/test/unit/test_cookies_purge_counting.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_cookies_purge_counting.js b/netwerk/test/unit/test_cookies_purge_counting.js new file mode 100644 index 0000000000..d92fabfbba --- /dev/null +++ b/netwerk/test/unit/test_cookies_purge_counting.js @@ -0,0 +1,74 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_setup(function test_setup() { + // FOG needs a profile directory to put its data in. + do_get_profile(); + + // FOG needs to be initialized in order for data to flow. + Services.fog.initializeFOG(); +}); + +add_task(async function test_purge_counting() { + let profile = do_get_profile(); + let dbFile = do_get_cookie_file(profile); + Assert.ok(!dbFile.exists()); + + let schema12db = new CookieDatabaseConnection(dbFile, 12); + + let now = Date.now() * 1000; // date in microseconds + let pastExpiry = Math.round(now / 1e6 - 1000); + let futureExpiry = Math.round(now / 1e6 + 1000); + + let manyHosts = 50; + let manyCookies = 140; + let totalCookies = manyHosts * manyCookies; + + // add many expired cookies for each host + for (let hostNum = 0; hostNum < manyHosts; hostNum++) { + let host = "cookie-host" + hostNum + ".com"; + for (let i = 0; i < manyCookies; i++) { + let cookie = new Cookie( + "cookie-name" + i, + "cookie-value" + i, + host, + "/", // path + pastExpiry, + pastExpiry, // needed to get the cookie by the db init + now, + false, + false, + false + ); + schema12db.insertCookie(cookie); + } + } + + let validCookies = Services.cookies.cookies.length; // includes expired cookies + Assert.equal(validCookies, totalCookies); + + // add a valid cookie - this triggers the purge + Services.cookies.add( + "cookie-host0.com", // any host + "/", // path + "cookie-name-x", + "cookie-value-x", + false, // secure + true, // http-only + true, // isSession + futureExpiry, + {}, // OA + Ci.nsICookie.SAMESITE_NONE, // SameSite + Ci.nsICookie.SCHEME_HTTPS + ); + + // check that we purge all the expired cookies and not the unexpired + validCookies = Services.cookies.cookies.length; + Assert.equal(validCookies, 1); + + // check that the telemetry fired + let cpm = await Glean.networking.cookiePurgeMax.testGetValue(); + Assert.equal(cpm.sum, totalCookies, "Purge the expected number of cookies"); + + schema12db.close(); +}); |