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 entryCount = 1000; michael@0: michael@0: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = request.result; michael@0: michael@0: event.target.onsuccess = continueToNextStep; michael@0: michael@0: let objectStore = db.createObjectStore("foo", { autoIncrement: true }); michael@0: michael@0: let firstKey; michael@0: for (let i = 0; i < entryCount; i++) { michael@0: request = objectStore.add({}); michael@0: request.onerror = errorHandler; michael@0: if (!i) { michael@0: request.onsuccess = function(event) { michael@0: firstKey = event.target.result; michael@0: }; michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: isnot(firstKey, undefined, "got first key"); michael@0: michael@0: let seenEntryCount = 0; michael@0: michael@0: request = db.transaction("foo").objectStore("foo").openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: seenEntryCount++; 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(seenEntryCount, entryCount, "Correct entry count"); michael@0: michael@0: try { michael@0: db.transaction("foo").objectStore("foo").clear(); michael@0: ok(false, "clear should throw on READ_ONLY transactions"); michael@0: } michael@0: catch (e) { michael@0: ok(true, "clear should throw on READ_ONLY transactions"); michael@0: } michael@0: michael@0: request = db.transaction("foo", "readwrite").objectStore("foo").clear(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: ok(event.target.result === undefined, "Correct event.target.result"); michael@0: ok(request.result === undefined, "Correct request.result"); michael@0: ok(request === event.target, "Correct event.target"); michael@0: michael@0: request = db.transaction("foo").objectStore("foo").openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: let cursor = request.result; michael@0: if (cursor) { michael@0: ok(false, "Shouldn't have any entries"); michael@0: } michael@0: continueToNextStep(); michael@0: } michael@0: yield undefined; michael@0: michael@0: request = db.transaction("foo", "readwrite").objectStore("foo").add({}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: isnot(event.target.result, firstKey, "Got a different key"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }