2 <title>IDBCursor.update() - index - modify a record in the object store </title>
3 <link rel="author" title="Microsoft" href="http://www.microsoft.com">
4 <script src="../../../resources/testharness.js"></script>
5 <script src="../../../resources/testharnessreport.js"></script>
6 <script src="support.js"></script>
13 records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" },
14 { pKey: "primaryKey_1", iKey: "indexKey_1" } ];
16 var open_rq = createdb(t);
17 open_rq.onupgradeneeded = function(e) {
20 var objStore = db.createObjectStore("test", { keyPath: "pKey" });
21 objStore.createIndex("index", "iKey");
23 for (var i = 0; i < records.length; i++)
24 objStore.add(records[i]);
26 // XXX: Gecko doesn't like this
27 //e.target.transaction.oncomplete = t.step_func(CursorUpdateRecord);
30 open_rq.onsuccess = CursorUpdateRecord;
33 function CursorUpdateRecord(e) {
34 var txn = db.transaction("test", "readwrite"),
35 cursor_rq = txn.objectStore("test")
38 cursor_rq.onsuccess = t.step_func(function(e) {
39 var cursor = e.target.result;
41 cursor.value.iKey += "_updated";
42 cursor.update(cursor.value);
45 txn.oncomplete = t.step_func(VerifyRecordWasUpdated);
49 function VerifyRecordWasUpdated(e) {
50 var cursor_rq = db.transaction("test")
54 cursor_rq.onsuccess = t.step_func(function(e) {
55 var cursor = e.target.result;
57 assert_equals(cursor.value.iKey, records[0].iKey + "_updated");