Bug 1536058 - Add a Test for cache isolation r=ckerschb,Ehsan
authorSebastian Streich <sstreich@mozilla.com>
Thu, 22 Aug 2019 15:21:09 +0000
changeset 553205 4fe91f01854e23e26382d491b4feae4bca13a222
parent 553204 a5e791146ef541d794bb74ac730c0fa40985e4d4
child 553206 bc3079511334f459cbed038a684b74684d0636ba
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb, Ehsan
bugs1536058
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1536058 - Add a Test for cache isolation r=ckerschb,Ehsan *** Adding Ehsans nits *** Differential Revision: https://phabricator.services.mozilla.com/D40613
dom/security/test/general/browser.ini
dom/security/test/general/file_cache_splitting_server.sjs
dom/security/test/general/file_cache_splitting_window.html
dom/security/test/general/mochitest.ini
dom/security/test/general/test_cache_split.html
--- a/dom/security/test/general/browser.ini
+++ b/dom/security/test/general/browser.ini
@@ -19,8 +19,10 @@ support-files =
   file_FTP_console_warning.html
 [browser_test_assert_systemprincipal_documents.js]
 skip-if = !nightly_build
 support-files =
   file_assert_systemprincipal_documents.html
   file_assert_systemprincipal_documents_iframe.html
 [browser_test_referrer_loadInOtherProcess.js]
 skip-if = fission # Times out
+
+
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/file_cache_splitting_server.sjs
@@ -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;
+        }
+    `);
+}
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/file_cache_splitting_window.html
@@ -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>
--- a/dom/security/test/general/mochitest.ini
+++ b/dom/security/test/general/mochitest.ini
@@ -19,20 +19,24 @@ support-files =
   file_same_site_cookies_toplevel_set_cookie.sjs
   file_same_site_cookies_blob_iframe_navigation.html
   file_same_site_cookies_blob_iframe_inclusion.html
   file_same_site_cookies_iframe.html
   file_same_site_cookies_iframe.sjs
   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]
 skip-if = toolkit == 'android' # intermittent failure
 [test_block_toplevel_data_img_navigation.html]
 skip-if = toolkit == 'android' # intermittent failure
 [test_allow_opening_data_pdf.html]
 skip-if = toolkit == 'android'
new file mode 100644
--- /dev/null
+++ b/dom/security/test/general/test_cache_split.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>