File: clear-cache-bfcache.sub.https.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,609,412 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (115 lines) | stat: -rw-r--r-- 3,373 bytes parent folder | download | duplicates (10)
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
110
111
112
113
114
115
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Clear-Site-Data: cache for bfcache</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="support/clear-cache-helper.sub.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="/common/utils.js"></script>
<script src="/html/browsers/browsing-the-web/back-forward-cache/resources/helper.sub.js"></script>
<script type="module">

const sameOrigin =
  'https://{{host}}:{{ports[https][0]}}';
const subdomainOrigin =
  'https://{{hosts[][www2]}}:{{ports[https][0]}}';
const crossSiteOrigin =
  'https://{{hosts[alt][]}}:{{ports[https][0]}}';

// The tests are built on top of the back-forward-cache test harness.
// Here is the steps for the tests:
// 1. Open a new window and navigate to a test URL.
// 2. Navigate the window to a second page.
// 3. Trigger the clear-site-data header either by window.open() or loading an
//    iframe from the second page.
// 4. Navigate back to the first page.
// 5. Assert that the first page is or is not cached.

function runBfCacheClearTest(params, description) {
  runBfcacheTest(
    {
      targetOrigin: sameOrigin,
      scripts: ["/clear-site-data/support/clear-cache-helper.sub.js"],
      funcBeforeBackNavigation: async (getUrlParams, mode) => {

        const cacheHelper = self.crypto.randomUUID();
        const testUrl = getUrl(cacheHelper, getUrlParams);

        let clearingPromise;
        if (mode === "window") {
          clearingPromise = new Promise(resolve => {
            window.addEventListener("message", resolve, {once: true});
            window.open(testUrl);
          });
        } else if (mode === "iframe") {
          clearingPromise = new Promise(resolve => {
            const iframe = document.createElement("iframe");
            iframe.src = testUrl;
            document.body.appendChild(iframe);
            iframe.onload = resolve;
          });
        } else {
          throw new Error("Unsupported mode");
        }

        await clearingPromise;
      },
      argsBeforeBackNavigation: [params.getUrlParams, params.mode],
      ...params,
    },
    description
  );
}

runBfCacheClearTest(
  {
    getUrlParams: {
      clear: "cache",
    },
    mode: "iframe",
    shouldBeCached: false,
  },
  "BfCached document shouldn't be cached after receiving clear-cache header from the same origin."
);

runBfCacheClearTest(
  {
    targetOrigin: subdomainOrigin,
    getUrlParams: {
      subdomain: true,
      clear: "cache",
    },
    mode: "iframe",
    shouldBeCached: true,
  },
  "BfCached document should be cached after receiving clear-cache header from a subdomain."
);

runBfCacheClearTest(
  {
    targetOrigin: crossSiteOrigin,
    getUrlParams: {
      secondOrigin: true,
      clear: "cache",
    },
    mode: "iframe",
    shouldBeCached: true,
  },
  "BfCached document should be cached after receiving clear-cache header from another site."
);

runBfCacheClearTest(
  {
    getUrlParams: {
      clear: "cache",
    },
    mode: "window",
    shouldBeCached: false,
  },
  "BfCached document shouldn't be cached after receiving clear-cache header from another window."
);

</script>