gecko/dom/indexedDB/test/test_odd_result_order.html

98 lines
2.6 KiB
HTML

<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database 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 data = { key: 5, index: 10 };
let request = mozIndexedDB.open(window.location.pathname);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let db;
setTimeout(function() {
db = request.result;
continueToNextStep();
}, 0);
yield;
ok(db instanceof IDBDatabase, "Got a real database");
db.onerror = errorHandler;
db.setVersion("1").onsuccess = grabEventAndContinueHandler;
event = yield;
let objectStore = db.createObjectStore("foo", { keyPath: "key",
autoIncrement: true });
let index = objectStore.createIndex("foo", "index");
event.target.transaction.oncomplete = continueToNextStep;
yield;
objectStore = db.transaction("foo", IDBTransaction.READ_WRITE)
.objectStore("foo");
request = objectStore.add(data);
request.onsuccess = grabEventAndContinueHandler;
event = yield;
let key;
setTimeout(function() {
key = request.result;
continueToNextStep();
}, 0);
yield;
is(key, data.key, "Got the right key");
objectStore = db.transaction("foo").objectStore("foo");
objectStore.get(data.key).onsuccess = grabEventAndContinueHandler;
event = yield;
let obj;
setTimeout(function() {
obj = event.target.result;
continueToNextStep();
}, 0);
yield;
is(obj.key, data.key, "Got the right key");
is(obj.index, data.index, "Got the right property value");
objectStore = db.transaction("foo", IDBTransaction.READ_WRITE)
.objectStore("foo");
request = objectStore.delete(data.key);
request.onsuccess = grabEventAndContinueHandler;
event = yield;
key = undefined;
setTimeout(function() {
key = request.result;
continueToNextStep();
}, 0);
yield;
is(key, data.key, "Got the right key");
finishTest();
yield;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>