Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: dom/indexedDB/test/mochitest-private.toml includes dom/indexedDB/test/mochitest-common.toml
- Manifest: dom/indexedDB/test/mochitest-regular.toml includes dom/indexedDB/test/mochitest-common.toml
<!--
Any copyright is dedicated to the Public Domain.
-->
<html>
<head>
<title>Indexed Database Blob Structured Clone Test</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript">
/**
* Test that structured cloning a Blob results in distinct backing files when
* stored in IndexedDB.
*
* Currently, IndexedDB deduplicates blobs based on Blob object identity.
* Structured cloning creates a new Blob instance with a different identity,
* so the two blobs are treated as distinct and stored separately on disk.
*
* This test verifies that behavior by ensuring the cloned Blob receives a
* different fileId.
*
* TODO: Once IndexedDB switches to using BlobImpl for deduplication,
* structured-cloned blobs that share the same underlying data should be
* deduplicated and mapped to the same fileId.
*/
async function testSteps()
{
const name = window.location.pathname;
const objectStoreName = "Blobs";
const blob = getRandomBlob(10000);
const clonedBlob = structuredClone(blob);
const blobData1 = { key: 1, blob, expectedFileId: 1 };
// TODO: After switching IndexedDB blob deduplication to use BlobImpl
// instead of Blob identity, this structured-cloned blob should reuse the
// same underlying file and have expectedFileId = 1.
const blobData2 = { key: 2, blob: clonedBlob, expectedFileId: 2 };
await SpecialPowers.pushPrefEnv({ set: [["dom.indexedDB.dataThreshold", -1]] });
let request = indexedDB.open(name, 1);
await expectingUpgrade(request);
let db = request.result;
db.onerror = errorHandler;
let objectStore = db.createObjectStore(objectStoreName, {});
objectStore.add(blobData1.blob, blobData1.key);
objectStore.add(blobData2.blob, blobData2.key);
await expectingSuccess(request);
objectStore = db.transaction([objectStoreName]).objectStore(objectStoreName);
request = objectStore.get(blobData1.key);
await requestSucceeded(request);
await verifyBlobAsync(request.result, blobData1.blob, blobData1.expectedFileId);
objectStore = db.transaction([objectStoreName]).objectStore(objectStoreName);
request = objectStore.get(blobData2.key);
await requestSucceeded(request);
await verifyBlobAsync(request.result, blobData2.blob, blobData2.expectedFileId);
is(bufferCache.length, 2, "Correct length");
}
</script>
<script type="text/javascript" src="file.js"></script>
<script type="text/javascript" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>