gecko/dom/indexedDB/test/test_indexes.html

1151 lines
37 KiB
HTML

<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript;version=1.7">
function testSteps()
{
const CONSTRAINT_ERR =
Components.interfaces.nsIIDBDatabaseException.CONSTRAINT_ERR;
const READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
const NEXT = Components.interfaces.nsIIDBCursor.NEXT;
const PREV = Components.interfaces.nsIIDBCursor.PREV;
const NEXT_NO_DUPLICATE =
Components.interfaces.nsIIDBCursor.NEXT_NO_DUPLICATE;
const PREV_NO_DUPLICATE =
Components.interfaces.nsIIDBCursor.PREV_NO_DUPLICATE;
const name = window.location.pathname;
const description = "My Test Database";
const objectStoreName = "People";
const objectStoreData = [
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "Pat", height: 65 } }
];
const indexData = [
{ name: "name", keyPath: "name", unique: true },
{ name: "height", keyPath: "height", unique: false },
{ name: "weight", keyPath: "weight", unique: false }
];
const objectStoreDataNameSort = [
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } },
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } }
];
const objectStoreDataWeightSort = [
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
];
const objectStoreDataHeightSort = [
{ key: "237-23-7733", value: { name: "Ann", height: 52, weight: 110 } },
{ key: "237-23-7735", value: { name: "Sue", height: 58, weight: 130 } },
{ key: "237-23-7732", value: { name: "Bob", height: 60, weight: 120 } },
{ key: "237-23-7736", value: { name: "Joe", height: 65, weight: 150 } },
{ key: "237-23-7737", value: { name: "Pat", height: 65 } },
{ key: "237-23-7734", value: { name: "Ron", height: 73, weight: 180 } }
];
let request = moz_indexedDB.open(name, description);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let db = event.result;
request = db.createObjectStore(objectStoreName, "");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = event.result;
// First, add all our data to the object store.
let addedData = 0;
for (let i in objectStoreData) {
request = objectStore.add(objectStoreData[i].value,
objectStoreData[i].key);
request.onerror = errorHandler;
request.onsuccess = function(event) {
if (++addedData == objectStoreData.length) {
testGenerator.send(event);
}
}
}
event = yield;
// Now create the index.
addedData = 0;
for (let i in indexData) {
request = objectStore.createIndex(indexData[i].name,
indexData[i].keyPath,
indexData[i].unique);
request.onerror = errorHandler;
request.onsuccess = function(event) {
if (++addedData == indexData.length) {
is(objectStore.indexNames.length, addedData, "Good index count");
SimpleTest.executeSoon(function() { testGenerator.next() });
}
}
}
yield;
objectStore = db.objectStore(objectStoreName);
// Check global properties to make sure they are correct.
is(objectStore.indexNames.length, indexData.length, "Good index count");
for (let i in indexData) {
let found = false;
for (let j = 0; j < objectStore.indexNames.length; j++) {
if (objectStore.indexNames.item(j) == indexData[i].name) {
found = true;
break;
}
}
is(found, true, "objectStore has our index");
let index = objectStore.index(indexData[i].name);
is(index.name, indexData[i].name, "Correct name");
is(index.storeName, objectStore.name, "Correct store name");
is(index.keyPath, indexData[i].keyPath, "Correct keyPath");
is(index.unique, indexData[i].unique, "Correct keyPath");
}
request = objectStore.index("name").get("Bob");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result, "237-23-7732", "Correct key returned!");
request = objectStore.index("name").getObject("Bob");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
is(event.result.name, "Bob", "Correct name returned!");
is(event.result.height, 60, "Correct height returned!");
is(event.result.weight, 120, "Correct weight returned!");
let keyIndex = 0;
request = objectStore.index("name").openCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreData.length, "Saw all the expected keys");
keyIndex = 0;
request = objectStore.index("weight").openCursor(null, NEXT);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
"Correct key");
is(cursor.value, objectStoreDataWeightSort[keyIndex].key,
"Correct value");
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
"Correct key");
is(cursor.value, objectStoreDataWeightSort[keyIndex].key,
"Correct value");
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreData.length - 1, "Saw all the expected keys");
// Check that the name index enforces its unique constraint.
objectStore = db.objectStore(objectStoreName, READ_WRITE);
request = objectStore.add({ name: "Bob", height: 62, weight: 170 },
"237-23-7738");
request.onerror = new ExpectError(CONSTRAINT_ERR);
request.onsuccess = unexpectedSuccessHandler;
event = yield;
keyIndex = objectStoreDataNameSort.length - 1;
request = objectStore.index("name").openCursor(null, PREV);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, -1, "Saw all the expected keys");
keyIndex = 1;
let keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron");
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 2;
let keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron", true);
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 1;
let keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron", false, true);
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 4, "Saw all the expected keys");
keyIndex = 2;
keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron", true, true);
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 4, "Saw all the expected keys");
keyIndex = 1;
keyRange = moz_indexedDB.makeLeftBoundKeyRange("Bob");
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
keyIndex = 2;
keyRange = moz_indexedDB.makeLeftBoundKeyRange("Bob", true);
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
keyIndex = 0;
keyRange = moz_indexedDB.makeRightBoundKeyRange("Joe");
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 3, "Saw all the expected keys");
keyIndex = 0;
keyRange = moz_indexedDB.makeRightBoundKeyRange("Joe", true);
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 2, "Saw all the expected keys");
keyIndex = 3;
keyRange = moz_indexedDB.makeSingleKeyRange("Pat");
request = objectStore.index("name").openCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 4, "Saw all the expected keys");
keyIndex = 0;
request = objectStore.index("name").openObjectCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
keyIndex = objectStoreDataNameSort.length - 1;
request = objectStore.index("name").openObjectCursor(null, PREV);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, -1, "Saw all the expected keys");
keyIndex = 1;
keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron");
request = objectStore.index("name").openObjectCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 2;
keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron", true);
request = objectStore.index("name").openObjectCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 1;
keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron", false, true);
request = objectStore.index("name").openObjectCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 4, "Saw all the expected keys");
keyIndex = 2;
keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron", true, true);
request = objectStore.index("name").openObjectCursor(keyRange);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 4, "Saw all the expected keys");
keyIndex = 4;
keyRange = moz_indexedDB.makeBoundKeyRange("Bob", "Ron");
request = objectStore.index("name").openObjectCursor(keyRange, PREV);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let retval = cursor.continue();
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 0, "Saw all the expected keys");
// Test NEXT_NO_DUPLICATE
keyIndex = 3;
keyRange = moz_indexedDB.makeSingleKeyRange(65);
request = objectStore.index("height").openCursor(keyRange, NEXT);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.value, objectStoreDataHeightSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 4;
keyRange = moz_indexedDB.makeSingleKeyRange(65);
request = objectStore.index("height").openCursor(keyRange,
NEXT_NO_DUPLICATE);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.value, objectStoreDataHeightSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 5;
request = objectStore.index("height").openCursor(null,
PREV_NO_DUPLICATE);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.value, objectStoreDataHeightSort[keyIndex].key,
"Correct value");
cursor.continue();
if (keyIndex == 4) {
keyIndex--;
}
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, -1, "Saw all the expected keys");
// Test NEXT_NO_DUPLICATE
keyIndex = 3;
keyRange = moz_indexedDB.makeSingleKeyRange(65);
request = objectStore.index("height").openObjectCursor(keyRange, NEXT);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataHeightSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataHeightSort[keyIndex].value.weight,
"Correct weight");
}
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 4;
keyRange = moz_indexedDB.makeSingleKeyRange(65);
request = objectStore.index("height").openObjectCursor(keyRange,
NEXT_NO_DUPLICATE);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataHeightSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataHeightSort[keyIndex].value.weight,
"Correct weight");
}
cursor.continue();
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, 5, "Saw all the expected keys");
keyIndex = 5;
request = objectStore.index("height").openObjectCursor(null,
PREV_NO_DUPLICATE);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataHeightSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataHeightSort[keyIndex].value.weight,
"Correct weight");
}
cursor.continue();
if (keyIndex == 4) {
keyIndex--;
}
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, -1, "Saw all the expected keys");
keyIndex = 0;
request = objectStore.index("name").openCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
let nextKey = !keyIndex ? "Pat" : undefined;
let retval = cursor.continue(nextKey);
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
if (!keyIndex) {
keyIndex = 3;
}
else {
keyIndex++;
}
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreData.length, "Saw all the expected keys");
keyIndex = 0;
request = objectStore.index("name").openCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
let nextKey = !keyIndex ? "Flo" : undefined;
let retval = cursor.continue(nextKey);
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value, objectStoreDataNameSort[keyIndex].key,
"Correct value");
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreData.length, "Saw all the expected keys");
keyIndex = 0;
request = objectStore.index("name").openObjectCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let nextKey = !keyIndex ? "Pat" : undefined;
let retval = cursor.continue(nextKey);
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
if (!keyIndex) {
keyIndex = 3;
}
else {
keyIndex++;
}
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
keyIndex = 0;
request = objectStore.index("name").openObjectCursor();
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.result;
if (cursor) {
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
let nextKey = !keyIndex ? "Flo" : undefined;
let retval = cursor.continue(nextKey);
is(retval, true, "Correct return from continue");
is(cursor.key, objectStoreDataNameSort[keyIndex].value.name,
"Correct key");
is(cursor.value.name, objectStoreDataNameSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataNameSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataNameSort[keyIndex].value.weight,
"Correct weight");
}
keyIndex++;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, objectStoreDataNameSort.length, "Saw all the expected keys");
finishTest();
yield;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>