diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js')
-rw-r--r-- | dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js b/dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js new file mode 100644 index 000000000..1ea0bc883 --- /dev/null +++ b/dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js @@ -0,0 +1,99 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +var testGenerator = testSteps(); + +function testSteps() +{ + const name = this.window ? window.location.pathname : "Splendid Test"; + const START_DATA = "hi"; + const END_DATA = "bye"; + const objectStoreInfo = [ + { name: "1", options: { keyPath: null }, key: 1, + entry: { data: START_DATA } }, + { name: "2", options: { keyPath: "foo" }, + entry: { foo: 1, data: START_DATA } }, + { name: "3", options: { keyPath: null, autoIncrement: true }, + entry: { data: START_DATA } }, + { name: "4", options: { keyPath: "foo", autoIncrement: true }, + entry: { data: START_DATA } }, + ]; + + for (let i = 0; i < objectStoreInfo.length; i++) { + // Create our object stores. + let info = objectStoreInfo[i]; + + ok(true, "1"); + request = indexedDB.open(name, i + 1); + request.onerror = errorHandler; + request.onupgradeneeded = grabEventAndContinueHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + + let db = event.target.result; + + ok(true, "2"); + let objectStore = info.hasOwnProperty("options") ? + db.createObjectStore(info.name, info.options) : + db.createObjectStore(info.name); + + // Create the indexes on 'data' on the object store. + let index = objectStore.createIndex("data_index", "data", + { unique: false }); + let uniqueIndex = objectStore.createIndex("unique_data_index", "data", + { unique: true }); + // Populate the object store with one entry of data. + request = info.hasOwnProperty("key") ? + objectStore.add(info.entry, info.key) : + objectStore.add(info.entry); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + ok(true, "3"); + + // Use a cursor to update 'data' to END_DATA. + request = objectStore.openCursor(); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + ok(true, "4"); + + let cursor = request.result; + let obj = cursor.value; + obj.data = END_DATA; + request = cursor.update(obj); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + ok(true, "5"); + + // Check both indexes to make sure that they were updated. + request = index.get(END_DATA); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + ok(true, "6"); + ok(obj.data, event.target.result.data, + "Non-unique index was properly updated."); + + request = uniqueIndex.get(END_DATA); + request.onerror = errorHandler; + request.onsuccess = grabEventAndContinueHandler; + event = yield undefined; + + ok(true, "7"); + ok(obj.data, event.target.result.data, + "Unique index was properly updated."); + + // Wait for success + yield undefined; + + db.close(); + } + + finishTest(); + yield undefined; +} + |