tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_cache_split.html (3925B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 
      4 <head>
      5    <meta charset="utf-8">
      6    <title>Bug 1454721 - Add same-site cookie test for about:blank and about:srcdoc</title>
      7    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8    <script src="/tests/SimpleTest/ChromeTask.js"></script>
      9    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10 </head>
     11 
     12 <body>
     13    <img id="cookieImage">
     14    <script class="testbody" type="text/javascript">
     15        SimpleTest.requestLongerTimeout(2);
     16 
     17        const CROSS_ORIGIN = "http://mochi.test:8888/";
     18        const SAME_ORIGIN= "https://example.com/";
     19        const PATH = "file_cache_splitting_server.sjs";
     20 
     21        async function getCount() {
     22            return fetch(`${PATH}?state`).then(r => r.text());
     23        }
     24        async function resetCount() {
     25            return fetch(`${PATH}?flush`).then(r => r.text());
     26        }
     27        async function ensureLoaded() {
     28            // This Fetch is geting the Response "1", once file_cache_splitting_isloaded
     29            // gets a request without a query String issued from the cache_splitting_window.html
     30            info("Waiting for Pageload");
     31            let result = await fetch("file_cache_splitting_isloaded.sjs?wait").then(r => r.text);
     32            info("Page has been Loaded");
     33            return result;
     34        }
     35 
     36 
     37        async function openAndLoadWindow(origin) {
     38            let isLoaded =  ensureLoaded();
     39            let url = `${origin}tests/dom/security/test/general/file_cache_splitting_window.html`;
     40            let w = window.open(url);
     41            // let ew = SpecialPowers.wrap(w);
     42            await isLoaded;
     43            return w;
     44        }
     45 
     46        async function checkStep(step = [SAME_ORIGIN, 1], name) {
     47            info(`Doing Step ${JSON.stringify(step)}`);
     48            let url = step[0];
     49            let should_count = step[1];
     50            let w = await openAndLoadWindow(url);
     51            let count = await getCount();
     52            ok(
     53                count == should_count,
     54                `${name} req to: ${
     55                url == SAME_ORIGIN ? "Same Origin" : "Cross Origin"
     56                } expected ${should_count} request to Server, got ${count}`
     57            );
     58            w.close()
     59        }
     60        async function clearCache(){
     61            info("Clearing Cache");
     62            SpecialPowers.ChromeUtils.clearResourceCache({
     63                types: ["stylesheet", "script"],
     64            });
     65            await ChromeTask.spawn(null,(()=>{
     66                Services.cache2.clear();
     67            }));
     68        }
     69        async function runTest(test) {
     70            info(`Starting Job with - ${test.steps.length} - Requests`);
     71            await resetCount();
     72            let { prefs, steps, name } = test;
     73            if (prefs) {
     74              await SpecialPowers.pushPrefEnv(prefs);
     75            }
     76            for (let step of steps) {
     77                await checkStep(step, name);
     78            }
     79            await clearCache();
     80        };
     81 
     82 
     83        add_task(
     84            async () =>
     85                runTest({
     86                    name: `Isolated Cache`,
     87                    steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
     88                })
     89        );
     90        // Test that cookieBehavior does not affect Cache Isolation
     91        for (let i = 0; i < SpecialPowers.Ci.nsICookieService.BEHAVIOR_LAST ; i++) {
     92            add_task(
     93                async () =>
     94                    runTest({
     95                        name: `cookieBehavior interaction ${i}`,
     96                        steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
     97                        prefs: {
     98                            set: [
     99                                ["privacy.firstparty.isolate", false],
    100                                ["network.cookie.cookieBehavior", i],
    101                            ],
    102                        },
    103                    })
    104            );
    105        }
    106    </script>
    107 </body>
    108 
    109 </html>