summaryrefslogtreecommitdiffstats
path: root/dom/indexedDB/test/unit/test_unique_index_update.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/indexedDB/test/unit/test_unique_index_update.js
parentInitial commit. (diff)
downloadfirefox-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_unique_index_update.js')
-rw-r--r--dom/indexedDB/test/unit/test_unique_index_update.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_unique_index_update.js b/dom/indexedDB/test/unit/test_unique_index_update.js
new file mode 100644
index 0000000000..736344ae5e
--- /dev/null
+++ b/dom/indexedDB/test/unit/test_unique_index_update.js
@@ -0,0 +1,71 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/* exported testGenerator */
+var testGenerator = testSteps();
+
+function* testSteps() {
+ let request = indexedDB.open(
+ this.window ? window.location.pathname : "Splendid Test",
+ 1
+ );
+ request.onerror = errorHandler;
+ request.onupgradeneeded = grabEventAndContinueHandler;
+ request.onsuccess = grabEventAndContinueHandler;
+
+ let event = yield undefined;
+
+ let db = event.target.result;
+
+ for (let autoIncrement of [false, true]) {
+ let objectStore = db.createObjectStore(autoIncrement, {
+ keyPath: "id",
+ autoIncrement,
+ });
+ objectStore.createIndex("", "index", { unique: true });
+
+ for (let i = 0; i < 10; i++) {
+ objectStore.add({ id: i, index: i });
+ }
+ }
+
+ event = yield undefined;
+ is(event.type, "success", "expect a success event");
+
+ for (let autoIncrement of [false, true]) {
+ let objectStore = db
+ .transaction(autoIncrement, "readwrite")
+ .objectStore(autoIncrement);
+
+ request = objectStore.put({ id: 5, index: 6 });
+ request.onsuccess = unexpectedSuccessHandler;
+ request.addEventListener("error", new ExpectError("ConstraintError", true));
+ event = yield undefined;
+
+ event.preventDefault();
+
+ let keyRange = IDBKeyRange.only(5);
+
+ objectStore.index("").openCursor(keyRange).onsuccess = function (event) {
+ let cursor = event.target.result;
+ ok(cursor, "Must have a cursor here");
+
+ is(cursor.value.index, 5, "Still have the right index value");
+
+ cursor.value.index = 6;
+
+ request = cursor.update(cursor.value);
+ request.onsuccess = unexpectedSuccessHandler;
+ request.addEventListener(
+ "error",
+ new ExpectError("ConstraintError", true)
+ );
+ };
+
+ yield undefined;
+ }
+
+ finishTest();
+}