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 objectStoreInfo = [ michael@0: { name: "foo", options: { keyPath: "id" }, location: 1 }, michael@0: { name: "bar", options: { keyPath: "id" }, location: 0 }, michael@0: ]; michael@0: const indexInfo = [ michael@0: { name: "foo", keyPath: "value", location: 1 }, michael@0: { name: "bar", keyPath: "value", location: 0 }, michael@0: ]; michael@0: michael@0: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onupgradeneeded = grabEventAndContinueHandler; michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: let event = yield undefined; michael@0: let db = event.target.result; michael@0: michael@0: for (let i = 0; i < objectStoreInfo.length; i++) { michael@0: let info = objectStoreInfo[i]; michael@0: let objectStore = info.hasOwnProperty("options") ? michael@0: db.createObjectStore(info.name, info.options) : michael@0: db.createObjectStore(info.name); michael@0: michael@0: // Test index creation, and that it ends up in indexNames. michael@0: let objectStoreName = info.name; michael@0: for (let j = 0; j < indexInfo.length; j++) { michael@0: let info = indexInfo[j]; michael@0: let count = objectStore.indexNames.length; michael@0: let index = info.hasOwnProperty("options") ? michael@0: objectStore.createIndex(info.name, info.keyPath, michael@0: info.options) : michael@0: objectStore.createIndex(info.name, info.keyPath); michael@0: } michael@0: } michael@0: michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: request.onupgradeneeded = unexpectedSuccessHandler; michael@0: michael@0: event = yield undefined; michael@0: michael@0: let objectStoreNames = [] michael@0: for (let i = 0; i < objectStoreInfo.length; i++) { michael@0: let info = objectStoreInfo[i]; michael@0: objectStoreNames.push(info.name); michael@0: michael@0: is(db.objectStoreNames[info.location], info.name, michael@0: "Got objectStore name in the right location"); michael@0: michael@0: let trans = db.transaction(info.name); michael@0: let objectStore = trans.objectStore(info.name); michael@0: for (let j = 0; j < indexInfo.length; j++) { michael@0: let info = indexInfo[j]; michael@0: is(objectStore.indexNames[info.location], info.name, michael@0: "Got index name in the right location"); michael@0: } michael@0: } michael@0: michael@0: let trans = db.transaction(objectStoreNames); michael@0: for (let i = 0; i < objectStoreInfo.length; i++) { michael@0: let info = objectStoreInfo[i]; michael@0: michael@0: is(trans.objectStoreNames[info.location], info.name, michael@0: "Got objectStore name in the right location"); michael@0: } michael@0: michael@0: db.close(); michael@0: michael@0: let request = indexedDB.open(name, 1); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: request.onupgradeneeded = unexpectedSuccessHandler; michael@0: let event = yield undefined; michael@0: michael@0: let db = event.target.result; michael@0: michael@0: let objectStoreNames = [] michael@0: for (let i = 0; i < objectStoreInfo.length; i++) { michael@0: let info = objectStoreInfo[i]; michael@0: objectStoreNames.push(info.name); michael@0: michael@0: is(db.objectStoreNames[info.location], info.name, michael@0: "Got objectStore name in the right location"); michael@0: michael@0: let trans = db.transaction(info.name); michael@0: let objectStore = trans.objectStore(info.name); michael@0: for (let j = 0; j < indexInfo.length; j++) { michael@0: let info = indexInfo[j]; michael@0: is(objectStore.indexNames[info.location], info.name, michael@0: "Got index name in the right location"); michael@0: } michael@0: } michael@0: michael@0: let trans = db.transaction(objectStoreNames); michael@0: for (let i = 0; i < objectStoreInfo.length; i++) { michael@0: let info = objectStoreInfo[i]; michael@0: michael@0: is(trans.objectStoreNames[info.location], info.name, michael@0: "Got objectStore name in the right location"); michael@0: } michael@0: michael@0: db.close(); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }