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 /dom/indexedDB/test/unit/test_advance.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 'dom/indexedDB/test/unit/test_advance.js')
-rw-r--r-- | dom/indexedDB/test/unit/test_advance.js | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_advance.js b/dom/indexedDB/test/unit/test_advance.js new file mode 100644 index 0000000000..eb18c68af4 --- /dev/null +++ b/dom/indexedDB/test/unit/test_advance.js @@ -0,0 +1,181 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/* exported testGenerator */ +var testGenerator = testSteps(); + +function* testSteps() { + const dataCount = 30; + + let request = indexedDB.open( + this.window ? window.location.pathname : "Splendid Test", + 1 + ); + request.onerror = errorHandler; + request.onupgradeneeded = grabEventAndContinueHandler; + let event = yield undefined; + + let db = event.target.result; + db.onerror = errorHandler; + + event.target.onsuccess = continueToNextStep; + + let objectStore = db.createObjectStore("", { keyPath: "key" }); + objectStore.createIndex("", "index"); + + for (let i = 0; i < dataCount; i++) { + objectStore.add({ key: i, index: i }); + } + yield undefined; + + function getObjectStore() { + return db.transaction("").objectStore(""); + } + + function getIndex() { + return db.transaction("").objectStore("").index(""); + } + + let count = 0; + + getObjectStore().openCursor().onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + count++; + cursor.continue(); + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, dataCount, "Saw all data"); + + count = 0; + + getObjectStore().openCursor().onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + is(cursor.primaryKey, count, "Got correct object"); + if (count) { + count++; + cursor.continue(); + } else { + count = 10; + cursor.advance(10); + } + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, dataCount, "Saw all data"); + + count = 0; + + getIndex().openCursor().onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + is(cursor.primaryKey, count, "Got correct object"); + if (count) { + count++; + cursor.continue(); + } else { + count = 10; + cursor.advance(10); + } + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, dataCount, "Saw all data"); + + count = 0; + + getIndex().openKeyCursor().onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + is(cursor.primaryKey, count, "Got correct object"); + if (count) { + count++; + cursor.continue(); + } else { + count = 10; + cursor.advance(10); + } + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, dataCount, "Saw all data"); + + count = 0; + + getObjectStore().openCursor().onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + is(cursor.primaryKey, count, "Got correct object"); + if (count == 0) { + cursor.advance(dataCount + 1); + } else { + ok(false, "Should never get here!"); + cursor.continue(); + } + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, 0, "Saw all data"); + + count = dataCount - 1; + + getObjectStore().openCursor(null, "prev").onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + is(cursor.primaryKey, count, "Got correct object"); + count--; + if (count == dataCount - 2) { + cursor.advance(10); + count -= 9; + } else { + cursor.continue(); + } + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, -1, "Saw all data"); + + count = dataCount - 1; + + getObjectStore().openCursor(null, "prev").onsuccess = function (event) { + let cursor = event.target.result; + if (cursor) { + is(cursor.primaryKey, count, "Got correct object"); + if (count == dataCount - 1) { + cursor.advance(dataCount + 1); + } else { + ok(false, "Should never get here!"); + cursor.continue(); + } + } else { + continueToNextStep(); + } + }; + yield undefined; + + is(count, dataCount - 1, "Saw all data"); + + finishTest(); +} |