зеркало из https://github.com/mozilla/gecko-dev.git
114 строки
3.0 KiB
HTML
114 строки
3.0 KiB
HTML
|
<!--
|
||
|
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 READ_WRITE = Components.interfaces.nsIIDBTransaction.READ_WRITE;
|
||
|
|
||
|
const name = window.location.pathname;
|
||
|
const description = "My Test Database";
|
||
|
const entryCount = 1000;
|
||
|
|
||
|
let request = moz_indexedDB.open(name, description);
|
||
|
request.onerror = errorHandler;
|
||
|
request.onsuccess = grabEventAndContinueHandler;
|
||
|
let event = yield;
|
||
|
|
||
|
let db = event.result;
|
||
|
|
||
|
request = db.createObjectStore("foo", "", true);
|
||
|
request.onerror = errorHandler;
|
||
|
request.onsuccess = grabEventAndContinueHandler;
|
||
|
let event = yield;
|
||
|
|
||
|
event.transaction.oncomplete = continueToNextStep;
|
||
|
|
||
|
let objectStore = event.result;
|
||
|
|
||
|
let firstKey;
|
||
|
for (let i = 0; i < entryCount; i++) {
|
||
|
request = objectStore.add({});
|
||
|
request.onerror = errorHandler;
|
||
|
if (!i) {
|
||
|
request.onsuccess = function(event) {
|
||
|
firstKey = event.result;
|
||
|
};
|
||
|
}
|
||
|
}
|
||
|
yield;
|
||
|
|
||
|
isnot(firstKey, undefined, "got first key");
|
||
|
|
||
|
let seenEntryCount = 0;
|
||
|
|
||
|
request = db.objectStore("foo").openCursor();
|
||
|
request.onerror = errorHandler;
|
||
|
request.onsuccess = function(event) {
|
||
|
let cursor = event.result;
|
||
|
if (cursor) {
|
||
|
seenEntryCount++;
|
||
|
cursor.continue();
|
||
|
}
|
||
|
else {
|
||
|
continueToNextStep();
|
||
|
}
|
||
|
}
|
||
|
yield;
|
||
|
|
||
|
is(seenEntryCount, entryCount, "Correct entry count");
|
||
|
|
||
|
try {
|
||
|
db.objectStore("foo").clear();
|
||
|
ok(false, "clear should throw on READ_ONLY transactions");
|
||
|
}
|
||
|
catch (e) {
|
||
|
ok(true, "clear should throw on READ_ONLY transactions");
|
||
|
}
|
||
|
|
||
|
request = db.objectStore("foo", READ_WRITE).clear();
|
||
|
request.onerror = errorHandler;
|
||
|
request.onsuccess = grabEventAndContinueHandler;
|
||
|
event = yield;
|
||
|
|
||
|
ok(event.result === null, "Correct event.result");
|
||
|
|
||
|
request = db.objectStore("foo").openCursor();
|
||
|
request.onerror = errorHandler;
|
||
|
request.onsuccess = function(event) {
|
||
|
let cursor = event.result;
|
||
|
if (cursor) {
|
||
|
ok(false, "Shouldn't have any entries");
|
||
|
}
|
||
|
continueToNextStep();
|
||
|
}
|
||
|
yield;
|
||
|
|
||
|
request = db.objectStore("foo", READ_WRITE).add({});
|
||
|
request.onerror = errorHandler;
|
||
|
request.onsuccess = grabEventAndContinueHandler;
|
||
|
event = yield;
|
||
|
|
||
|
isnot(event.result, firstKey, "Got a different key");
|
||
|
|
||
|
finishTest();
|
||
|
yield;
|
||
|
}
|
||
|
</script>
|
||
|
<script type="text/javascript;version=1.7" src="helpers.js"></script>
|
||
|
|
||
|
</head>
|
||
|
|
||
|
<body onload="runTest();"></body>
|
||
|
|
||
|
</html>
|