2 <title>IDBCursor direction - object store with keyrange</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#cursor-iteration-operation">
5 <link rel=assert title='If direction is "next", let found record be the first record in records which satisfy all of the following requirements'>
6 <link rel=assert title='If direction is "prev", let found record be the last record in records which satisfy all of the following requirements'>
7 <link rel=assert title="If range is defined, the record's key is in range.">
8 <script src="../../../resources/testharness.js"></script>
9 <script src="../../../resources/testharnessreport.js"></script>
10 <script src="support.js"></script>
13 var records = [ 1337, "Alice", "Bob", "Greg", "Åke", ["Anne"] ];
14 var directions = ["next", "prev", "nextunique", "prevunique"];
17 directions.forEach(function(dir) {
18 tests[dir] = async_test(document.title + ' - ' + dir);
21 var open_rq = indexedDB.open("testdb-" + new Date().getTime() + Math.random());
23 open_rq.onupgradeneeded = function(e) {
24 var objStore = e.target.result.createObjectStore("test");
26 for (var i = 0; i < records.length; i++)
27 objStore.add(records[i], records[i]);
30 open_rq.onsuccess = function(e) {
31 var db = e.target.result;
32 db.onerror = fail_helper("db.onerror");
36 testdir('next', ['Alice', 'Bob', 'Greg']);
37 testdir('prev', ['Greg', 'Bob', 'Alice']);
38 testdir('nextunique', ['Alice', 'Bob', 'Greg']);
39 testdir('prevunique', ['Greg', 'Bob', 'Alice']);
43 function testdir(dir, expect) {
46 var rq = db.transaction("test").objectStore("test").openCursor(IDBKeyRange.bound("AA", "ZZ"), dir);
47 rq.onsuccess = t.step_func(function(e) {
48 var cursor = e.target.result;
50 assert_equals(count, expect.length, "cursor runs");
53 assert_equals(cursor.value, expect[count], "cursor.value");
57 rq.onerror = t.step_func(function(e) {
60 assert_unreached("rq.onerror - " + e.message);
66 function fail_helper(name) {
68 directions.forEach(function(dir) {
69 tests[dir].step(function() { assert_unreached(name); });
73 open_rq.onblocked = fail_helper('open_rq.onblocked');
74 open_rq.onerror = fail_helper('open_rq.onerror');