diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
commit | 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch) | |
tree | a4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /testing/web-platform/tests/IndexedDB/idbindex_getKey.any.js | |
parent | Adding debian version 124.0.1-1. (diff) | |
download | firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/idbindex_getKey.any.js')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/idbindex_getKey.any.js | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbindex_getKey.any.js b/testing/web-platform/tests/IndexedDB/idbindex_getKey.any.js new file mode 100644 index 0000000000..677a70e7cb --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbindex_getKey.any.js @@ -0,0 +1,191 @@ +// META: global=window,worker +// META: title=IDBIndex.getKey() +// META: script=resources/support.js +// @author Microsoft <https://www.microsoft.com> +// @author Intel <http://www.intel.com> + +'use_strict'; + +async_test(t => { + let db; + const record = { key: 1, indexedProperty: "data" }; + + const open_rq = createdb(t); + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + const objStore = db.createObjectStore("test", { keyPath: "key" }); + objStore.createIndex("index", "indexedProperty"); + + objStore.add(record); + }; + + open_rq.onsuccess = function(e) { + let rq = db.transaction("test", "readonly", { durability: 'relaxed' }) + .objectStore("test"); + + rq = rq.index("index"); + + rq = rq.getKey("data"); + + rq.onsuccess = t.step_func(function(e) { + assert_equals(e.target.result, record.key); + t.done(); + }); + }; +}, 'getKey() returns the record\'s primary key'); + +async_test(t => { + let db; + const records = [ + { key: 1, indexedProperty: "data" }, + { key: 2, indexedProperty: "data" }, + { key: 3, indexedProperty: "data" } + ]; + + const open_rq = createdb(t); + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + var objStore = db.createObjectStore("test", { keyPath: "key" }); + objStore.createIndex("index", "indexedProperty"); + + for (let i = 0; i < records.length; i++) + objStore.add(records[i]); + }; + + open_rq.onsuccess = function(e) { + const rq = db.transaction("test", "readonly", { durability: 'relaxed' }) + .objectStore("test") + .index("index") + .getKey("data"); + + rq.onsuccess = t.step_func(function(e) { + assert_equals(e.target.result, records[0].key); + t.done(); + }); + }; +}, 'getKey() returns the record\'s primary key where the index contains duplicate values'); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + const rq = db.createObjectStore("test", { keyPath: "key" }) + .createIndex("index", "indexedProperty") + .getKey(1); + + rq.onsuccess = t.step_func(function(e) { + assert_equals(e.target.result, undefined); + t.done(); + }); + }; +}, 'getKey() attempt to retrieve the primary key of a record that doesn\'t exist'); + +async_test(t => { + let db; + + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + const store = db.createObjectStore("store", { keyPath: "key" }); + store.createIndex("index", "indexedProperty"); + + for (let i = 0; i < 10; i++) { + store.add({ key: i, indexedProperty: "data" + i }); + } + }; + + open_rq.onsuccess = function(e) { + const rq = db.transaction("store", "readonly", { durability: 'relaxed' }) + .objectStore("store") + .index("index") + .getKey(IDBKeyRange.bound('data4', 'data7')); + + rq.onsuccess = t.step_func(function(e) { + assert_equals(e.target.result, 4); + + step_timeout(function () { t.done(); }, 4) + }); + }; +}, 'getKey() returns the key of the first record within the range'); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + + const index = db.createObjectStore("test", { keyPath: "key" }) + .createIndex("index", "indexedProperty"); + + assert_throws_dom("DataError", function () { + index.getKey(NaN); + }); + t.done(); + }; +}, 'getKey() throws DataError when using invalid key'); + +async_test(t => { + let db; + const open_rq = createdb(t); + + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + const store = db.createObjectStore("store", { keyPath: "key" }); + const index = store.createIndex("index", "indexedProperty"); + + store.add({ key: 1, indexedProperty: "data" }); + store.deleteIndex("index"); + + assert_throws_dom("InvalidStateError", function () { + index.getKey("data"); + }); + t.done(); + }; +}, 'getKey() throws InvalidStateError when the index is deleted'); + +async_test(t => { + let db; + + const open_rq = createdb(t); + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + const store = db.createObjectStore("store", { keyPath: "key" }); + const index = store.createIndex("index", "indexedProperty"); + store.add({ key: 1, indexedProperty: "data" }); + }; + + open_rq.onsuccess = function(e) { + db = e.target.result; + const tx = db.transaction('store', 'readonly', { durability: 'relaxed' }); + const index = tx.objectStore('store').index('index'); + tx.abort(); + + assert_throws_dom("TransactionInactiveError", function () { + index.getKey("data"); + }); + t.done(); + }; +}, 'getKey() throws TransactionInactiveError on aborted transaction'); + +async_test(t => { + let db; + + const open_rq = createdb(t); + open_rq.onupgradeneeded = function(e) { + db = e.target.result; + const store = db.createObjectStore("store", { keyPath: "key" }); + const index = store.createIndex("index", "indexedProperty"); + store.add({ key: 1, indexedProperty: "data" }); + + e.target.transaction.abort(); + + assert_throws_dom("InvalidStateError", function () { + index.getKey("data"); + }); + t.done(); + }; +}, 'getKey() throws InvalidStateError on index deleted by aborted upgrade'); |