2 <meta name=help
href=
"https://privacycg.github.io/storage-partitioning/">
3 <title>Partitioned estimate() usage details for caches test
</title>
4 <script src=
"/resources/testharness.js"></script>
5 <script src=
"/resources/testharnessreport.js"></script>
6 <script src=
"/common/utils.js"></script>
10 const usageDetails
= async () =>
11 (await navigator
.storage
.estimate()).usageDetails
.caches
|| 0;
13 const createSomeUsage
= async () => {
14 const cache_name
= token();
15 const cache_url
= `/foo-${cache_name}`;
16 const cache
= await caches
.open(cache_name
);
17 await cache
.put(cache_url
, new Response('x'.repeat(128)));
18 return [cache
, cache_url
];
21 const testPath
= () => location
.pathname
.split("/").slice(0, -1).join("/");
23 let alt_origin
= "https://{{hosts[alt][]}}:{{ports[https][0]}}";
26 const iframe
= document
.createElement("iframe");
27 iframe
.src
= `https://{{host}}:{{ports[https][0]}}${testPath()}` +
28 `/resources/partitioned-estimate-usage-details-caches-helper-frame.html`
29 document
.body
.appendChild(iframe
);
32 if (location
.origin
=== alt_origin
)
36 test
.step(async () => {
37 details
.init
= await
usageDetails();
38 [cache
, cache_url
] = await
createSomeUsage(test
);
39 details
.after
= await
usageDetails();
40 assert_greater_than(details
.after
, details
.init
);
42 iframe
.contentWindow
.postMessage("get-details", iframe
.origin
);
45 window
.addEventListener("message", test
.step_func(event
=> {
46 if (event
.data
.source
=== "same-site") {
47 details
.same_site
= event
.data
;
49 const cross_site_window
= window
50 .open(`${alt_origin}${location.pathname}`, "", "noopener=false");
51 test
.add_cleanup(() => cross_site_window
.close());
53 if (event
.data
.source
=== "cross-site") {
54 details
.cross_site
= event
.data
;
57 test
.step(async () => await cache
.delete(cache_url
));
60 assert_true(details
.cross_site
.init
== 0, "Usage should be 0.");
61 assert_equals(details
.same_site
.init
, details
.after
);
67 }, "Partitioned estimate() usage details for caches test.");