1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 add_setup(function test_setup() {
5 // FOG needs a profile directory to put its data in.
8 // FOG needs to be initialized in order for data to flow.
9 Services
.fog
.initializeFOG();
12 add_task(async
function test_purge_counting_per_host() {
13 let profile
= do_get_profile();
14 let dbFile
= do_get_cookie_file(profile
);
15 Assert
.ok(!dbFile
.exists());
17 let schema12db
= new CookieDatabaseConnection(dbFile
, 12);
19 let now
= Date
.now() * 1000; // date in microseconds
20 let pastExpiry
= Math
.round(now
/ 1e6
- 1000);
21 let futureExpiry
= Math
.round(now
/ 1e6
+ 1000);
23 let host
= "cookie-host1.com";
25 let manyCookies
= 180;
27 let cookiesPurged
= manyCookies
- cookieMax
;
29 // add many expired cookies for a single host
30 for (let i
= 0; i
< manyCookies
; i
++) {
31 let cookie
= new Cookie(
43 schema12db
.insertCookie(cookie
);
46 // check that the cookies were added to the db
47 Assert
.equal(do_count_cookies_in_db(schema12db
.db
), manyCookies
);
49 do_count_cookies_in_db(schema12db
.db
, "cookie-host1.com"),
53 // startup the cookie service and check the cookie count
54 let validCookies
= Services
.cookies
.countCookiesFromHost(host
); // includes expired cookies
55 Assert
.equal(validCookies
, manyCookies
);
57 // add a cookie - this will trigger the purge
68 Ci
.nsICookie
.SAMESITE_NONE
, // SameSite
69 Ci
.nsICookie
.SCHEME_HTTPS
72 // check that we purge down to the cookieMax (plus the cookie added)
73 validCookies
= Services
.cookies
.countCookiesFromHost(host
);
74 Assert
.equal(validCookies
, cookieMax
+ 1);
76 // check that the telemetry fired
77 let cpem
= await Glean
.networking
.cookiePurgeEntryMax
.testGetValue();
78 Assert
.equal(cpem
.sum
, cookiesPurged
, "Purge the expected number of cookies");