summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js')
-rw-r--r--testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js b/testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js
new file mode 100644
index 0000000000..24923ffcf8
--- /dev/null
+++ b/testing/web-platform/tests/IndexedDB/storage-buckets.https.any.js
@@ -0,0 +1,89 @@
+// META: title=Buckets API: Tests for indexedDB API.
+// META: global=window,worker
+// META: script=resources/support-promises.js
+
+promise_test(async testCase => {
+ const inboxBucket = await navigator.storageBuckets.open('inbox_bucket');
+ const outboxBucket = await navigator.storageBuckets.open('outbox_bucket');
+ testCase.add_cleanup(async () => {
+ await navigator.storageBuckets.delete('inbox_bucket');
+ await navigator.storageBuckets.delete('outbox_bucket');
+ });
+
+ // Set up similar databases in two buckets.
+ const inboxDb = await new Promise((resolve, reject) => {
+ const request = inboxBucket.indexedDB.open('messages');
+ request.onupgradeneeded = (event) => {
+ const inboxStore =
+ event.target.result.createObjectStore('primary', {keyPath: 'id'});
+ event.target.transaction.commit();
+ };
+ request.onsuccess = () => resolve(request.result);
+ request.onerror = () => reject(request.error);
+ });
+
+ const txn = inboxDb.transaction(['primary'], 'readwrite');
+ const inboxStore = txn.objectStore('primary');
+ inboxStore.put({ subject: 'Bonjour', id: '42'});
+ txn.commit();
+ await promiseForTransaction(testCase, txn);
+
+ const outboxDb = await new Promise((resolve, reject) => {
+ const request = outboxBucket.indexedDB.open('messages');
+ request.onupgradeneeded = (event) => {
+ const outboxStore =
+ event.target.result.createObjectStore('primary', {keyPath: 'id'});
+ event.target.transaction.commit();
+ };
+ request.onsuccess = () => resolve(request.result);
+ request.onerror = () => reject(request.error);
+ });
+
+ const txn2 = outboxDb.transaction(['primary'], 'readwrite');
+ const outboxStore = txn2.objectStore('primary');
+ outboxStore.put({ subject: 're: Bonjour', id: '47'});
+ txn2.commit();
+ await promiseForTransaction(testCase, txn2);
+
+ // Make sure it's possible to read from the bucket database.
+ const inboxMessage = await new Promise((resolve, reject) => {
+ const txn3 = inboxDb.transaction(['primary'], 'readonly');
+ const inboxLookup = txn3.objectStore('primary').get('42');
+ inboxLookup.onsuccess = (e) => resolve(inboxLookup.result);
+ inboxLookup.onerror = (e) => reject(inboxLookup.error);
+ });
+ assert_equals(inboxMessage.subject, 'Bonjour');
+
+ // Make sure it's possible to read from the other bucket database.
+ const outboxMessage = await new Promise((resolve, reject) => {
+ const txn4 = outboxDb.transaction(['primary'], 'readonly');
+ const outboxLookup = txn4.objectStore('primary').get('47');
+ outboxLookup.onsuccess = (e) => resolve(outboxLookup.result);
+ outboxLookup.onerror = (e) => reject(outboxLookup.error);
+ });
+ assert_equals(outboxMessage.subject, 're: Bonjour');
+
+ // Make sure they are different databases (looking up the data keyed on `47`
+ // fails in the first database).
+ const nonexistentInboxMessage = await new Promise((resolve, reject) => {
+ const txn5 = inboxDb.transaction(['primary'], 'readonly');
+ const nonexistentInboxLookup = txn5.objectStore('primary').get('47');
+ nonexistentInboxLookup.onsuccess = (e) =>
+ resolve(nonexistentInboxLookup.result);
+ nonexistentInboxLookup.onerror = (e) =>
+ reject(nonexistentInboxLookup.error);
+ });
+ assert_equals(nonexistentInboxMessage, undefined);
+}, 'Basic test that buckets create independent databases.');
+
+promise_test(async testCase => {
+ const inboxBucket = await navigator.storageBuckets.open('inbox');
+ await navigator.storageBuckets.delete('inbox');
+
+ return promise_rejects_dom(
+ testCase, 'UnknownError', new Promise((resolve, reject) => {
+ const request = inboxBucket.indexedDB.open('messages');
+ request.onsuccess = () => resolve(request.result);
+ request.onerror = () => reject(request.error);
+ }));
+}, 'Tests trying to use indexedDB in a deleted bucket.');