diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/IndexedDB/idbobjectstore_createIndex15-autoincrement.htm | |
parent | Initial commit. (diff) | |
download | firefox-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/idbobjectstore_createIndex15-autoincrement.htm')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/idbobjectstore_createIndex15-autoincrement.htm | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbobjectstore_createIndex15-autoincrement.htm b/testing/web-platform/tests/IndexedDB/idbobjectstore_createIndex15-autoincrement.htm new file mode 100644 index 0000000000..679b5d05aa --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbobjectstore_createIndex15-autoincrement.htm @@ -0,0 +1,106 @@ +<!DOCTYPE html> +<meta charset=utf-8> +<title>IDBObjectStore.createIndex() - AutoIncrement in Compound Index</title> +<meta name="timeout" content="long"> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="resources/support.js"></script> +<script> + indexeddb_test( + function(t, db, txn) { + // No auto-increment + var store = db.createObjectStore("Store1", {keyPath: "id"}); + store.createIndex("CompoundKey", ["num", "id"]); + + // Add data + store.put({id: 1, num: 100}); + }, + function(t, db) { + var store = db.transaction("Store1", "readwrite", {durability: 'relaxed'}).objectStore("Store1"); + + store.openCursor().onsuccess = t.step_func(function(e) { + var item = e.target.result.value; + store.index("CompoundKey").get([item.num, item.id]).onsuccess = t.step_func(function(e) { + assert_equals(e.target.result ? e.target.result.num : null, 100, 'Expected 100.'); + t.done(); + }); + }); + }, + "Explicit Primary Key" + ); + + indexeddb_test( + function(t, db, txn) { + // Auto-increment + var store = db.createObjectStore("Store2", {keyPath: "id", autoIncrement: true}); + store.createIndex("CompoundKey", ["num", "id"]); + + // Add data + store.put({num: 100}); + }, + function(t, db) { + var store = db.transaction("Store2", "readwrite", {durability: 'relaxed'}).objectStore("Store2"); + store.openCursor().onsuccess = t.step_func(function(e) { + var item = e.target.result.value; + store.index("CompoundKey").get([item.num, item.id]).onsuccess = t.step_func(function(e) { + assert_equals(e.target.result ? e.target.result.num : null, 100, 'Expected 100.'); + t.done(); + }); + }); + }, + "Auto-Increment Primary Key" + ); + + indexeddb_test( + function(t, db, txn) { + // Auto-increment + var store = db.createObjectStore("Store3", {keyPath: "id", autoIncrement: true}); + store.createIndex("CompoundKey", ["num", "id", "other"]); + + var num = 100; + + // Add data to Store3 - valid keys + // Objects will be stored in Store3 and keys will get added + // to the CompoundKeys index. + store.put({num: num++, other: 0}); + store.put({num: num++, other: [0]}); + + // Add data - missing key + // Objects will be stored in Store3 but keys won't get added to + // the CompoundKeys index because the 'other' keypath doesn't + // resolve to a value. + store.put({num: num++}); + + // Add data to Store3 - invalid keys + // Objects will be stored in Store3 but keys won't get added to + // the CompoundKeys index because the 'other' property values + // aren't valid keys. + store.put({num: num++, other: null}); + store.put({num: num++, other: {}}); + store.put({num: num++, other: [null]}); + store.put({num: num++, other: [{}]}); + }, + function(t, db) { + var store = db.transaction("Store3", "readwrite", {durability: 'relaxed'}).objectStore("Store3"); + const keys = []; + let count; + store.count().onsuccess = t.step_func(e => { count = e.target.result; }); + store.index("CompoundKey").openCursor().onsuccess = t.step_func(function(e) { + const cursor = e.target.result; + if (cursor !== null) { + keys.push(cursor.key); + cursor.continue(); + return; + } + + // Done iteration, check results. + assert_equals(count, 7, 'Expected all 7 records to be stored.'); + assert_equals(keys.length, 2, 'Expected exactly two index entries.'); + assert_array_equals(keys[0], [100, 1, 0]); + assert_object_equals(keys[1], [101, 2, [0]]); + t.done(); + }); + }, + "Auto-Increment Primary Key - invalid key values elsewhere" + ); +</script> |