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 = { key: 5, index: 10 }; 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: michael@0: ok(db instanceof IDBDatabase, "Got a real database"); michael@0: michael@0: db.onerror = errorHandler; michael@0: michael@0: let objectStore = db.createObjectStore("foo", { keyPath: "key", michael@0: autoIncrement: true }); michael@0: let index = objectStore.createIndex("foo", "index"); michael@0: michael@0: event.target.onsuccess = continueToNextStep; michael@0: yield undefined; michael@0: michael@0: objectStore = db.transaction("foo", "readwrite") michael@0: .objectStore("foo"); michael@0: request = objectStore.add(data); michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: let key; michael@0: executeSoon(function() { michael@0: key = request.result; michael@0: continueToNextStep(); michael@0: }); michael@0: yield undefined; michael@0: michael@0: is(key, data.key, "Got the right key"); michael@0: michael@0: objectStore = db.transaction("foo").objectStore("foo"); michael@0: objectStore.get(data.key).onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: let obj; michael@0: executeSoon(function() { michael@0: obj = event.target.result; michael@0: continueToNextStep(); michael@0: }); michael@0: yield undefined; michael@0: michael@0: is(obj.key, data.key, "Got the right key"); michael@0: is(obj.index, data.index, "Got the right property value"); michael@0: michael@0: objectStore = db.transaction("foo", "readwrite") michael@0: .objectStore("foo"); michael@0: request = objectStore.delete(data.key); michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: key = undefined; michael@0: executeSoon(function() { michael@0: key = request.result; michael@0: continueToNextStep(); michael@0: }, 0); michael@0: yield undefined; michael@0: michael@0: ok(key === undefined, "Got the right value"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }