Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / imported / web-platform-tests / IndexedDB / idbcursor_iterating_objectstore2.htm
1 <!DOCTYPE html>
2 <title>IDBCursor.continue() - objectstore - 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" },
13                   { pKey: "primaryKey_2" } ],
14       expected_records = [ { pKey: "primaryKey_0" },
15                            { pKey: "primaryKey_1" },
16                            { pKey: "primaryKey_2" } ];
17
18     var open_rq = createdb(t);
19     open_rq.onupgradeneeded = function(e) {
20         db = e.target.result;
21         var objStore = db.createObjectStore("test", {keyPath:"pKey"});
22
23         for (var i = 0; i < records.length; i++)
24             objStore.add(records[i]);
25     };
26
27     open_rq.onsuccess = function(e) {
28         var cursor_rq = db.transaction("test", "readwrite")
29                           .objectStore("test")
30                           .openCursor();
31
32         cursor_rq.onsuccess = t.step_func(function(e) {
33             var cursor = e.target.result;
34             if (!cursor) {
35                 assert_equals(count, 3, "cursor run count");
36                 t.done();
37             }
38
39             var record = cursor.value;
40             if (record.pKey == "primaryKey_0") {
41                e.target.source.add({ pKey: "primaryKey_1" });
42             }
43             assert_equals(record.pKey, expected_records[count].pKey, "primary key");
44
45             cursor.continue();
46             count++;
47         });
48     };
49 </script>
50
51 <div id="log"> </div>