diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/IndexedDB/idbobjectstore_getKey.any.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/idbobjectstore_getKey.any.js')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/idbobjectstore_getKey.any.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbobjectstore_getKey.any.js b/testing/web-platform/tests/IndexedDB/idbobjectstore_getKey.any.js new file mode 100644 index 0000000000..f0dc13d45c --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbobjectstore_getKey.any.js @@ -0,0 +1,89 @@ +// META: title=IndexedDB: Test IDBObjectStore.getKey() +// META: script=resources/support.js + +'use strict'; + +function getkey_test(func, name) { + indexeddb_test( + (t, db, tx) => { + const basic = db.createObjectStore('basic'); + const key_path_store = db.createObjectStore('key path', + { keyPath: 'id' }); + const key_generator_store = db.createObjectStore('key generator', + { autoIncrement: true }); + const key_generator_and_path_store = db.createObjectStore( + 'key generator and key path', + { autoIncrement: true, key_path: 'id' }); + + for (let i = 1; i <= 10; ++i) { + basic.put(`value: ${i}`, i); + key_path_store.put({ id: i }); + key_generator_store.put(`value: ${i}`); + key_generator_and_path_store.put({}); + } + }, + func, + name + ); +} + +getkey_test((t, db) => { + const tx = db.transaction('basic', 'readonly', {durability: 'relaxed'}); + const store = tx.objectStore('basic'); + assert_throws_js(TypeError, () => store.getKey()); + assert_throws_dom('DataError', () => store.getKey(null)); + assert_throws_dom('DataError', () => store.getKey({})); + t.done(); +}, 'IDBObjectStore.getKey() - invalid parameters'); + +[ + 'basic', + 'key path', + 'key generator', + 'key generator and key path' +].forEach(store_name => { + getkey_test((t, db) => { + const tx = db.transaction(store_name); + const store = tx.objectStore(store_name); + const request = store.getKey(5); + request.onerror = t.unreached_func('request failed'); + request.onsuccess = t.step_func(() => + assert_equals(request.result, 5)); + tx.onabort = t.unreached_func('transaction aborted'); + tx.oncomplete = t.step_func(() => t.done()); + }, `IDBObjectStore.getKey() - ${store_name} - key`); + + getkey_test((t, db) => { + const tx = db.transaction(store_name); + const store = tx.objectStore(store_name); + const request = store.getKey(IDBKeyRange.lowerBound(4.5)); + request.onerror = t.unreached_func('request failed'); + request.onsuccess = t.step_func(() => + assert_equals(request.result, 5)); + tx.onabort = t.unreached_func('transaction aborted'); + tx.oncomplete = t.step_func(() => t.done()); + }, `IDBObjectStore.getKey() - ${store_name} - range`); + + getkey_test((t, db) => { + const tx = db.transaction(store_name); + const store = tx.objectStore(store_name); + const request = store.getKey(11); + request.onerror = t.unreached_func('request failed'); + request.onsuccess = t.step_func(() => + assert_equals(request.result, undefined)); + tx.onabort = t.unreached_func('transaction aborted'); + tx.oncomplete = t.step_func(() => t.done()); + }, `IDBObjectStore.getKey() - ${store_name} - key - no match`); + + getkey_test((t, db) => { + const tx = db.transaction(store_name); + const store = tx.objectStore(store_name); + const request = store.getKey(IDBKeyRange.lowerBound(11)); + request.onerror = t.unreached_func('request failed'); + request.onsuccess = t.step_func(() => + assert_equals(request.result, undefined) + ); + tx.onabort = t.unreached_func('transaction aborted'); + tx.oncomplete = t.step_func(() => t.done()); + }, `IDBObjectStore.getKey() - ${store_name} - range - no match`); +}); |