| OLD | NEW | 
| (Empty) |  | 
 |   1 <!DOCTYPE html> | 
 |   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> | 
 |   7  | 
 |   8 <script> | 
 |   9  | 
 |  10     var db, | 
 |  11       count = 0, | 
 |  12       t = async_test(), | 
 |  13       records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" }, | 
 |  14                   { pKey: "primaryKey_1", iKey: "indexKey_1" } ]; | 
 |  15  | 
 |  16     var open_rq = createdb(t); | 
 |  17     open_rq.onupgradeneeded = function(e) { | 
 |  18         db = e.target.result; | 
 |  19  | 
 |  20         var objStore = db.createObjectStore("test", { keyPath: "pKey" }); | 
 |  21         objStore.createIndex("index", "iKey"); | 
 |  22  | 
 |  23         for (var i = 0; i < records.length; i++) | 
 |  24             objStore.add(records[i]); | 
 |  25  | 
 |  26         // XXX: Gecko doesn't like this | 
 |  27         //e.target.transaction.oncomplete = t.step_func(CursorUpdateRecord); | 
 |  28     }; | 
 |  29  | 
 |  30     open_rq.onsuccess = CursorUpdateRecord; | 
 |  31  | 
 |  32  | 
 |  33     function CursorUpdateRecord(e) { | 
 |  34         var txn = db.transaction("test", "readwrite"), | 
 |  35           cursor_rq = txn.objectStore("test") | 
 |  36                          .index("index") | 
 |  37                          .openCursor(); | 
 |  38         cursor_rq.onsuccess = t.step_func(function(e) { | 
 |  39             var cursor = e.target.result; | 
 |  40  | 
 |  41             cursor.value.iKey += "_updated"; | 
 |  42             cursor.update(cursor.value); | 
 |  43         }); | 
 |  44  | 
 |  45         txn.oncomplete = t.step_func(VerifyRecordWasUpdated); | 
 |  46     } | 
 |  47  | 
 |  48  | 
 |  49     function VerifyRecordWasUpdated(e) { | 
 |  50         var cursor_rq = db.transaction("test") | 
 |  51                           .objectStore("test") | 
 |  52                           .openCursor(); | 
 |  53  | 
 |  54         cursor_rq.onsuccess = t.step_func(function(e) { | 
 |  55             var cursor = e.target.result; | 
 |  56  | 
 |  57             assert_equals(cursor.value.iKey, records[0].iKey + "_updated"); | 
 |  58             t.done(); | 
 |  59         }); | 
 |  60     } | 
 |  61  | 
 |  62 </script> | 
 |  63  | 
 |  64 <div id="log"></div> | 
| OLD | NEW |