michael@0: /** michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: var testGenerator = testSteps(); michael@0: michael@0: function testSteps() michael@0: { michael@0: const name = this.window ? window.location.pathname : "Splendid Test"; michael@0: const START_DATA = "hi"; michael@0: const END_DATA = "bye"; michael@0: const objectStoreInfo = [ michael@0: { name: "1", options: { keyPath: null }, key: 1, michael@0: entry: { data: START_DATA } }, michael@0: { name: "2", options: { keyPath: "foo" }, michael@0: entry: { foo: 1, data: START_DATA } }, michael@0: { name: "3", options: { keyPath: null, autoIncrement: true }, michael@0: entry: { data: START_DATA } }, michael@0: { name: "4", options: { keyPath: "foo", autoIncrement: true }, michael@0: entry: { data: START_DATA } }, michael@0: ]; michael@0: michael@0: for (let i = 0; i < objectStoreInfo.length; i++) { michael@0: // Create our object stores. michael@0: let info = objectStoreInfo[i]; michael@0: michael@0: ok(true, "1"); michael@0: request = indexedDB.open(name, i + 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: michael@0: ok(true, "2"); michael@0: let objectStore = info.hasOwnProperty("options") ? michael@0: db.createObjectStore(info.name, info.options) : michael@0: db.createObjectStore(info.name); michael@0: michael@0: // Create the indexes on 'data' on the object store. michael@0: let index = objectStore.createIndex("data_index", "data", michael@0: { unique: false }); michael@0: let uniqueIndex = objectStore.createIndex("unique_data_index", "data", michael@0: { unique: true }); michael@0: // Populate the object store with one entry of data. michael@0: request = info.hasOwnProperty("key") ? michael@0: objectStore.add(info.entry, info.key) : michael@0: objectStore.add(info.entry); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: ok(true, "3"); michael@0: michael@0: // Use a cursor to update 'data' to END_DATA. michael@0: request = objectStore.openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: ok(true, "4"); michael@0: michael@0: let cursor = request.result; michael@0: let obj = cursor.value; michael@0: obj.data = END_DATA; michael@0: request = cursor.update(obj); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: ok(true, "5"); michael@0: michael@0: // Check both indexes to make sure that they were updated. michael@0: request = index.get(END_DATA); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: ok(true, "6"); michael@0: ok(obj.data, event.target.result.data, michael@0: "Non-unique index was properly updated."); michael@0: michael@0: request = uniqueIndex.get(END_DATA); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: ok(true, "7"); michael@0: ok(obj.data, event.target.result.data, michael@0: "Unique index was properly updated."); michael@0: db.close(); michael@0: } michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: } michael@0: