Bug 1949932 - Part 2: Use ChromeUtils.clearResourceCache and Services.cache2.clear for clearing cache in testcases for consistency. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D242729
This commit is contained in:
@@ -25,40 +25,14 @@ async function reloadAndGetCounter(tab) {
|
||||
return getCounter(tab);
|
||||
}
|
||||
|
||||
function clearAllCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function clearJSCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_JS_CACHE,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function clearNetworkCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_NETWORK_CACHE,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_withoutNavigationCache() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", false]],
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
const resetResponse = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await resetResponse.text(), "reset", "Server state should be reset");
|
||||
@@ -76,7 +50,8 @@ add_task(async function test_withoutNavigationCache() {
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
1,
|
||||
@@ -88,17 +63,17 @@ add_task(async function test_withoutNavigationCache() {
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearJSCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
is(await reloadAndGetCounter(tab), 1, "network cache should be used.");
|
||||
|
||||
await clearNetworkCache();
|
||||
Services.cache2.clear();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
2,
|
||||
"request should reach the server after network cache is cleared."
|
||||
);
|
||||
|
||||
await clearJSCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
is(await reloadAndGetCounter(tab), 2, "network cache should be used.");
|
||||
|
||||
BrowserTestUtils.removeTab(tab);
|
||||
@@ -110,7 +85,8 @@ add_task(async function test_withNavigationCache() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
const resetResponse = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await resetResponse.text(), "reset", "Server state should be reset");
|
||||
@@ -128,7 +104,8 @@ add_task(async function test_withNavigationCache() {
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
1,
|
||||
@@ -140,19 +117,19 @@ add_task(async function test_withNavigationCache() {
|
||||
"cache should be used for subsequent load."
|
||||
);
|
||||
|
||||
await clearJSCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
is(await reloadAndGetCounter(tab), 1, "network cache should be used.");
|
||||
|
||||
// The above reload loads from the network cache, and the JS cache is
|
||||
// re-created.
|
||||
|
||||
await clearNetworkCache();
|
||||
Services.cache2.clear();
|
||||
is(await reloadAndGetCounter(tab), 1, "JS cache should be used.");
|
||||
|
||||
// The above reload loads from the JS cache.
|
||||
// Currently, network cache is not re-created from the JS cache.
|
||||
|
||||
await clearJSCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
is(
|
||||
await reloadAndGetCounter(tab),
|
||||
2,
|
||||
|
||||
@@ -4,15 +4,6 @@ const TEST_URL =
|
||||
const TEST_SCRIPT_URL =
|
||||
"https://example.com/browser/dom/tests/browser/cacheable_non_cacheable_server.sjs";
|
||||
|
||||
function clearAllCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function () {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", true]],
|
||||
@@ -23,7 +14,8 @@ add_task(async function () {
|
||||
const response1 = await fetch(TEST_SCRIPT_URL + "?use-cacheable");
|
||||
is(await response1.text(), "ok", "Server state should be set");
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
const TEST_URL =
|
||||
"https://example.com/browser/dom/tests/browser/page_scriptCache_load_events.html";
|
||||
|
||||
function clearAllCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function testOrder() {
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
const tab = await BrowserTestUtils.openNewForegroundTab({
|
||||
gBrowser,
|
||||
|
||||
@@ -1,12 +1,3 @@
|
||||
async function clearAllCache() {
|
||||
await new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const URL_BASE = "https://example.com/browser/dom/tests/browser/";
|
||||
const URL_BASE2 = "https://example.net/browser/dom/tests/browser/";
|
||||
|
||||
@@ -177,7 +168,8 @@ add_task(async function testCompleteCacheAfterReload() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
@@ -239,7 +231,8 @@ add_task(async function testCompleteCacheInSameDocument() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
@@ -331,7 +324,8 @@ add_task(async function testNoCacheReload() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
@@ -393,7 +387,8 @@ add_task(async function test_NoCORS() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
@@ -454,7 +449,8 @@ add_task(async function test_NoCORS_TAO() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
@@ -515,7 +511,8 @@ add_task(async function test_CORS() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
@@ -577,7 +574,8 @@ add_task(async function test_CORS_TAO() {
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
|
||||
@@ -26,15 +26,6 @@ async function reloadAndGetCounter(tab, query) {
|
||||
return getCounter(tab, query);
|
||||
}
|
||||
|
||||
function clearAllCache() {
|
||||
return new Promise(function (resolve) {
|
||||
Services.clearData.deleteData(
|
||||
Ci.nsIClearDataService.CLEAR_ALL_CACHES,
|
||||
resolve
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function test_redirectCache() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", true]],
|
||||
@@ -80,7 +71,8 @@ add_task(async function test_redirectCache() {
|
||||
];
|
||||
|
||||
for (const { query, cachedCounter, log } of tests) {
|
||||
await clearAllCache();
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
const resetResponse = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await resetResponse.text(), "reset", "Server state should be reset");
|
||||
|
||||
Reference in New Issue
Block a user