Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / imported / web-platform-tests / IndexedDB / idbcursor_continue_objectstore4.htm
1 <!DOCTYPE html>
2 <title>IDBCursor.continue() - object store - attempt to iterate to the next record when the direction is set for the previous record </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     var db,
10       t = async_test(),
11       records = [ { pKey: "primaryKey_0" },
12                   { pKey: "primaryKey_1" },
13                   { pKey: "primaryKey_2" } ];
14
15     var open_rq = createdb(t);
16     open_rq.onupgradeneeded = function(e) {
17         db = e.target.result;
18         var objStore = db.createObjectStore("test", { keyPath: "pKey" });
19
20         for (var i = 0; i < records.length; i++)
21             objStore.add(records[i]);
22     };
23
24     open_rq.onsuccess = function(e) {
25         var count = 0,
26           cursor_rq = db.transaction("test")
27                         .objectStore("test")
28                         .openCursor(null, "prev");
29
30         cursor_rq.onsuccess = t.step_func(function(e) {
31             var cursor = e.target.result;
32
33             assert_true(cursor != null, "cursor exist");
34
35             switch(count) {
36             case 0:
37                 assert_equals(cursor.value.pKey, records[2].pKey, "first cursor pkey");
38                 cursor.continue(records[1].pKey);
39                 break;
40
41             case 1:
42                 assert_equals(cursor.value.pKey, records[1].pKey, "second cursor pkey");
43                 assert_throws("DataError",
44                     function() { cursor.continue(records[2].pKey); });
45                 t.done();
46                 break;
47
48             default:
49                 assert_unreached("Unexpected count value: " + count);
50             }
51
52             count++;
53         });
54     };
55 </script>
56
57 <div id="log"></div>