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 START_DATA = "hi";
|
|
|
|
const END_DATA = "bye";
|
|
|
|
const objectStoreInfo = [
|
|
|
|
{ name: "1", keyPath: "", key: 1,
|
|
|
|
entry: { data: START_DATA } },
|
|
|
|
{ name: "2", keyPath: "foo",
|
|
|
|
entry: { foo: 1, data: START_DATA } },
|
|
|
|
{ name: "3", keyPath: "", autoIncrement: true,
|
|
|
|
entry: { data: START_DATA } },
|
|
|
|
{ name: "4", keyPath: "foo", autoIncrement: true,
|
|
|
|
entry: { data: START_DATA } },
|
|
|
|
];
|
|
|
|
|
|
|
|
let request = moz_indexedDB.open(name, description);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
let event = yield;
|
|
|
|
|
|
|
|
let db = event.result;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
for (let i = 0; i < objectStoreInfo.length; i++) {
|
|
|
|
// Create our object stores.
|
|
|
|
let info = objectStoreInfo[i];
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
ok(true, "1");
|
|
|
|
request = db.setVersion("1");
|
2010-06-23 12:46:08 -07:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
ok(true, "2");
|
|
|
|
let objectStore = info.hasOwnProperty("autoIncrement") ?
|
|
|
|
db.createObjectStore(info.name, info.keyPath,
|
|
|
|
info.autoIncrement) :
|
|
|
|
db.createObjectStore(info.name, info.keyPath);
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
// Create the indexes on 'data' on the object store.
|
2010-10-19 10:58:52 -07:00
|
|
|
let index = objectStore.createIndex("data_index", "data", false);
|
|
|
|
let uniqueIndex = objectStore.createIndex("unique_data_index", "data", true);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
// Populate the object store with one entry of data.
|
|
|
|
request = info.hasOwnProperty("key") ?
|
|
|
|
objectStore.add(info.entry, info.key) :
|
|
|
|
objectStore.add(info.entry);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
2010-10-19 10:58:52 -07:00
|
|
|
ok(true, "3");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
// Use a cursor to update 'data' to END_DATA.
|
|
|
|
request = objectStore.openCursor();
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
2010-10-19 10:58:52 -07:00
|
|
|
ok(true, "4");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
let cursor = event.result;
|
|
|
|
let obj = cursor.value;
|
|
|
|
obj.data = END_DATA;
|
|
|
|
request = cursor.update(obj);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
2010-10-19 10:58:52 -07:00
|
|
|
ok(true, "5");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
// Check both indexes to make sure that they were updated.
|
|
|
|
request = index.getObject(END_DATA);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
2010-10-19 10:58:52 -07:00
|
|
|
ok(true, "6");
|
2010-06-23 12:46:08 -07:00
|
|
|
SimpleTest.ok(obj.data, event.result.data,
|
|
|
|
"Non-unique index was properly updated.");
|
|
|
|
|
|
|
|
request = uniqueIndex.getObject(END_DATA);
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
ok(true, "7");
|
2010-06-23 12:46:08 -07:00
|
|
|
SimpleTest.ok(obj.data, event.result.data,
|
|
|
|
"Unique index was properly updated.");
|
|
|
|
}
|
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|