2010-06-23 12:46:08 -07:00
|
|
|
<!--
|
|
|
|
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 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 } },
|
|
|
|
{ key: "237-23-7738", value: { name: "Mel", height: 66, weight: {} } }
|
|
|
|
];
|
|
|
|
|
|
|
|
const badObjectStoreData = [
|
|
|
|
{ key: "237-23-7739", value: { name: "Rob", height: 65 } },
|
|
|
|
{ key: "237-23-7740", value: { name: "Jen", height: 66, weight: {} } }
|
|
|
|
];
|
|
|
|
|
|
|
|
const indexData = [
|
2010-12-21 08:02:01 -08:00
|
|
|
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
2010-06-23 12:46:08 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
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 } }
|
|
|
|
];
|
|
|
|
|
2011-01-03 12:03:06 -08:00
|
|
|
let request = mozIndexedDB.open(name, description);
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
let event = yield;
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
let db = event.target.result;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
request = db.setVersion("1");
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-12-21 08:02:01 -08:00
|
|
|
let objectStore = db.createObjectStore(objectStoreName, { } );
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for (let i in indexData) {
|
2010-10-19 10:58:52 -07:00
|
|
|
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
2010-12-21 08:02:01 -08:00
|
|
|
indexData[i].options);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
addedData = 0;
|
|
|
|
for (let i in badObjectStoreData) {
|
|
|
|
request = objectStore.add(badObjectStoreData[i].value,
|
|
|
|
badObjectStoreData[i].key);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = function(event) {
|
|
|
|
if (++addedData == badObjectStoreData.length) {
|
|
|
|
SimpleTest.executeSoon(function() { testGenerator.next() });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
2010-10-19 10:58:49 -07:00
|
|
|
objectStore = db.transaction(objectStoreName)
|
|
|
|
.objectStore(objectStoreName);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
let keyIndex = 0;
|
|
|
|
|
2010-12-15 13:21:02 -08:00
|
|
|
request = objectStore.index("weight").openKeyCursor();
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = function (event) {
|
2011-01-06 22:21:36 -08:00
|
|
|
let cursor = event.target.result;
|
2010-06-23 12:46:08 -07:00
|
|
|
if (cursor) {
|
|
|
|
is(cursor.key, objectStoreDataWeightSort[keyIndex].value.weight,
|
|
|
|
"Correct key");
|
2011-02-10 23:47:00 -08:00
|
|
|
is(cursor.primaryKey, objectStoreDataWeightSort[keyIndex].key,
|
2010-06-23 12:46:08 -07:00
|
|
|
"Correct value");
|
|
|
|
keyIndex++;
|
|
|
|
|
|
|
|
cursor.continue();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
|
|
|
is(keyIndex, objectStoreDataWeightSort.length, "Saw all weights");
|
|
|
|
|
|
|
|
keyIndex = 0;
|
|
|
|
|
|
|
|
request = objectStore.openCursor();
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = function (event) {
|
2011-01-06 22:21:36 -08:00
|
|
|
let cursor = event.target.result;
|
2010-06-23 12:46:08 -07:00
|
|
|
if (cursor) {
|
|
|
|
keyIndex++;
|
|
|
|
cursor.continue();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
testGenerator.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
|
|
|
is(keyIndex, objectStoreData.length + badObjectStoreData.length,
|
|
|
|
"Saw all people");
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|