1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/ */
4 function count_IsPartitioned(bool
) {
5 var cookieCountIsPartitioned
= 0;
6 Services
.cookies
.cookies
.forEach(cookie
=> {
7 if (cookie
.isPartitioned
=== bool
) {
8 cookieCountIsPartitioned
+= 1;
11 return cookieCountIsPartitioned
;
14 add_task(async
function test_IsPartitioned() {
15 let profile
= do_get_profile();
16 let dbFile
= do_get_cookie_file(profile
);
17 Assert
.ok(!dbFile
.exists());
19 let schema13db
= new CookieDatabaseConnection(dbFile
, 13);
20 let now
= Date
.now() * 1000; // date in microseconds
22 // add some non-partitioned cookies for key
23 let nUnpartitioned
= 5;
24 let hostNonPartitioned
= "cookie-host-non-partitioned.com";
25 for (let i
= 0; i
< nUnpartitioned
; i
++) {
26 let cookie
= new Cookie(
37 false, // inBrowserElement
40 schema13db
.insertCookie(cookie
);
43 // add some partitioned cookies
45 let hostPartitioned
= "host-partitioned.com";
46 for (let i
= 0; i
< nPartitioned
; i
++) {
47 let cookie
= new Cookie(
58 false, // inBrowserElement
59 { partitionKey
: "(https,example.com)" }
61 schema13db
.insertCookie(cookie
);
64 Assert
.equal(do_count_cookies_in_db(schema13db
.db
), 10);
66 // Startup the cookie service and check the cookie counts by OA
67 let cookieCountNonPart
=
68 Services
.cookies
.countCookiesFromHost(hostNonPartitioned
); // includes expired cookies
69 Assert
.equal(cookieCountNonPart
, nUnpartitioned
);
70 let cookieCountPart
= Services
.cookies
.getCookiesFromHost(hostPartitioned
, {
71 partitionKey
: "(https,example.com)",
72 }).length
; // includes expired cookies
73 Assert
.equal(cookieCountPart
, nPartitioned
);
75 // Startup the cookie service and check the cookie counts by isPartitioned (IsPartitioned())
76 Assert
.equal(count_IsPartitioned(false), nUnpartitioned
);
77 Assert
.equal(count_IsPartitioned(true), nPartitioned
);