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 objectStoreName = "Objects"; 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 = event.target.result; michael@0: is(db.objectStoreNames.length, 0, "Correct objectStoreNames list"); michael@0: michael@0: let objectStore = db.createObjectStore(objectStoreName, michael@0: { keyPath: "foo" }); michael@0: michael@0: let addedCount = 0; michael@0: michael@0: for (let i = 0; i < 100; i++) { michael@0: request = objectStore.add({foo: i}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: if (++addedCount == 100) { michael@0: executeSoon(function() { testGenerator.next(); }); michael@0: } michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(db.objectStoreNames.length, 1, "Correct objectStoreNames list"); michael@0: is(db.objectStoreNames.item(0), objectStoreName, "Correct name"); michael@0: michael@0: db.close(); michael@0: michael@0: let request = indexedDB.open(name, 2); 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: let trans = event.target.transaction; michael@0: michael@0: let oldObjectStore = trans.objectStore(objectStoreName); michael@0: isnot(oldObjectStore, null, "Correct object store prior to deleting"); michael@0: db.deleteObjectStore(objectStoreName); michael@0: is(db.objectStoreNames.length, 0, "Correct objectStores list"); michael@0: try { michael@0: trans.objectStore(objectStoreName); michael@0: ok(false, "should have thrown"); michael@0: } michael@0: catch(ex) { michael@0: ok(ex instanceof DOMException, "Got a DOMException"); michael@0: is(ex.name, "NotFoundError", "expect a NotFoundError"); michael@0: is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR"); michael@0: } michael@0: michael@0: objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" }); michael@0: is(db.objectStoreNames.length, 1, "Correct objectStoreNames list"); michael@0: is(db.objectStoreNames.item(0), objectStoreName, "Correct name"); michael@0: is(trans.objectStore(objectStoreName), objectStore, "Correct new objectStore"); michael@0: isnot(oldObjectStore, objectStore, "Old objectStore is not new objectStore"); michael@0: michael@0: request = objectStore.openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: is(event.target.result, undefined, "ObjectStore shouldn't have any items"); michael@0: testGenerator.send(event); michael@0: } michael@0: event = yield undefined; michael@0: michael@0: db.deleteObjectStore(objectStore.name); michael@0: is(db.objectStoreNames.length, 0, "Correct objectStores list"); michael@0: michael@0: continueToNextStep(); michael@0: yield undefined; michael@0: michael@0: db.close(); michael@0: michael@0: let request = indexedDB.open(name, 3); 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: objectStore = db.createObjectStore(objectStoreName, { keyPath: "foo" }); michael@0: michael@0: request = objectStore.add({foo:"bar"}); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: michael@0: db.deleteObjectStore(objectStoreName); michael@0: michael@0: event = yield undefined; michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }