Bug 1954639 - Part 2: Add container tests for SharedScriptCache. r=nbp
Differential Revision: https://phabricator.services.mozilla.com/D242303
This commit is contained in:
@@ -162,6 +162,13 @@ support-files = [
|
||||
"page_scriptCache_load_events.html",
|
||||
]
|
||||
|
||||
["browser_scriptCache_container.js"]
|
||||
skip-if = ["!nightly_build"]
|
||||
support-files = [
|
||||
"page_scriptCache_container.html",
|
||||
"counter_server.sjs",
|
||||
]
|
||||
|
||||
["browser_scriptCache_partition.js"]
|
||||
skip-if = ["!nightly_build"]
|
||||
support-files = [
|
||||
|
||||
59
dom/tests/browser/browser_scriptCache_container.js
Normal file
59
dom/tests/browser/browser_scriptCache_container.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const TEST_URL =
|
||||
"https://example.com/browser/dom/tests/browser/page_scriptCache_container.html";
|
||||
|
||||
const TEST_SCRIPT_URL =
|
||||
"https://example.com/browser/dom/tests/browser/counter_server.sjs";
|
||||
|
||||
async function testScriptCache({ enableCache }) {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.script_loader.navigation_cache", enableCache]],
|
||||
});
|
||||
registerCleanupFunction(() => SpecialPowers.popPrefEnv());
|
||||
|
||||
const response1 = await fetch(TEST_SCRIPT_URL + "?reset");
|
||||
is(await response1.text(), "reset", "Server state should be reset");
|
||||
|
||||
ChromeUtils.clearResourceCache();
|
||||
Services.cache2.clear();
|
||||
|
||||
async function getCounter(tab) {
|
||||
return SpecialPowers.spawn(tab.linkedBrowser, [], () => {
|
||||
return content.document.body.getAttribute("counter");
|
||||
});
|
||||
}
|
||||
|
||||
async function openTab(url, userContextId) {
|
||||
const tab = BrowserTestUtils.addTab(gBrowser, url, { userContextId });
|
||||
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
|
||||
return tab;
|
||||
}
|
||||
|
||||
// Loading script from different containers should use separate cache.
|
||||
const tab0 = await openTab(TEST_URL, 1);
|
||||
is(await getCounter(tab0), "0");
|
||||
|
||||
const tab1 = await openTab(TEST_URL, 2);
|
||||
is(await getCounter(tab1), "1");
|
||||
|
||||
// Reloading the page should use the cached script, for each container.
|
||||
await BrowserTestUtils.reloadTab(tab0);
|
||||
is(await getCounter(tab0), "0");
|
||||
|
||||
await BrowserTestUtils.reloadTab(tab1);
|
||||
is(await getCounter(tab1), "1");
|
||||
|
||||
BrowserTestUtils.removeTab(tab0);
|
||||
BrowserTestUtils.removeTab(tab1);
|
||||
}
|
||||
|
||||
add_task(async function testNoCache() {
|
||||
await testScriptCache({
|
||||
enableCache: false,
|
||||
});
|
||||
});
|
||||
|
||||
add_task(async function testCache() {
|
||||
await testScriptCache({
|
||||
enableCache: true,
|
||||
});
|
||||
});
|
||||
8
dom/tests/browser/page_scriptCache_container.html
Normal file
8
dom/tests/browser/page_scriptCache_container.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>per-container cache test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="counter_server.sjs"></script>
|
||||
</body>
|
||||
Reference in New Issue
Block a user