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: michael@0: const objectStoreName = "People"; michael@0: michael@0: const objectStoreData = [ michael@0: { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, michael@0: { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, michael@0: { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }, michael@0: { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }, michael@0: { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, michael@0: { key: "237-23-7737", value: { name: "Pat", height: 65 } } michael@0: ]; michael@0: michael@0: const indexData = [ michael@0: { name: "name", keyPath: "name", options: { unique: true } }, michael@0: { name: "height", keyPath: "height", options: { } }, michael@0: { name: "weight", keyPath: "weight", options: { unique: false } } michael@0: ]; michael@0: michael@0: const objectStoreDataNameSort = [ michael@0: { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, michael@0: { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, michael@0: { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, michael@0: { key: "237-23-7737", value: { name: "Pat", height: 65 } }, michael@0: { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }, michael@0: { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } } michael@0: ]; michael@0: michael@0: const objectStoreDataWeightSort = [ michael@0: { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, michael@0: { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, michael@0: { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }, michael@0: { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, michael@0: { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } } michael@0: ]; michael@0: michael@0: const objectStoreDataHeightSort = [ michael@0: { key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } }, michael@0: { key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }, michael@0: { key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } }, michael@0: { key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } }, michael@0: { key: "237-23-7737", value: { name: "Pat", height: 65 } }, michael@0: { key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } } 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 = grabEventAndContinueHandler; michael@0: let event = yield undefined; michael@0: let db = event.target.result; michael@0: michael@0: let objectStore = db.createObjectStore(objectStoreName, { keyPath: null }); michael@0: michael@0: // First, add all our data to the object store. michael@0: let addedData = 0; michael@0: for (let i in objectStoreData) { michael@0: request = objectStore.add(objectStoreData[i].value, michael@0: objectStoreData[i].key); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function(event) { michael@0: if (++addedData == objectStoreData.length) { michael@0: testGenerator.send(event); michael@0: } michael@0: } michael@0: } michael@0: event = yield undefined; michael@0: // Now create the indexes. michael@0: for (let i in indexData) { michael@0: objectStore.createIndex(indexData[i].name, indexData[i].keyPath, michael@0: indexData[i].options); michael@0: } michael@0: is(objectStore.indexNames.length, indexData.length, "Good index count"); michael@0: yield undefined; michael@0: objectStore = db.transaction(objectStoreName) michael@0: .objectStore(objectStoreName); michael@0: michael@0: // Check global properties to make sure they are correct. michael@0: is(objectStore.indexNames.length, indexData.length, "Good index count"); michael@0: for (let i in indexData) { michael@0: let found = false; michael@0: for (let j = 0; j < objectStore.indexNames.length; j++) { michael@0: if (objectStore.indexNames.item(j) == indexData[i].name) { michael@0: found = true; michael@0: break; michael@0: } michael@0: } michael@0: is(found, true, "objectStore has our index"); michael@0: let index = objectStore.index(indexData[i].name); michael@0: is(index.name, indexData[i].name, "Correct name"); michael@0: is(index.storeName, objectStore.name, "Correct store name"); michael@0: is(index.keyPath, indexData[i].keyPath, "Correct keyPath"); michael@0: is(index.unique, indexData[i].options.unique ? true : false, michael@0: "Correct unique value"); michael@0: } michael@0: michael@0: request = objectStore.index("name").getKey("Bob"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result, "237-23-7732", "Correct key returned!"); michael@0: michael@0: request = objectStore.index("name").get("Bob"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = grabEventAndContinueHandler; michael@0: event = yield undefined; michael@0: michael@0: is(event.target.result.name, "Bob", "Correct name returned!"); michael@0: is(event.target.result.height, 60, "Correct height returned!"); michael@0: is(event.target.result.weight, 120, "Correct weight returned!"); michael@0: michael@0: ok(true, "Test group 1"); michael@0: michael@0: let keyIndex = 0; michael@0: michael@0: request = objectStore.index("name").openKeyCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: ok(!("value" in cursor), "No value"); michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: ok(!("value" in cursor), "No value"); michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreData.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 2"); michael@0: michael@0: keyIndex = 0; michael@0: michael@0: request = objectStore.index("weight").openKeyCursor(null, "next"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys"); michael@0: michael@0: // Check that the name index enforces its unique constraint. michael@0: objectStore = db.transaction(objectStoreName, "readwrite") michael@0: .objectStore(objectStoreName); michael@0: request = objectStore.add({ name: "Bob", height: 62, weight: 170 }, michael@0: "237-23-7738"); michael@0: request.addEventListener("error", new ExpectError("ConstraintError", true)); michael@0: request.onsuccess = unexpectedSuccessHandler; michael@0: event = yield undefined; michael@0: michael@0: ok(true, "Test group 3"); michael@0: michael@0: keyIndex = objectStoreDataNameSort.length - 1; michael@0: michael@0: request = objectStore.index("name").openKeyCursor(null, "prev"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, -1, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 4"); michael@0: michael@0: keyIndex = 1; michael@0: let keyRange = IDBKeyRange.bound("Bob", "Ron"); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 5, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 5"); michael@0: michael@0: keyIndex = 2; michael@0: let keyRange = IDBKeyRange.bound("Bob", "Ron", true); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 5, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 6"); michael@0: michael@0: keyIndex = 1; michael@0: let keyRange = IDBKeyRange.bound("Bob", "Ron", false, true); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 7"); michael@0: michael@0: keyIndex = 2; michael@0: keyRange = IDBKeyRange.bound("Bob", "Ron", true, true); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 8"); michael@0: michael@0: keyIndex = 1; michael@0: keyRange = IDBKeyRange.lowerBound("Bob"); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 9"); michael@0: michael@0: keyIndex = 2; michael@0: keyRange = IDBKeyRange.lowerBound("Bob", true); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 10"); michael@0: michael@0: keyIndex = 0; michael@0: keyRange = IDBKeyRange.upperBound("Joe"); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 3, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 11"); michael@0: michael@0: keyIndex = 0; michael@0: keyRange = IDBKeyRange.upperBound("Joe", true); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 2, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 12"); michael@0: michael@0: keyIndex = 3; michael@0: keyRange = IDBKeyRange.only("Pat"); michael@0: michael@0: request = objectStore.index("name").openKeyCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 13"); michael@0: michael@0: keyIndex = 0; michael@0: michael@0: request = objectStore.index("name").openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 14"); michael@0: michael@0: keyIndex = objectStoreDataNameSort.length - 1; michael@0: michael@0: request = objectStore.index("name").openCursor(null, "prev"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, -1, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 15"); michael@0: michael@0: keyIndex = 1; michael@0: keyRange = IDBKeyRange.bound("Bob", "Ron"); michael@0: michael@0: request = objectStore.index("name").openCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 5, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 16"); michael@0: michael@0: keyIndex = 2; michael@0: keyRange = IDBKeyRange.bound("Bob", "Ron", true); michael@0: michael@0: request = objectStore.index("name").openCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 5, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 17"); michael@0: michael@0: keyIndex = 1; michael@0: keyRange = IDBKeyRange.bound("Bob", "Ron", false, true); michael@0: michael@0: request = objectStore.index("name").openCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 18"); michael@0: michael@0: keyIndex = 2; michael@0: keyRange = IDBKeyRange.bound("Bob", "Ron", true, true); michael@0: michael@0: request = objectStore.index("name").openCursor(keyRange); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 19"); michael@0: michael@0: keyIndex = 4; michael@0: keyRange = IDBKeyRange.bound("Bob", "Ron"); michael@0: michael@0: request = objectStore.index("name").openCursor(keyRange, "prev"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 0, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 20"); michael@0: michael@0: // Test "nextunique" michael@0: keyIndex = 3; michael@0: keyRange = IDBKeyRange.only(65); michael@0: michael@0: request = objectStore.index("height").openKeyCursor(keyRange, "next"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 5, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 21"); michael@0: michael@0: keyIndex = 3; michael@0: keyRange = IDBKeyRange.only(65); michael@0: michael@0: request = objectStore.index("height").openKeyCursor(keyRange, michael@0: "nextunique"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 21.5"); michael@0: michael@0: keyIndex = 5; michael@0: michael@0: request = objectStore.index("height").openKeyCursor(null, "prev"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, -1, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 22"); michael@0: michael@0: keyIndex = 5; michael@0: michael@0: request = objectStore.index("height").openKeyCursor(null, michael@0: "prevunique"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: cursor.continue(); michael@0: if (keyIndex == 5) { michael@0: keyIndex--; michael@0: } michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, -1, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 23"); michael@0: michael@0: keyIndex = 3; michael@0: keyRange = IDBKeyRange.only(65); michael@0: michael@0: request = objectStore.index("height").openCursor(keyRange, "next"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataHeightSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 5, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 24"); michael@0: michael@0: keyIndex = 3; michael@0: keyRange = IDBKeyRange.only(65); michael@0: michael@0: request = objectStore.index("height").openCursor(keyRange, michael@0: "nextunique"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataHeightSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: keyIndex++; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, 4, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 24.5"); michael@0: michael@0: keyIndex = 5; michael@0: michael@0: request = objectStore.index("height").openCursor(null, "prev"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataHeightSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, -1, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 25"); michael@0: michael@0: keyIndex = 5; michael@0: michael@0: request = objectStore.index("height").openCursor(null, michael@0: "prevunique"); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataHeightSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataHeightSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: cursor.continue(); michael@0: if (keyIndex == 5) { michael@0: keyIndex--; michael@0: } michael@0: keyIndex--; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, -1, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 26"); michael@0: michael@0: keyIndex = 0; michael@0: michael@0: request = objectStore.index("name").openKeyCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: let nextKey = !keyIndex ? "Pat" : undefined; michael@0: michael@0: cursor.continue(nextKey); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: if (!keyIndex) { michael@0: keyIndex = 3; michael@0: } michael@0: else { michael@0: keyIndex++; michael@0: } michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreData.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 27"); michael@0: michael@0: keyIndex = 0; michael@0: michael@0: request = objectStore.index("name").openKeyCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: let nextKey = !keyIndex ? "Flo" : undefined; michael@0: michael@0: cursor.continue(nextKey); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct value"); michael@0: michael@0: keyIndex += keyIndex ? 1 : 2; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreData.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 28"); michael@0: michael@0: keyIndex = 0; michael@0: michael@0: request = objectStore.index("name").openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: let nextKey = !keyIndex ? "Pat" : undefined; michael@0: michael@0: cursor.continue(nextKey); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: if (!keyIndex) { michael@0: keyIndex = 3; michael@0: } michael@0: else { michael@0: keyIndex++; michael@0: } michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); michael@0: michael@0: ok(true, "Test group 29"); michael@0: michael@0: keyIndex = 0; michael@0: michael@0: request = objectStore.index("name").openCursor(); michael@0: request.onerror = errorHandler; michael@0: request.onsuccess = function (event) { michael@0: let cursor = event.target.result; michael@0: if (cursor) { michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: let nextKey = !keyIndex ? "Flo" : undefined; michael@0: michael@0: cursor.continue(nextKey); michael@0: michael@0: is(cursor.key, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct key"); michael@0: is(cursor.primaryKey, objectStoreDataNameSort[keyIndex].key, michael@0: "Correct primary key"); michael@0: is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name, michael@0: "Correct name"); michael@0: is(cursor.value.height, michael@0: objectStoreDataNameSort[keyIndex].value.height, michael@0: "Correct height"); michael@0: if ("weight" in cursor.value) { michael@0: is(cursor.value.weight, michael@0: objectStoreDataNameSort[keyIndex].value.weight, michael@0: "Correct weight"); michael@0: } michael@0: michael@0: keyIndex += keyIndex ? 1 : 2; michael@0: } michael@0: else { michael@0: testGenerator.next(); michael@0: } michael@0: } michael@0: yield undefined; michael@0: michael@0: is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys"); michael@0: michael@0: finishTest(); michael@0: yield undefined; michael@0: }