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 indexName = "My Test Index"; 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("test store", { keyPath: "foo" }); michael@0: is(db.objectStoreNames.length, 1, "Correct objectStoreNames list"); michael@0: is(db.objectStoreNames.item(0), objectStore.name, "Correct name"); michael@0: michael@0: is(objectStore.indexNames.length, 0, "Correct indexNames list"); michael@0: michael@0: let index = objectStore.createIndex(indexName, "foo"); michael@0: michael@0: is(objectStore.indexNames.length, 1, "Correct indexNames list"); michael@0: is(objectStore.indexNames.item(0), indexName, "Correct name"); michael@0: is(objectStore.index(indexName), index, "Correct instance"); michael@0: michael@0: objectStore.deleteIndex(indexName); michael@0: michael@0: is(objectStore.indexNames.length, 0, "Correct indexNames list"); michael@0: try { michael@0: objectStore.index(indexName); 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: let index2 = objectStore.createIndex(indexName, "foo"); michael@0: isnot(index, index2, "New instance should be created"); michael@0: michael@0: is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list"); michael@0: is(objectStore.indexNames.item(0), indexName, "Correct recreacted name"); michael@0: is(objectStore.index(indexName), index2, "Correct instance"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }