summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbindex_keyPath.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/idbindex_keyPath.any.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.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/idbindex_keyPath.any.js')
-rw-r--r--testing/web-platform/tests/IndexedDB/idbindex_keyPath.any.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbindex_keyPath.any.js b/testing/web-platform/tests/IndexedDB/idbindex_keyPath.any.js
new file mode 100644
index 0000000000..40721462a3
--- /dev/null
+++ b/testing/web-platform/tests/IndexedDB/idbindex_keyPath.any.js
@@ -0,0 +1,74 @@
+// META: title=IndexedDB: IDBIndex keyPath attribute
+// META: script=resources/support.js
+
+indexeddb_test(
+ (t, db) => {
+ const store = db.createObjectStore('store', {keyPath: ['a', 'b']});
+ store.createIndex('index', ['a', 'b']);
+ },
+ (t, db) => {
+ const tx = db.transaction('store', 'readonly', {durability: 'relaxed'});
+ const store = tx.objectStore('store');
+ const index = store.index('index');
+ assert_equals(typeof index.keyPath, 'object', 'keyPath is an object');
+ assert_true(Array.isArray(index.keyPath), 'keyPath is an array');
+
+ assert_equals(
+ index.keyPath, index.keyPath,
+ 'Same object instance is returned each time keyPath is inspected');
+
+ const tx2 = db.transaction('store', 'readonly', {durability: 'relaxed'});
+ const store2 = tx2.objectStore('store');
+ const index2 = store2.index('index');
+
+ assert_not_equals(
+ index.keyPath, index2.keyPath,
+ 'Different instances are returned from different index instances.');
+
+ t.done();
+ },
+ `IDBIndex's keyPath attribute returns the same object.`);
+
+ indexeddb_test(
+ (t, db) => {
+ const store = db.createObjectStore('store', {autoIncrement: true});
+ store.createIndex('index', ['a']);
+
+ store.add({a: 1, b: 2, c: 3})
+ },
+ (t, db) => {
+ const tx = db.transaction('store', 'readonly', {durability: 'relaxed'});
+ const store = tx.objectStore('store');
+ const index = store.index('index');
+ const cursorReq = index.openCursor();
+
+ cursorReq.onsuccess = t.step_func_done((e) => {
+ const expectedKeyValue = [1];
+ const actualKeyValue = e.target.result.key;
+
+ assert_array_equals(actualKeyValue, expectedKeyValue, "An array keypath should yield an array key");
+ });
+ },
+ `IDBIndex's keyPath array with a single value`);
+
+ indexeddb_test(
+ (t, db) => {
+ const store = db.createObjectStore('store', {autoIncrement: true});
+ store.createIndex('index', ['a', 'b']);
+
+ store.add({a: 1, b: 2, c: 3})
+ },
+ (t, db) => {
+ const tx = db.transaction('store', 'readonly', {durability: 'relaxed'});
+ const store = tx.objectStore('store');
+ const index = store.index('index');
+ const cursorReq = index.openCursor();
+
+ cursorReq.onsuccess = t.step_func_done((e) => {
+ const expectedKeyValue = [1, 2];
+ const actualKeyValue = e.target.result.key;
+
+ assert_array_equals(actualKeyValue, expectedKeyValue, "An array keypath should yield an array key");
+ });
+ },
+ `IDBIndex's keyPath array with multiple values`);