2010-08-27 00:57:30 +04: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 READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
|
|
|
|
|
|
|
const name = window.location.pathname;
|
|
|
|
const description = "My Test Database";
|
|
|
|
const entryCount = 1000;
|
|
|
|
|
2011-10-20 20:10:56 +04:00
|
|
|
let request = mozIndexedDB.open(name, 1, description);
|
2010-08-27 00:57:30 +04:00
|
|
|
request.onerror = errorHandler;
|
2011-10-20 20:10:56 +04:00
|
|
|
request.onupgradeneeded = grabEventAndContinueHandler;
|
2010-08-27 00:57:30 +04:00
|
|
|
let event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
let db = request.result;
|
2010-08-27 00:57:30 +04:00
|
|
|
|
2011-10-25 02:49:59 +04:00
|
|
|
event.target.transaction.oncomplete = continueToNextStep;
|
2010-08-27 00:57:30 +04:00
|
|
|
|
2010-12-21 19:02:01 +03:00
|
|
|
let objectStore = db.createObjectStore("foo", { autoIncrement: true });
|
2010-08-27 00:57:30 +04:00
|
|
|
|
|
|
|
let firstKey;
|
|
|
|
for (let i = 0; i < entryCount; i++) {
|
|
|
|
request = objectStore.add({});
|
|
|
|
request.onerror = errorHandler;
|
|
|
|
if (!i) {
|
|
|
|
request.onsuccess = function(event) {
|
2011-01-07 09:21:36 +03:00
|
|
|
firstKey = event.target.result;
|
2010-08-27 00:57:30 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
|
|
|
isnot(firstKey, undefined, "got first key");
|
|
|
|
|
|
|
|
let seenEntryCount = 0;
|
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").openCursor();
|
2010-08-27 00:57:30 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = function(event) {
|
2011-01-07 09:21:36 +03:00
|
|
|
let cursor = event.target.result;
|
2010-08-27 00:57:30 +04:00
|
|
|
if (cursor) {
|
|
|
|
seenEntryCount++;
|
|
|
|
cursor.continue();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
continueToNextStep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
|
|
|
is(seenEntryCount, entryCount, "Correct entry count");
|
|
|
|
|
|
|
|
try {
|
2010-10-19 21:58:49 +04:00
|
|
|
db.transaction("foo").objectStore("foo").clear();
|
2010-08-27 00:57:30 +04:00
|
|
|
ok(false, "clear should throw on READ_ONLY transactions");
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
ok(true, "clear should throw on READ_ONLY transactions");
|
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo", READ_WRITE).objectStore("foo").clear();
|
2010-08-27 00:57:30 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
ok(event.target.result === undefined, "Correct event.target.result");
|
|
|
|
ok(request.result === undefined, "Correct request.result");
|
|
|
|
ok(request === event.target, "Correct event.target");
|
2010-08-27 00:57:30 +04:00
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo").objectStore("foo").openCursor();
|
2010-08-27 00:57:30 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = function(event) {
|
2011-01-07 09:21:36 +03:00
|
|
|
let cursor = request.result;
|
2010-08-27 00:57:30 +04:00
|
|
|
if (cursor) {
|
|
|
|
ok(false, "Shouldn't have any entries");
|
|
|
|
}
|
|
|
|
continueToNextStep();
|
|
|
|
}
|
|
|
|
yield;
|
|
|
|
|
2010-10-19 21:58:49 +04:00
|
|
|
request = db.transaction("foo", READ_WRITE).objectStore("foo").add({});
|
2010-08-27 00:57:30 +04:00
|
|
|
request.onerror = errorHandler;
|
|
|
|
request.onsuccess = grabEventAndContinueHandler;
|
|
|
|
event = yield;
|
|
|
|
|
2011-01-07 09:21:36 +03:00
|
|
|
isnot(event.target.result, firstKey, "Got a different key");
|
2010-08-27 00:57:30 +04:00
|
|
|
|
|
|
|
finishTest();
|
|
|
|
yield;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body onload="runTest();"></body>
|
|
|
|
|
|
|
|
</html>
|