Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_cookie_partitioned_attribute.js
blobf1f3744831609748358fbe246e1c515aa1755c17
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;
10 });
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(
27 "cookie-name" + i,
28 "cookie-value" + i,
29 hostNonPartitioned,
30 "/", // path
31 now, // expiry
32 now, // last accessed
33 now, // creation time
34 false, // session
35 false, // secure
36 false, // http-only
37 false, // inBrowserElement
38 {} // OA
40 schema13db.insertCookie(cookie);
43 // add some partitioned cookies
44 let nPartitioned = 5;
45 let hostPartitioned = "host-partitioned.com";
46 for (let i = 0; i < nPartitioned; i++) {
47 let cookie = new Cookie(
48 "cookie-name" + i,
49 "cookie-value" + i,
50 hostPartitioned,
51 "/", // path
52 now, // expiry
53 now, // last accessed
54 now, // creation time
55 false, // session
56 false, // secure
57 false, // http-only
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);
79 schema13db.close();
80 });