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 data = { id: new Date().getTime(), michael@0: num: parseInt(Math.random() * 1000) }; michael@0: michael@0: let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: db.onerror = errorHandler; michael@0: michael@0: event.target.onsuccess = continueToNextStep; michael@0: michael@0: // Make object store, add data. michael@0: let objectStore = db.createObjectStore("foo", { keyPath: "id" }); michael@0: objectStore.add(data); michael@0: yield undefined; michael@0: db.close(); michael@0: michael@0: let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 2); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db2 = event.target.result; michael@0: db2.onerror = errorHandler; michael@0: michael@0: event.target.onsuccess = continueToNextStep; michael@0: michael@0: // Create index. michael@0: event.target.transaction.objectStore("foo").createIndex("foo", "num"); michael@0: yield undefined; michael@0: michael@0: // Make sure our object made it into the index. michael@0: let seenCount = 0; michael@0: michael@0: michael@0: db2.transaction("foo").objectStore("foo").index("foo") michael@0: .openKeyCursor().onsuccess = function(event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, data.num, "Good key"); michael@0: is(cursor.primaryKey, data.id, "Good value"); michael@0: seenCount++; michael@0: cursor.continue(); michael@0: } michael@0: else { michael@0: continueToNextStep(); michael@0: } michael@0: }; michael@0: yield undefined; michael@0: michael@0: is(seenCount, 1, "Saw our entry"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }