2010-06-23 19:46:08 +00: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="/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 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 = [
|
2010-12-21 16:02:01 +00:00
|
|
|
{ name: "name", keyPath: "name", options: { unique: true } },
|
|
|
|
{ name: "height", keyPath: "height", options: { unique: false } },
|
|
|
|
{ name: "weight", keyPath: "weight", options: { unique: false } }
|
2010-06-23 19:46:08 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
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 } }
|
|
|
|
];
|
|
|
|
|
2011-10-20 16:10:56 +00:00
|
|
|
let request = mozIndexedDB.open(name, 1, description);
|
2010-06-23 19:46:08 +00:00
|
|
|
request.onerror = errorHandler;
|
2011-10-20 16:10:56 +00:00
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2010-06-23 19:46:08 +00:00
|
|
|
let event = yield;
|
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
let db = event.target.result;
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-12-21 16:02:01 +00:00
|
|
|
let objectStore = db.createObjectStore(objectStoreName, {});
|
2010-06-23 19:46:08 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2010-10-19 17:58:52 +00:00
|
|
|
// Now create the indexes.
|
2010-06-23 19:46:08 +00:00
|
|
|
for (let i in indexData) {
|
2010-10-19 17:58:52 +00:00
|
|
|
objectStore.createIndex(indexData[i].name, indexData[i].keyPath,
|
2010-12-21 16:02:01 +00:00
|
|
|
indexData[i].options);
|
2010-06-23 19:46:08 +00:00
|
|
|
}
|
2010-10-19 17:58:52 +00:00
|
|
|
|
|
|
|
is(objectStore.indexNames.length, indexData.length, "Good index count");
|
2011-10-24 22:49:59 +00:00
|
|
|
continueToNextStep();
|
2010-06-23 19:46:08 +00:00
|
|
|
yield;
|
|
|
|
|
2010-10-19 17:58:49 +00:00
|
|
|
objectStore = db.transaction(objectStoreName)
|
|
|
|
.objectStore(objectStoreName);
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2010-12-15 21:21:02 +00:00
|
|
|
request = objectStore.index("height").getAll(65);
|
2010-06-23 19:46:08 +00:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 2, "Correct length");
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
let result = event.target.result[i];
|
2010-06-23 19:46:08 +00:00
|
|
|
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
|
|
|
|
|
|
|
is(result.name, testObj.name, "Correct name");
|
|
|
|
is(result.height, testObj.height, "Correct height");
|
|
|
|
|
|
|
|
if (testObj.hasOwnProperty("weight")) {
|
|
|
|
is(result.weight, testObj.weight, "Correct weight");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 21:21:02 +00:00
|
|
|
request = objectStore.index("height").getAll();
|
2010-06-23 19:46:08 +00:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, objectStoreDataHeightSort.length,
|
2010-06-23 19:46:08 +00:00
|
|
|
"Correct length");
|
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
let result = event.target.result[i];
|
2010-06-23 19:46:08 +00:00
|
|
|
let testObj = objectStoreDataHeightSort[i].value;
|
|
|
|
|
|
|
|
is(result.name, testObj.name, "Correct name");
|
|
|
|
is(result.height, testObj.height, "Correct height");
|
|
|
|
|
|
|
|
if (testObj.hasOwnProperty("weight")) {
|
|
|
|
is(result.weight, testObj.weight, "Correct weight");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 21:21:02 +00:00
|
|
|
request = objectStore.index("height").getAll(null, 4);
|
2010-06-23 19:46:08 +00:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 4, "Correct length");
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
let result = event.target.result[i];
|
2010-06-23 19:46:08 +00:00
|
|
|
let testObj = objectStoreDataHeightSort[i].value;
|
|
|
|
|
|
|
|
is(result.name, testObj.name, "Correct name");
|
|
|
|
is(result.height, testObj.height, "Correct height");
|
|
|
|
|
|
|
|
if (testObj.hasOwnProperty("weight")) {
|
|
|
|
is(result.weight, testObj.weight, "Correct weight");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 21:21:02 +00:00
|
|
|
request = objectStore.index("height").getAll(65, 1);
|
2010-06-23 19:46:08 +00:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
is(event.target.result instanceof Array, true, "Got an array object");
|
|
|
|
is(event.target.result.length, 1, "Correct length");
|
2010-06-23 19:46:08 +00:00
|
|
|
|
2011-01-07 06:21:36 +00:00
|
|
|
for (let i in event.target.result) {
|
|
|
|
let result = event.target.result[i];
|
2010-06-23 19:46:08 +00:00
|
|
|
let testObj = objectStoreDataHeightSort[parseInt(i) + 3].value;
|
|
|
|
|
|
|
|
is(result.name, testObj.name, "Correct name");
|
|
|
|
is(result.height, testObj.height, "Correct height");
|
|
|
|
|
|
|
|
if (testObj.hasOwnProperty("weight")) {
|
|
|
|
is(result.weight, testObj.weight, "Correct weight");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|