1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
const { SiteDataManager } = ChromeUtils.import(
"resource:///modules/SiteDataManager.jsm"
);
const { SiteDataTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/SiteDataTestUtils.sys.mjs"
);
const EXAMPLE_ORIGIN = "https://www.example.com";
const EXAMPLE_ORIGIN_2 = "https://example.org";
add_task(function setup() {
do_get_profile();
});
add_task(async function testGetSitesByContainers() {
SiteDataTestUtils.addToCookies({
origin: EXAMPLE_ORIGIN,
name: "foo1",
value: "bar1",
originAttributes: { userContextId: "1" },
});
SiteDataTestUtils.addToCookies({
origin: EXAMPLE_ORIGIN,
name: "foo2",
value: "bar2",
originAttributes: { userContextId: "2" },
});
SiteDataTestUtils.addToCookies({
origin: EXAMPLE_ORIGIN,
name: "foo3",
value: "bar3",
originAttributes: { userContextId: "2" },
});
SiteDataTestUtils.addToCookies({
origin: EXAMPLE_ORIGIN_2,
name: "foo",
value: "bar",
originAttributes: { userContextId: "3" },
});
await SiteDataTestUtils.addToIndexedDB(
EXAMPLE_ORIGIN + "^userContextId=1",
4096
);
await SiteDataTestUtils.addToIndexedDB(
EXAMPLE_ORIGIN_2 + "^userContextId=3",
2048
);
await SiteDataManager.updateSites();
let sites = await SiteDataManager.getSites();
let site1Container1 = sites
.find(site => site.baseDomain == "example.com")
.containersData.get(1);
let site1Container2 = sites
.find(site => site.baseDomain == "example.com")
.containersData.get(2);
let site2Container3 = sites
.find(site => site.baseDomain == "example.org")
.containersData.get(3);
Assert.equal(
sites.reduce(
(accumulator, site) => accumulator + site.containersData.size,
0
),
3,
"Has the correct number of sites by containers"
);
Assert.equal(
site1Container1.cookiesBlocked,
1,
"Has the correct number of cookiesBlocked by containers"
);
Assert.greater(
site1Container1.quotaUsage,
4096,
"Has correct usage for example.com^userContextId=1"
);
Assert.ok(
typeof site1Container1.lastAccessed.getDate == "function",
"lastAccessed for example.com^userContextId=1 is a Date"
);
Assert.ok(
site1Container1.lastAccessed > Date.now() - 60 * 1000,
"lastAccessed for example.com^userContextId=1 happened recently"
);
Assert.equal(
site1Container2.cookiesBlocked,
2,
"Has the correct number of cookiesBlocked by containers"
);
Assert.equal(
site1Container2.quotaUsage,
0,
"Has correct usage for example.org^userContextId=2"
);
Assert.ok(
typeof site1Container2.lastAccessed.getDate == "function",
"lastAccessed for example.com^userContextId=2 is a Date"
);
Assert.equal(
site2Container3.cookiesBlocked,
1,
"Has the correct number of cookiesBlocked by containers"
);
Assert.greater(
site2Container3.quotaUsage,
2048,
"Has correct usage for example.org^userContextId=3"
);
Assert.ok(
typeof site2Container3.lastAccessed.getDate == "function",
"lastAccessed for example.org^userContextId=3 is a Date"
);
Assert.ok(
site2Container3.lastAccessed > Date.now() - 60 * 1000,
"lastAccessed for example.org^userContextId=3 happened recently"
);
await SiteDataTestUtils.clear();
});
|