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: "1", options: { keyPath: null } }, michael@0: { name: "2", options: { keyPath: null, autoIncrement: true } }, michael@0: { name: "3", options: { keyPath: null, autoIncrement: false } }, michael@0: { name: "4", options: { keyPath: null } }, michael@0: { name: "5", options: { keyPath: "foo" } }, michael@0: { name: "6" }, michael@0: { name: "7", options: null }, michael@0: { name: "8", options: { autoIncrement: true } }, michael@0: { name: "9", options: { autoIncrement: false } }, michael@0: { name: "10", options: { keyPath: "foo", autoIncrement: false } }, michael@0: { name: "11", options: { keyPath: "foo", autoIncrement: true } }, michael@0: { name: "" }, michael@0: { name: null }, michael@0: { name: undefined } 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: michael@0: let db = event.target.result; michael@0: michael@0: let count = db.objectStoreNames.length; michael@0: is(count, 0, "correct objectStoreNames length"); michael@0: michael@0: try { michael@0: db.createObjectStore("foo", "bar"); michael@0: ok(false, "createObjectStore with bad options should throw"); michael@0: } michael@0: catch(e) { michael@0: ok(true, "createObjectStore with bad options"); michael@0: } michael@0: michael@0: ok(db.createObjectStore("foo", { foo: "" }), michael@0: "createObjectStore with unknown options should not throw"); michael@0: db.deleteObjectStore("foo"); michael@0: michael@0: for (let index in objectStoreInfo) { michael@0: index = parseInt(index); michael@0: const info = objectStoreInfo[index]; michael@0: 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: is(db.objectStoreNames.length, index + 1, michael@0: "updated objectStoreNames list"); 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: let found = false; michael@0: for (let i = 0; i <= index; i++) { michael@0: if (db.objectStoreNames.item(i) == name) { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: is(found, true, "objectStoreNames contains name"); michael@0: michael@0: is(objectStore.name, name, "Bad name"); michael@0: is(objectStore.keyPath, info.options && info.options.keyPath ? michael@0: info.options.keyPath : null, michael@0: "Bad keyPath"); michael@0: if(objectStore.indexNames.length, 0, "Bad indexNames"); michael@0: michael@0: ok(event.target.transaction, "event has a transaction"); michael@0: ok(event.target.transaction.db === db, "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, index + 1, michael@0: "transaction has correct objectStoreNames list"); michael@0: found = false; michael@0: for (let j = 0; j < event.target.transaction.objectStoreNames.length; michael@0: j++) { michael@0: if (event.target.transaction.objectStoreNames.item(j) == name) { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: is(found, true, "transaction has correct objectStoreNames list"); michael@0: } michael@0: michael@0: // Can't handle autoincrement and empty keypath michael@0: let ex; michael@0: try { michael@0: db.createObjectStore("storefail", { keyPath: "", autoIncrement: true }); michael@0: } michael@0: catch(e) { michael@0: ex = e; michael@0: } michael@0: ok(ex, "createObjectStore with empty keyPath and autoIncrement 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: // Can't handle autoincrement and array keypath michael@0: let ex; michael@0: try { michael@0: db.createObjectStore("storefail", { keyPath: ["a"], autoIncrement: true }); michael@0: } michael@0: catch(e) { michael@0: ex = e; michael@0: } michael@0: ok(ex, "createObjectStore with array keyPath and autoIncrement 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: 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: }