Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test failed 43 times in the preceding 30 days. quicksearch this test
- Manifest: browser/base/content/test/sanitize/browser.toml
/* Any copyright is dedicated to the Public Domain.
const { SiteDataTestUtils } = ChromeUtils.importESModule(
);
const { PromiseTestUtils } = ChromeUtils.importESModule(
);
XPCOMUtils.defineLazyServiceGetter(
this,
"sas",
"@mozilla.org/storage/activity-service;1",
"nsIStorageActivityService"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"swm",
"@mozilla.org/serviceworkers/manager;1",
"nsIServiceWorkerManager"
);
const oneHour = 3600000000;
const fiveHours = oneHour * 5;
function waitForUnregister(host) {
return new Promise(resolve => {
let listener = {
onUnregister: registration => {
if (registration.principal.host != host) {
return;
}
swm.removeListener(listener);
resolve(registration);
},
};
swm.addListener(listener);
});
}
function moveOriginInTime(principals, endDate, host) {
for (let i = 0; i < principals.length; ++i) {
let principal = principals.queryElementAt(i, Ci.nsIPrincipal);
if (principal.host == host) {
sas.moveOriginInTime(principal, endDate - fiveHours);
return true;
}
}
return false;
}
// We will be removing the ["cookies","offlineApps"] option once we remove the
let prefs = [["cookiesAndStorage"], ["cookies", "offlineApps"]];
for (let itemsToClear of prefs) {
add_task(async function testWithRange() {
// We have intermittent occurrences of NS_ERROR_ABORT being
// thrown at closing database instances when using Santizer.sanitize().
// This does not seem to impact cleanup, since our tests run fine anyway.
PromiseTestUtils.allowMatchingRejectionsGlobally(/NS_ERROR_ABORT/);
await SpecialPowers.pushPrefEnv({
set: [
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.testing.enabled", true],
],
});
// The service may have picked up activity from prior tests in this run.
// Clear it.
sas.testOnlyReset();
let endDate = Date.now() * 1000;
let principals = sas.getActiveOrigins(endDate - oneHour, endDate);
is(principals.length, 0, "starting from clear activity state");
info("sanitize: " + itemsToClear.join(", "));
await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false });
await createDummyDataForHost("example.org");
await createDummyDataForHost("example.com");
endDate = Date.now() * 1000;
principals = sas.getActiveOrigins(endDate - oneHour, endDate);
ok(!!principals, "We have an active origin.");
Assert.greaterOrEqual(principals.length, 2, "We have an active origin.");
let found = 0;
for (let i = 0; i < principals.length; ++i) {
let principal = principals.queryElementAt(i, Ci.nsIPrincipal);
if (principal.host == "example.org" || principal.host == "example.com") {
found++;
}
}
is(found, 2, "Our origins are active.");
ok(
"We have indexedDB data for example.org"
);
ok(
"We have serviceWorker data for example.org"
);
ok(
"We have indexedDB data for example.com"
);
ok(
"We have serviceWorker data for example.com"
);
// Let's move example.com in the past.
ok(
moveOriginInTime(principals, endDate, "example.com"),
"Operation completed!"
);
let p = waitForUnregister("example.org");
// Clear it
info("sanitize: " + itemsToClear.join(", "));
await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false });
await p;
ok(
"We don't have indexedDB data for example.org"
);
ok(
"We don't have serviceWorker data for example.org"
);
ok(
"We still have indexedDB data for example.com"
);
ok(
"We still have serviceWorker data for example.com"
);
// We have to move example.com in the past because how we check IDB triggers
// a storage activity.
ok(
moveOriginInTime(principals, endDate, "example.com"),
"Operation completed!"
);
// Let's call the clean up again.
info("sanitize again to ensure clearing doesn't expand the activity scope");
await Sanitizer.sanitize(itemsToClear, { ignoreTimespan: false });
ok(
"We still have indexedDB data for example.com"
);
ok(
"We still have serviceWorker data for example.com"
);
ok(
"We don't have indexedDB data for example.org"
);
ok(
"We don't have serviceWorker data for example.org"
);
sas.testOnlyReset();
// Clean up.
await SiteDataTestUtils.clear();
});
add_task(async function testExceptionsOnShutdown() {
await createDummyDataForHost("example.org");
await createDummyDataForHost("example.com");
// Set exception for example.org to not get cleaned
PermissionTestUtils.add(
originALLOW,
"cookie",
Ci.nsICookiePermission.ACCESS_ALLOW
);
ok(
"We have indexedDB data for example.org"
);
ok(
"We have serviceWorker data for example.org"
);
ok(
"We have indexedDB data for example.com"
);
ok(
"We have serviceWorker data for example.com"
);
await SpecialPowers.pushPrefEnv({
set: [
["browser.sanitizer.loglevel", "All"],
["privacy.clearOnShutdown.offlineApps", true],
["privacy.sanitize.sanitizeOnShutdown", true],
],
});
// Clear it
await Sanitizer.runSanitizeOnShutdown();
// Data for example.org should not have been cleared
ok(
"We still have indexedDB data for example.org"
);
ok(
"We still have serviceWorker data for example.org"
);
// Data for example.com should be cleared
ok(
"We don't have indexedDB data for example.com"
);
ok(
"We don't have serviceWorker data for example.com"
);
// Clean up
await SiteDataTestUtils.clear();
Services.perms.removeAll();
});
}