зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1536058 - Add a Test for cache isolation r=ckerschb,Ehsan
*** Adding Ehsans nits *** Differential Revision: https://phabricator.services.mozilla.com/D40613 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
444eb9179d
Коммит
140ba11647
|
@ -24,3 +24,5 @@ support-files =
|
|||
file_assert_systemprincipal_documents_iframe.html
|
||||
[browser_test_referrer_loadInOtherProcess.js]
|
||||
skip-if = fission # Times out
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
function handleRequest(request, response) {
|
||||
var receivedRequests = parseInt(getState("requests"));
|
||||
if (isNaN(receivedRequests)) {
|
||||
receivedRequests = 0;
|
||||
}
|
||||
if (request.queryString.includes("state")) {
|
||||
response.write(receivedRequests);
|
||||
return;
|
||||
}
|
||||
if (request.queryString.includes("flush")) {
|
||||
setState("requests", "0");
|
||||
response.write("OK");
|
||||
return;
|
||||
}
|
||||
response.setHeader("Cache-Control", "max-age=999999"); // Force caching
|
||||
response.setHeader("Content-Type", "text/css");
|
||||
receivedRequests = receivedRequests + 1;
|
||||
setState("requests", "" + receivedRequests);
|
||||
response.write(`
|
||||
.test{
|
||||
color:red;
|
||||
}
|
||||
.test h1{
|
||||
font-size:200px;
|
||||
}
|
||||
`);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Document</title>
|
||||
<link rel="stylesheet" href="http://mochi.test:8888/tests/dom/security/test/general/file_cache_splitting_server.sjs">
|
||||
</head>
|
||||
<body>
|
||||
<h1>HELLO WORLD!</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -24,10 +24,14 @@ support-files =
|
|||
file_same_site_cookies_about_navigation.html
|
||||
file_same_site_cookies_about_inclusion.html
|
||||
file_same_site_cookies_about.sjs
|
||||
file_cache_splitting_server.sjs
|
||||
file_cache_splitting_window.html
|
||||
|
||||
|
||||
[test_contentpolicytype_targeted_link_iframe.html]
|
||||
[test_nosniff.html]
|
||||
[test_cache_split.html]
|
||||
skip-if = fission || verify
|
||||
[test_nosniff_navigation.html]
|
||||
[test_block_script_wrong_mime.html]
|
||||
[test_block_toplevel_data_navigation.html]
|
||||
|
|
|
@ -0,0 +1,151 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Bug 1454721 - Add same-site cookie test for about:blank and about:srcdoc</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script src="/tests/SimpleTest/ChromeTask.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<img id="cookieImage">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
const SAME_ORIGIN = "http://mochi.test:8888/"
|
||||
const CROSS_ORIGIN = "http://example.com/";
|
||||
const PATH = "file_cache_splitting_server.sjs";
|
||||
|
||||
const Ci = SpecialPowers.Ci;
|
||||
|
||||
async function getCount() {
|
||||
return fetch(`${PATH}?state`).then(r => r.text());
|
||||
}
|
||||
async function resetCount() {
|
||||
return fetch(`${PATH}?flush`).then(r => r.text());
|
||||
}
|
||||
function ensureLoaded(win) {
|
||||
return new Promise((res, err) => {
|
||||
var superSadCheck = setInterval(() => {
|
||||
try {
|
||||
if (win.document.readyState === "complete") {
|
||||
clearInterval(superSadCheck);
|
||||
res(win);
|
||||
}
|
||||
} catch (error) { err(error) }
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function openAndLoadWindow(origin) {
|
||||
let url = `${origin}tests/dom/security/test/general/file_cache_splitting_window.html`;
|
||||
let w = window.open(url);
|
||||
let ew = SpecialPowers.wrap(w);
|
||||
await ensureLoaded(ew);
|
||||
return w;
|
||||
}
|
||||
|
||||
async function checkStep(step = [SAME_ORIGIN, 1], name) {
|
||||
info(`Doing Step ${JSON.stringify(step)}`);
|
||||
let url = step[0];
|
||||
let should_count = step[1];
|
||||
let w = await openAndLoadWindow(url);
|
||||
let count = await getCount();
|
||||
ok(
|
||||
count == should_count,
|
||||
`${name} req to: ${
|
||||
url == SAME_ORIGIN ? "Same Origin" : "Cross Origin"
|
||||
} expected ${should_count} request to Server, got ${count}`
|
||||
);
|
||||
w.close()
|
||||
}
|
||||
async function clearCache(){
|
||||
info("Clearing Cache");
|
||||
await ChromeTask.spawn(null,(()=>{
|
||||
Services.cache2.clear();
|
||||
}));
|
||||
}
|
||||
async function runTest(test) {
|
||||
info(`Starting Job with - ${test.steps.length} - Requests`);
|
||||
await resetCount();
|
||||
let { prefs, steps, name } = test;
|
||||
await SpecialPowers.pushPrefEnv(prefs);
|
||||
for (let step of steps) {
|
||||
await checkStep(step, name);
|
||||
}
|
||||
await clearCache();
|
||||
};
|
||||
|
||||
|
||||
add_task(
|
||||
async () =>
|
||||
await runTest({
|
||||
name: `Isolated Cache`,
|
||||
steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
|
||||
prefs: {
|
||||
set: [["browser.cache.cache_isolation", true]],
|
||||
},
|
||||
})
|
||||
);
|
||||
// Negative Test: The CROSS_ORIGIN should be able to
|
||||
// acess the cache of SAME_ORIGIN
|
||||
add_task(
|
||||
async () =>
|
||||
await runTest({
|
||||
name: `Non Isolated Cache`,
|
||||
steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 1]],
|
||||
prefs: {
|
||||
set: [["browser.cache.cache_isolation", false]],
|
||||
},
|
||||
})
|
||||
);
|
||||
// Test that FPI does not affect Cache Isolation
|
||||
add_task(
|
||||
async () =>
|
||||
await runTest({
|
||||
name: `FPI interaction`,
|
||||
steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
|
||||
prefs: {
|
||||
set: [
|
||||
["privacy.firstparty.isolate", true],
|
||||
["browser.cache.cache_isolation", true],
|
||||
],
|
||||
},
|
||||
})
|
||||
);
|
||||
// Test that cookieBehavior does not affect Cache Isolation
|
||||
for (let i = 0; i < Ci.nsICookieService.BEHAVIOR_LAST ; i++) {
|
||||
add_task(
|
||||
async () =>
|
||||
await runTest({
|
||||
name: `cookieBehavior interaction ${i}`,
|
||||
steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
|
||||
prefs: {
|
||||
set: [
|
||||
["privacy.firstparty.isolate", false],
|
||||
["browser.cache.cache_isolation", true],
|
||||
["network.cookie.cookieBehavior", i],
|
||||
],
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
add_task(
|
||||
async () =>
|
||||
await runTest({
|
||||
name: `FPI interaction - 2`,
|
||||
steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
|
||||
prefs: {
|
||||
set: [
|
||||
["privacy.firstparty.isolate", true],
|
||||
["browser.cache.cache_isolation", false],
|
||||
],
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче