Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: os == 'android' OR condprof
- This test failed 27 times in the preceding 30 days. quicksearch this test
- Manifest: toolkit/components/cleardata/tests/unit/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
/**
* Test clearing cache.
*/
"use strict";
function getPartitionedLoadContextInfo(
{ scheme, topLevelBaseDomain, port },
originAttributes = {}
) {
return Services.loadContextInfo.custom(
false,
getOAWithPartitionKey(
{ scheme, topLevelBaseDomain, port },
originAttributes
)
);
}
add_task(async function test_deleteFromHost() {
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
await new Promise(aResolve => {
Services.clearData.deleteDataFromHost(
"example.com",
true,
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
value => {
Assert.equal(value, 0);
aResolve();
}
);
});
Assert.ok(
"The disk cache is cleared"
);
Assert.ok(
"The memory cache is cleared"
);
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
await SiteDataTestUtils.clear();
});
add_task(async function test_deleteFromPrincipal() {
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
let principal =
Services.scriptSecurityManager.createContentPrincipalFromOrigin(
);
await new Promise(aResolve => {
Services.clearData.deleteDataFromPrincipal(
principal,
true,
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
value => {
Assert.equal(value, 0);
aResolve();
}
);
});
Assert.ok(
"The disk cache is cleared"
);
Assert.ok(
"The memory cache is cleared"
);
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
await SiteDataTestUtils.clear();
});
add_task(async function test_deleteFromBaseDomain() {
for (let cacheType of ["disk", "memory"]) {
Assert.ok(
`The ${cacheType} cache has an entry.`
);
Assert.ok(
`The ${cacheType} cache has an entry.`
);
// Partitioned cache.
await SiteDataTestUtils.addCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.org" })
);
Assert.ok(
SiteDataTestUtils.hasCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.org" })
),
`The ${cacheType} cache has a partitioned entry`
);
await SiteDataTestUtils.addCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.com" })
);
Assert.ok(
SiteDataTestUtils.hasCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.com" })
),
`The ${cacheType} cache has a partitioned entry`
);
// Clear an unrelated base domain.
await new Promise(aResolve => {
Services.clearData.deleteDataFromSite(
"foo.com",
{},
true,
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
value => {
Assert.equal(value, 0);
aResolve();
}
);
});
// Should still have all cache entries.
Assert.ok(
`The ${cacheType} cache has an entry.`
);
Assert.ok(
`The ${cacheType} cache has an entry.`
);
Assert.ok(
SiteDataTestUtils.hasCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.org" })
),
`The ${cacheType} cache has a partitioned entry`
);
Assert.ok(
SiteDataTestUtils.hasCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.com" })
),
`The ${cacheType} cache has a partitioned entry`
);
// Clear data for example.com
await new Promise(aResolve => {
Services.clearData.deleteDataFromSite(
"example.com",
{},
true,
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
value => {
Assert.equal(value, 0);
aResolve();
}
);
});
Assert.ok(
`The ${cacheType} cache is cleared.`
);
Assert.ok(
`The ${cacheType} cache has an entry.`
);
Assert.ok(
!SiteDataTestUtils.hasCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.org" })
),
`The ${cacheType} cache is cleared.`
);
Assert.ok(
!SiteDataTestUtils.hasCacheEntry(
cacheType,
getPartitionedLoadContextInfo({ topLevelBaseDomain: "example.com" })
),
`The ${cacheType} cache is cleared.`
);
await SiteDataTestUtils.clear();
}
});
add_task(async function test_deleteAll() {
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
Assert.ok(
"The disk cache has an entry"
);
Assert.ok(
"The memory cache has an entry"
);
await new Promise(aResolve => {
Services.clearData.deleteData(
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
value => {
Assert.equal(value, 0);
aResolve();
}
);
});
Assert.ok(
"The disk cache is cleared"
);
Assert.ok(
"The memory cache is cleared"
);
Assert.ok(
"The disk cache is cleared"
);
Assert.ok(
"The memory cache is cleared"
);
await SiteDataTestUtils.clear();
});