OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>IDBCursor.delete() - index - remove a record from 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 |
| 27 open_rq.onsuccess = t.step_func(CursorDeleteRecord); |
| 28 |
| 29 |
| 30 function CursorDeleteRecord(e) { |
| 31 var txn = db.transaction("test", "readwrite"), |
| 32 cursor_rq = txn.objectStore("test") |
| 33 .index("index") |
| 34 .openCursor(); |
| 35 |
| 36 cursor_rq.onsuccess = t.step_func(function(e) { |
| 37 var cursor = e.target.result; |
| 38 |
| 39 assert_true(cursor instanceof IDBCursor, "cursor exist"); |
| 40 cursor.delete(); |
| 41 }); |
| 42 |
| 43 txn.oncomplete = t.step_func(VerifyRecordWasDeleted); |
| 44 } |
| 45 |
| 46 |
| 47 function VerifyRecordWasDeleted(e) { |
| 48 var cursor_rq = db.transaction("test") |
| 49 .objectStore("test") |
| 50 .openCursor(); |
| 51 |
| 52 cursor_rq.onsuccess = t.step_func(function(e) { |
| 53 var cursor = e.target.result; |
| 54 |
| 55 if (!cursor) { |
| 56 assert_equals(count, 1, 'count'); |
| 57 t.done(); |
| 58 } |
| 59 |
| 60 assert_equals(cursor.value.pKey, records[1].pKey); |
| 61 assert_equals(cursor.value.iKey, records[1].iKey); |
| 62 cursor.continue(); |
| 63 count++; |
| 64 }); |
| 65 } |
| 66 |
| 67 </script> |
| 68 |
| 69 <div id="log"></div> |
OLD | NEW |