idbcursor_continue_objectstore.htm
<!DOCTYPE html>
<html>
<head>
<title>IDBCursor.continue() - object store - iterate to the next record</title>
<script type="text/javascript" src="support.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
var objectStoreName = "objectstore";
var records = [ { pKey: "primaryKey_0" },
{ pKey: "primaryKey_1" }];
var count = 0;
var db = null;
var t = async_test();
function RunTest() {
var rqOpen = window.indexedDB.open(databaseName, databaseVersion);
rqOpen.onupgradeneeded = t.step_func( function (event) {
db = event.target.result;
db.onerror = t.step_func( assert_database_error );
var objStore = db.createObjectStore(objectStoreName, {keyPath:"pKey"});
for(var i = 0; i < records.length; i++) {
objStore.add(records[i]);
}
});
rqOpen.onsuccess = t.step_func( VerifyCursorIterates );
rqOpen.onerror = t.step_func( assert_open_request_error );
}
function VerifyCursorIterates(event) {
var txn = db.transaction(objectStoreName, "readonly");
var objStore = txn.objectStore(objectStoreName);
var rqCursor = objStore.openCursor();
rqCursor.onsuccess = t.step_func( function(event) {
var cursor = event.target.result;
if(cursor) {
var record = cursor.value;
assert_equals(record.pKey, records[count].pKey, "record.pKey");
count++;
cursor.continue();
} else {
assert_equals(count, records.length, "count");
t.done();
}
});
}
add_completion_callback(function() { if(db) db.close(); });
setup(function() {
var rqDelete = window.indexedDB.deleteDatabase(databaseName);
rqDelete.onsuccess = t.step_func( RunTest );
});
</script>
</head>
<body>
<div id="log">
</div>
</body>
</html>