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 nsIIDBObjectStore = Components.interfaces.nsIIDBObjectStore;
|
|
|
|
const nsIIDBTransaction = Components.interfaces.nsIIDBTransaction;
|
|
|
|
|
|
|
|
const name = window.location.pathname;
|
|
|
|
const description = "My Test Database";
|
|
|
|
const objectStoreInfo = [
|
2010-12-21 08:02:01 -08:00
|
|
|
{ name: "a", options: { keyPath: "id", autoIncrement: true } },
|
|
|
|
{ name: "b", options: { keyPath: "id", autoIncrement: false } },
|
2010-06-23 12:46:08 -07:00
|
|
|
];
|
|
|
|
const indexInfo = [
|
2010-12-21 08:02:01 -08:00
|
|
|
{ name: "1", keyPath: "unique_value", options: { unique: true } },
|
|
|
|
{ name: "2", keyPath: "value", options: { unique: false } },
|
|
|
|
{ name: "3", keyPath: "value", options: { unique: false } },
|
2010-06-23 12:46:08 -07:00
|
|
|
];
|
|
|
|
|
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");
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
for (let i = 0; i < objectStoreInfo.length; i++) {
|
|
|
|
let info = objectStoreInfo[i];
|
2010-12-21 08:02:01 -08:00
|
|
|
let objectStore = info.hasOwnProperty("options") ?
|
|
|
|
db.createObjectStore(info.name, info.options) :
|
|
|
|
db.createObjectStore(info.name);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
// Test basic failure conditions.
|
|
|
|
try {
|
|
|
|
request = objectStore.createIndex(null, null);
|
|
|
|
ok(false, "createIndex with null name should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createIndex with null name should throw");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
request = objectStore.createIndex("", "");
|
|
|
|
ok(false, "createIndex with empty name should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createIndex with empty name should throw");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
request = objectStore.createIndex("Hola");
|
|
|
|
ok(false, "createIndex with no keyPath should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createIndex with no keyPath should throw");
|
|
|
|
}
|
|
|
|
|
2010-12-21 08:02:01 -08:00
|
|
|
try {
|
|
|
|
request = objectStore.createIndex("foo", "bar", 10);
|
|
|
|
ok(false, "createIndex with bad options should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createIndex with bad options threw");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
request = objectStore.createIndex("foo", "bar", { foo: "" });
|
|
|
|
ok(false, "createIndex with bad options should throw");
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
ok(true, "createIndex with bad options threw");
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
// Test index creation, and that it ends up in indexNames.
|
|
|
|
let objectStoreName = info.name;
|
|
|
|
for (let j = 0; j < indexInfo.length; j++) {
|
|
|
|
let info = indexInfo[j];
|
|
|
|
let count = objectStore.indexNames.length;
|
2010-12-21 08:02:01 -08:00
|
|
|
let index = info.hasOwnProperty("options") ?
|
2010-10-19 10:58:52 -07:00
|
|
|
objectStore.createIndex(info.name, info.keyPath,
|
2010-12-21 08:02:01 -08:00
|
|
|
info.options) :
|
2010-10-19 10:58:52 -07:00
|
|
|
objectStore.createIndex(info.name, info.keyPath);
|
|
|
|
|
|
|
|
is(index.name, info.name, "correct name");
|
|
|
|
is(index.keyPath, info.keyPath, "correct keyPath");
|
2010-12-21 08:02:01 -08:00
|
|
|
is(index.unique, info.options.unique, "correct uniqueness");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
is(objectStore.indexNames.length, count + 1,
|
|
|
|
"indexNames grew in size");
|
|
|
|
let found = false;
|
|
|
|
for (let k = 0; k < objectStore.indexNames.length; k++) {
|
|
|
|
if (objectStore.indexNames.item(k) == info.name) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ok(found, "Name is on objectStore.indexNames");
|
|
|
|
|
2011-01-06 22:21:36 -08:00
|
|
|
ok(event.target.transaction, "event has a transaction");
|
|
|
|
ok(event.target.transaction.db === db,
|
|
|
|
"transaction has the right db");
|
|
|
|
is(event.target.transaction.readyState, nsIIDBTransaction.LOADING,
|
2010-06-23 12:46:08 -07:00
|
|
|
"transaction has the correct readyState");
|
2011-01-06 22:21:36 -08:00
|
|
|
is(event.target.transaction.mode, nsIIDBTransaction.VERSION_CHANGE,
|
2010-06-23 12:46:08 -07:00
|
|
|
"transaction has the correct mode");
|
2011-01-06 22:21:36 -08:00
|
|
|
is(event.target.transaction.objectStoreNames.length, i + 1,
|
2010-06-23 12:46:08 -07:00
|
|
|
"transaction only has one object store");
|
2011-01-06 22:21:36 -08:00
|
|
|
is(event.target.transaction.objectStoreNames.item(0), objectStoreName,
|
2010-06-23 12:46:08 -07:00
|
|
|
"transaction has the correct object store");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|