summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_blob_file_backed.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/indexedDB/test/unit/test_blob_file_backed.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/indexedDB/test/unit/test_blob_file_backed.js')
-rw-r--r--dom/indexedDB/test/unit/test_blob_file_backed.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_blob_file_backed.js b/dom/indexedDB/test/unit/test_blob_file_backed.js
new file mode 100644
index 0000000000..ba973d63d5
--- /dev/null
+++ b/dom/indexedDB/test/unit/test_blob_file_backed.js
@@ -0,0 +1,79 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* exported testGenerator, disableWorkerTest */
+var disableWorkerTest = "This test uses SpecialPowers";
+
+var testGenerator = testSteps();
+
+function* testSteps() {
+ const fileData = "abcdefghijklmnopqrstuvwxyz";
+ const fileType = "text/plain";
+
+ const databaseName = "window" in this ? window.location.pathname : "Test";
+ const objectStoreName = "foo";
+ const objectStoreKey = "10";
+
+ info("Creating temp file");
+
+ SpecialPowers.createFiles(
+ [{ data: fileData, options: { type: fileType } }],
+ function (files) {
+ testGenerator.next(files[0]);
+ }
+ );
+
+ let file = yield undefined;
+
+ ok(file instanceof File, "Got a File object");
+ is(file.size, fileData.length, "Correct size");
+ is(file.type, fileType, "Correct type");
+
+ let fileReader = new FileReader();
+ fileReader.onload = grabEventAndContinueHandler;
+ fileReader.readAsText(file);
+
+ let event = yield undefined;
+
+ is(fileReader.result, fileData, "Correct data");
+
+ let request = indexedDB.open(databaseName, 1);
+ request.onerror = errorHandler;
+ request.onupgradeneeded = grabEventAndContinueHandler;
+ request.onsuccess = grabEventAndContinueHandler;
+
+ event = yield undefined;
+
+ let db = event.target.result;
+ let objectStore = db.createObjectStore(objectStoreName);
+ objectStore.put(file, objectStoreKey);
+
+ event = yield undefined;
+
+ db = event.target.result;
+
+ file = null;
+
+ objectStore = db.transaction(objectStoreName).objectStore(objectStoreName);
+ objectStore.get(objectStoreKey).onsuccess = grabEventAndContinueHandler;
+
+ event = yield undefined;
+
+ file = event.target.result;
+
+ ok(file instanceof File, "Got a File object");
+ is(file.size, fileData.length, "Correct size");
+ is(file.type, fileType, "Correct type");
+
+ fileReader = new FileReader();
+ fileReader.onload = grabEventAndContinueHandler;
+ fileReader.readAsText(file);
+
+ event = yield undefined;
+
+ is(fileReader.result, fileData, "Correct data");
+
+ finishTest();
+}