diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/IndexedDB/idbindex_reverse_cursor.any.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/IndexedDB/idbindex_reverse_cursor.any.js')
-rw-r--r-- | testing/web-platform/tests/IndexedDB/idbindex_reverse_cursor.any.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/testing/web-platform/tests/IndexedDB/idbindex_reverse_cursor.any.js b/testing/web-platform/tests/IndexedDB/idbindex_reverse_cursor.any.js new file mode 100644 index 0000000000..88c367466d --- /dev/null +++ b/testing/web-platform/tests/IndexedDB/idbindex_reverse_cursor.any.js @@ -0,0 +1,60 @@ +// META: title=Reverse Cursor Validity +// META: script=resources/support-promises.js + +async function iterateAndReturnAllCursorResult(testCase, cursor) { + return new Promise((resolve, reject) => { + let results = []; + cursor.onsuccess = testCase.step_func(function(e) { + let cursor = e.target.result; + if (!cursor) { + resolve(results); + return; + } + results.push(cursor.value); + cursor.continue(); + }); + cursor.onerror = reject; + }); +} + +promise_test(async testCase => { + const db = await createDatabase(testCase, db => { + db.createObjectStore('objectStore', {keyPath: 'key'}) + .createIndex('index', 'indexedOn'); + }); + const txn1 = db.transaction(['objectStore'], 'readwrite'); + txn1.objectStore('objectStore').add({'key': 'firstItem', 'indexedOn': 3}); + const txn2 = db.transaction(['objectStore'], 'readwrite'); + txn2.objectStore('objectStore').put({'key': 'firstItem', 'indexedOn': -1}); + const txn3= db.transaction(['objectStore'], 'readwrite'); + txn3.objectStore('objectStore').add({'key': 'secondItem', 'indexedOn': 2}); + + const txn4 = db.transaction(['objectStore'], 'readonly'); + cursor = txn4.objectStore('objectStore').index('index').openCursor(IDBKeyRange.bound(0, 10), "prev"); + let results = await iterateAndReturnAllCursorResult(testCase, cursor); + + assert_equals(results.length, 1); + + await promiseForTransaction(testCase, txn4); + db.close(); +}, 'Reverse cursor sees update from separate transactions.'); + +promise_test(async testCase => { + const db = await createDatabase(testCase, db => { + db.createObjectStore('objectStore', {keyPath: 'key'}) + .createIndex('index', 'indexedOn'); + }); + const txn = db.transaction(['objectStore'], 'readwrite'); + txn.objectStore('objectStore').add({'key': '1', 'indexedOn': 2}); + txn.objectStore('objectStore').put({'key': '1', 'indexedOn': -1}); + txn.objectStore('objectStore').add({'key': '2', 'indexedOn': 1}); + + const txn2 = db.transaction(['objectStore'], 'readonly'); + cursor = txn2.objectStore('objectStore').index('index').openCursor(IDBKeyRange.bound(0, 10), "prev"); + let results = await iterateAndReturnAllCursorResult(testCase, cursor); + + assert_equals(1, results.length); + + await promiseForTransaction(testCase, txn2); + db.close(); +}, 'Reverse cursor sees in-transaction update.'); |