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: "a", options: { keyPath: "id", autoIncrement: true } }, michael@0: { name: "b", options: { keyPath: "id", autoIncrement: false } }, michael@0: ]; michael@0: const indexInfo = [ michael@0: { name: "1", keyPath: "unique_value", options: { unique: true } }, michael@0: { name: "2", keyPath: "value", options: { unique: false } }, michael@0: { name: "3", keyPath: "value", options: { unique: false } }, michael@0: { name: "", keyPath: "value", options: { unique: false } }, michael@0: { name: null, keyPath: "value", options: { unique: false } }, michael@0: { name: undefined, keyPath: "value", options: { unique: false } }, 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: try { michael@0: request = objectStore.createIndex("Hola"); michael@0: ok(false, "createIndex with no keyPath should throw"); michael@0: } michael@0: catch(e) { michael@0: ok(true, "createIndex with no keyPath should throw"); michael@0: } michael@0: michael@0: let ex; michael@0: try { michael@0: objectStore.createIndex("Hola", ["foo"], { multiEntry: true }); michael@0: } michael@0: catch(e) { michael@0: ex = e; michael@0: } michael@0: ok(ex, "createIndex with array keyPath and multiEntry should throw"); michael@0: is(ex.name, "InvalidAccessError", "should throw right exception"); michael@0: ok(ex instanceof DOMException, "should throw right exception"); michael@0: is(ex.code, DOMException.INVALID_ACCESS_ERR, "should throw right exception"); michael@0: michael@0: try { michael@0: objectStore.createIndex("foo", "bar", 10); michael@0: ok(false, "createIndex with bad options should throw"); michael@0: } michael@0: catch(e) { michael@0: ok(true, "createIndex with bad options threw"); michael@0: } michael@0: michael@0: ok(objectStore.createIndex("foo", "bar", { foo: "" }), michael@0: "createIndex with unknown options should not throw"); michael@0: objectStore.deleteIndex("foo"); 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: let name = info.name; michael@0: if (name === null) { michael@0: name = "null"; michael@0: } michael@0: else if (name === undefined) { michael@0: name = "undefined"; michael@0: } michael@0: michael@0: is(index.name, name, "correct name"); michael@0: is(index.keyPath, info.keyPath, "correct keyPath"); michael@0: is(index.unique, info.options.unique, "correct uniqueness"); michael@0: michael@0: is(objectStore.indexNames.length, count + 1, michael@0: "indexNames grew in size"); michael@0: let found = false; michael@0: for (let k = 0; k < objectStore.indexNames.length; k++) { michael@0: if (objectStore.indexNames.item(k) == name) { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: ok(found, "Name is on objectStore.indexNames"); michael@0: michael@0: ok(event.target.transaction, "event has a transaction"); michael@0: ok(event.target.transaction.db === db, michael@0: "transaction has the right db"); michael@0: is(event.target.transaction.mode, "versionchange", michael@0: "transaction has the correct mode"); michael@0: is(event.target.transaction.objectStoreNames.length, i + 1, michael@0: "transaction only has one object store"); michael@0: ok(event.target.transaction.objectStoreNames.contains(objectStoreName), michael@0: "transaction has the correct object store"); 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: finishTest(); michael@0: yield undefined; michael@0: }