Backed out changeset 7969278ce39f (bug 1869884) for causing failures on browser_sanit...
[gecko.git] / browser / base / content / test / sanitize / browser_sanitize-history.js
blobc9902d27cf1475c6758e546eabb348acfc79ffdf
1 /* Any copyright is dedicated to the Public Domain.
2  * http://creativecommons.org/publicdomain/zero/1.0/ */
4 // Tests that sanitizing history will clear storage access permissions
5 // for sites without cookies or site data.
6 add_task(async function sanitizeStorageAccessPermissions() {
7   let categories = ["history", "historyAndFormData"];
9   for (let pref of categories) {
10     await new Promise(resolve => {
11       Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
12     });
14     await SiteDataTestUtils.addToIndexedDB("https://sub.example.org");
15     await SiteDataTestUtils.addToCookies({ origin: "https://example.com" });
17     PermissionTestUtils.add(
18       "https://example.org",
19       "storageAccessAPI",
20       Services.perms.ALLOW_ACTION
21     );
22     PermissionTestUtils.add(
23       "https://example.com",
24       "storageAccessAPI",
25       Services.perms.ALLOW_ACTION
26     );
27     PermissionTestUtils.add(
28       "http://mochi.test",
29       "storageAccessAPI",
30       Services.perms.ALLOW_ACTION
31     );
33     // Add some time in between taking the snapshot of the timestamp
34     // to avoid flakyness.
35     // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
36     await new Promise(c => setTimeout(c, 100));
37     let timestamp = Date.now();
38     // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
39     await new Promise(c => setTimeout(c, 100));
41     PermissionTestUtils.add(
42       "http://example.net",
43       "storageAccessAPI",
44       Services.perms.ALLOW_ACTION
45     );
47     await Sanitizer.sanitize([pref], {
48       // Sanitizer and ClearDataService work with time range in PRTime (microseconds)
49       range: [timestamp * 1000, Date.now() * 1000],
50     });
52     Assert.equal(
53       PermissionTestUtils.testExactPermission(
54         "http://example.net",
55         "storageAccessAPI"
56       ),
57       Services.perms.UNKNOWN_ACTION
58     );
59     Assert.equal(
60       PermissionTestUtils.testExactPermission(
61         "http://mochi.test",
62         "storageAccessAPI"
63       ),
64       Services.perms.ALLOW_ACTION
65     );
66     Assert.equal(
67       PermissionTestUtils.testExactPermission(
68         "https://example.com",
69         "storageAccessAPI"
70       ),
71       Services.perms.ALLOW_ACTION
72     );
73     Assert.equal(
74       PermissionTestUtils.testExactPermission(
75         "https://example.org",
76         "storageAccessAPI"
77       ),
78       Services.perms.ALLOW_ACTION
79     );
81     await Sanitizer.sanitize([pref]);
83     Assert.equal(
84       PermissionTestUtils.testExactPermission(
85         "http://mochi.test",
86         "storageAccessAPI"
87       ),
88       Services.perms.UNKNOWN_ACTION
89     );
90     Assert.equal(
91       PermissionTestUtils.testExactPermission(
92         "http://example.net",
93         "storageAccessAPI"
94       ),
95       Services.perms.UNKNOWN_ACTION
96     );
97     Assert.equal(
98       PermissionTestUtils.testExactPermission(
99         "https://example.com",
100         "storageAccessAPI"
101       ),
102       Services.perms.ALLOW_ACTION
103     );
104     Assert.equal(
105       PermissionTestUtils.testExactPermission(
106         "https://example.org",
107         "storageAccessAPI"
108       ),
109       Services.perms.ALLOW_ACTION
110     );
112     await Sanitizer.sanitize([pref, "siteSettings"]);
114     Assert.equal(
115       PermissionTestUtils.testExactPermission(
116         "http://mochi.test",
117         "storageAccessAPI"
118       ),
119       Services.perms.UNKNOWN_ACTION
120     );
121     Assert.equal(
122       PermissionTestUtils.testExactPermission(
123         "https://example.com",
124         "storageAccessAPI"
125       ),
126       Services.perms.UNKNOWN_ACTION
127     );
128     Assert.equal(
129       PermissionTestUtils.testExactPermission(
130         "https://example.org",
131         "storageAccessAPI"
132       ),
133       Services.perms.UNKNOWN_ACTION
134     );
135   }