OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>IDBCursor.advance() - index - iterate to the next record</title> |
| 3 <link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal"> |
| 4 <link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#
widl-IDBCursor-advance-void-unsigned-long-count"> |
| 5 <link rel=assert title="The operation runs the steps for iterating a cursor coun
t number of times with null as key and this cursor as cursor."> |
| 6 <link rel=assert title="The number of advances forward the cursor should make."> |
| 7 <script src="../../../resources/testharness.js"></script> |
| 8 <script src="../../../resources/testharnessreport.js"></script> |
| 9 <script src="support.js"></script> |
| 10 |
| 11 <script> |
| 12 var db, |
| 13 count = 0, |
| 14 t = async_test(document.title, {timeout: 10000}), |
| 15 records = [ { pKey: "primaryKey_0", iKey: "indexKey_0" }, |
| 16 { pKey: "primaryKey_1", iKey: "indexKey_1" }, |
| 17 { pKey: "primaryKey_1-2", iKey: "indexKey_1" } ], |
| 18 expected = [ { pKey: "primaryKey_0", iKey: "indexKey_0" }, |
| 19 { pKey: "primaryKey_1-2", iKey: "indexKey_1" } ]; |
| 20 |
| 21 var open_rq = createdb(t); |
| 22 open_rq.onupgradeneeded = function(e) { |
| 23 db = e.target.result |
| 24 var objStore = db.createObjectStore("test", { keyPath:"pKey" }) |
| 25 |
| 26 objStore.createIndex("index", "iKey") |
| 27 |
| 28 for (var i = 0; i < records.length; i++) |
| 29 objStore.add(records[i]) |
| 30 }; |
| 31 |
| 32 open_rq.onsuccess = function(e) { |
| 33 var cursor_rq = db.transaction("test") |
| 34 .objectStore("test") |
| 35 .index("index") |
| 36 .openCursor(); |
| 37 |
| 38 cursor_rq.onsuccess = t.step_func(function(e) { |
| 39 var cursor = e.target.result; |
| 40 if (!cursor) { |
| 41 assert_equals(count, expected.length, "cursor run count") |
| 42 t.done() |
| 43 } |
| 44 |
| 45 var record = cursor.value; |
| 46 assert_equals(record.pKey, expected[count].pKey, "primary key"); |
| 47 assert_equals(record.iKey, expected[count].iKey, "index key"); |
| 48 |
| 49 cursor.advance(2); |
| 50 count++; |
| 51 }); |
| 52 }; |
| 53 </script> |
| 54 |
| 55 <div id="log"></div> |
OLD | NEW |