OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>IDBCursor.continue() - index - add next element, and iterate to it</title
> |
| 3 <link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal"> |
| 4 <script src="../../../resources/testharness.js"></script> |
| 5 <script src="../../../resources/testharnessreport.js"></script> |
| 6 <script src="support.js"></script> |
| 7 |
| 8 <script> |
| 9 var db, |
| 10 count = 0, |
| 11 t = async_test(document.title, {timeout: 10000}), |
| 12 records = [ { pKey: "primaryKey_0", obj: { iKey: "iKey_0" }}, |
| 13 { pKey: "primaryKey_2", obj: { iKey: "iKey_2" }} ], |
| 14 |
| 15 expected = [ [ "primaryKey_2", "iKey_2" ], |
| 16 [ "primaryKey_1", "iKey_1" ], |
| 17 [ "primaryKey_0", "iKey_0" ] ]; |
| 18 |
| 19 var open_rq = createdb(t); |
| 20 open_rq.onupgradeneeded = function(e) { |
| 21 db = e.target.result; |
| 22 var objStore = db.createObjectStore("test", {keyPath:"pKey"}); |
| 23 objStore.createIndex("index", [ "pKey", "obj.iKey" ]); |
| 24 |
| 25 for (var i = 0; i < records.length; i++) |
| 26 objStore.add(records[i]); |
| 27 }; |
| 28 |
| 29 open_rq.onsuccess = function(e) { |
| 30 var cursor_rq = db.transaction("test", "readwrite") |
| 31 .objectStore("test") |
| 32 .index("index") |
| 33 .openCursor(null, "prev"); |
| 34 |
| 35 cursor_rq.onsuccess = t.step_func(function(e) { |
| 36 var cursor = e.target.result; |
| 37 if (!cursor) { |
| 38 assert_equals(count, 3, "cursor run count"); |
| 39 t.done(); |
| 40 } |
| 41 |
| 42 if (count === 0) { |
| 43 e.target.source.objectStore.add({ pKey: "primaryKey_1", obj: { i
Key: "iKey_1" } }); |
| 44 } |
| 45 assert_array_equals(cursor.key, expected[count], "primary key"); |
| 46 |
| 47 cursor.continue(); |
| 48 count++; |
| 49 }); |
| 50 }; |
| 51 </script> |
| 52 |
| 53 <div id="log"> </div> |
OLD | NEW |