diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html')
-rw-r--r-- | test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html b/test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html new file mode 100644 index 0000000..98a1ed8 --- /dev/null +++ b/test/wpt/tests/storage/partitioned-estimate-usage-details-indexeddb.tentative.https.sub.html @@ -0,0 +1,84 @@ +<!DOCTYPE html> +<meta name=help href="https://privacycg.github.io/storage-partitioning/"> +<title>Partitioned estimate() usage details for indexeddb test</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/common/utils.js"></script> +<script src="./helpers.js"></script> +<script src="../IndexedDB/resources/support-promises.js"></script> + +<body> + <script> + const usageDetails = async () => + (await navigator.storage.estimate()).usageDetails.indexedDB || 0; + + const createSomeUsage = async (test) => { + // We use 100KB here because db compaction usually happens every few MB + // 100KB is large enough to avoid a false positive (small amounts of + // metadata getting written for some random reason), and small enough to + // avoid compaction with a reasonably high probability. + const write_size = 1024 * 100; + const object_store_name = token(); + const db_name = self.location.pathname; + + await indexedDB.deleteDatabase(db_name); + const db = await createDB(db_name, object_store_name, test); + const transaction = db.transaction(object_store_name, 'readwrite'); + const value_to_store = largeValue(write_size, Math.random() * 255); + transaction.objectStore(object_store_name).add(value_to_store, 1); + + await transactionPromise(transaction); + return db; + } + + const testPath = () => location.pathname.split("/").slice(0, -1).join("/"); + + let alt_origin = "https://{{hosts[alt][]}}:{{ports[https][0]}}"; + let details = {}; + + const iframe = document.createElement("iframe"); + iframe.src = `https://{{host}}:{{ports[https][0]}}${testPath()}/resources` + + `/partitioned-estimate-usage-details-indexeddb-helper-frame.html`; + document.body.appendChild(iframe); + + async_test(test => { + if (location.origin === alt_origin) + return; + + let db; + window.addEventListener("message", test.step_func(async event => { + if (event.data === "iframe-is-ready") { + details.init = await usageDetails(); + db = await createSomeUsage(test); + details.after = await usageDetails(); + assert_greater_than(details.after, details.init); + + iframe.contentWindow.postMessage("get-details", iframe.origin); + } + })); + + window.addEventListener("message", test.step_func(event => { + if (event.data.source === "same-site") { + details.same_site = event.data; + + const cross_site_window = window + .open(`${alt_origin}${location.pathname}`, "", "noopener=false"); + test.add_cleanup(() => cross_site_window.close()); + } + if (event.data.source === "cross-site") { + details.cross_site = event.data; + + // Some cleanup + test.step(async () => await db.close()); + + test.step(() => { + assert_true(details.cross_site.init == 0, "Usage should be 0."); + assert_equals(details.same_site.init, details.after); + }); + + test.done(); + } + })); + }, "Partitioned estimate() usage details for indexeddb test."); + </script> +</body> |