Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / storage / partitioned-estimate-usage-details-caches.tentative.https.sub.html
blob2eac826eb10d2ec99b5b5e927b0e28d5ea2c825d
1 <!DOCTYPE html>
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>
8 <body>
9 <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]}}";
24 let details = {};
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);
31 async_test(test => {
32 if (location.origin === alt_origin)
33 return;
35 let cache, cache_url;
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);
43 });
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;
56 // Some cleanup
57 test.step(async () => await cache.delete(cache_url));
59 test.step(() => {
60 assert_true(details.cross_site.init == 0, "Usage should be 0.");
61 assert_equals(details.same_site.init, details.after);
62 });
64 test.done();
66 }));
67 }, "Partitioned estimate() usage details for caches test.");
68 </script>
69 </body>