File: test_cache_split.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (109 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <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">
        SimpleTest.requestLongerTimeout(2);

        const CROSS_ORIGIN = "http://mochi.test:8888/";
        const SAME_ORIGIN= "https://example.com/";
        const PATH = "file_cache_splitting_server.sjs";

        async function getCount() {
            return fetch(`${PATH}?state`).then(r => r.text());
        }
        async function resetCount() {
            return fetch(`${PATH}?flush`).then(r => r.text());
        }
        async function ensureLoaded() {
            // This Fetch is geting the Response "1", once file_cache_splitting_isloaded
            // gets a request without a query String issued from the cache_splitting_window.html
            info("Waiting for Pageload");
            let result = await fetch("file_cache_splitting_isloaded.sjs?wait").then(r => r.text);
            info("Page has been Loaded");
            return result;
        }


        async function openAndLoadWindow(origin) {
            let isLoaded =  ensureLoaded();
            let url = `${origin}tests/dom/security/test/general/file_cache_splitting_window.html`;
            let w = window.open(url);
            // let ew = SpecialPowers.wrap(w);
            await isLoaded;
            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");
            SpecialPowers.ChromeUtils.clearResourceCache({
                types: ["stylesheet", "script"],
            });
            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;
            if (prefs) {
              await SpecialPowers.pushPrefEnv(prefs);
            }
            for (let step of steps) {
                await checkStep(step, name);
            }
            await clearCache();
        };


        add_task(
            async () =>
                runTest({
                    name: `Isolated Cache`,
                    steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
                })
        );
        // Test that cookieBehavior does not affect Cache Isolation
        for (let i = 0; i < SpecialPowers.Ci.nsICookieService.BEHAVIOR_LAST ; i++) {
            add_task(
                async () =>
                    runTest({
                        name: `cookieBehavior interaction ${i}`,
                        steps: [[SAME_ORIGIN, 1], [SAME_ORIGIN, 1], [CROSS_ORIGIN, 2]],
                        prefs: {
                            set: [
                                ["privacy.firstparty.isolate", false],
                                ["network.cookie.cookieBehavior", i],
                            ],
                        },
                    })
            );
        }
    </script>
</body>

</html>