tizen beta release
[profile/ivi/webkit-efl.git] / LayoutTests / storage / indexeddb / cursor-inconsistency.html
1 <html>
2 <head>
3 <script src="../../fast/js/resources/js-test-pre.js"></script>
4 <script src="resources/shared.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10
11 description("Test consistency of IndexedDB's cursor objects.");
12 if (window.layoutTestController)
13     layoutTestController.waitUntilDone();
14
15 test();
16
17 function test()
18 {
19     request = evalAndLog("webkitIndexedDB.open('cursor-inconsistency')");
20     request.onsuccess = openSuccess;
21     request.onerror = unexpectedErrorCallback;
22 }
23
24 function openSuccess()
25 {
26     var db = evalAndLog("db = event.target.result");
27
28     request = evalAndLog("db.setVersion('new version')");
29     request.onsuccess = setVersionSuccess;
30     request.onerror = unexpectedErrorCallback;
31 }
32
33 function setVersionSuccess()
34 {
35     debug("setVersionSuccess():");
36     window.trans = evalAndLog("trans = event.target.result");
37     shouldBeTrue("trans !== null");
38     trans.onabort = unexpectedAbortCallback;
39     trans.oncomplete = openBasicCursor;
40
41     deleteAllObjectStores(db);
42
43     var objectStore = evalAndLog("objectStore = db.createObjectStore('basicStore')");
44     evalAndLog("objectStore.add('someValue1', 'someKey1').onerror = unexpectedErrorCallback");
45     evalAndLog("objectStore.add('someValue2', 'someKey2').onerror = unexpectedErrorCallback");
46     evalAndLog("objectStore.add('someValue3', 'someKey3').onerror = unexpectedErrorCallback");
47     evalAndLog("objectStore.add('someValue4', 'someKey4').onerror = unexpectedErrorCallback");
48
49 }
50
51 function openBasicCursor()
52 {
53     debug("openBasicCursor()");
54     evalAndLog("trans = db.transaction(['basicStore'], webkitIDBTransaction.READ_WRITE)");
55     trans.onabort = unexpectedAbortCallback;
56     trans.oncomplete = transactionComplete;
57
58     keyRange = webkitIDBKeyRange.lowerBound("someKey1");
59     window.objectStore = evalAndLog("trans.objectStore('basicStore')");
60     request = evalAndLog("objectStore.openCursor(keyRange)");
61     request.onsuccess = checkCursor;
62     request.onerror = unexpectedErrorCallback;
63     counter = 1;
64 }
65
66 storedCursor = null;
67 function checkCursor()
68 {
69     debug("")
70     debug("checkCursor()");
71     if (event.target.result == null) {
72         shouldBe("counter", "5");
73         return;
74     }
75     if (storedCursor == null)
76       storedCursor = evalAndLog("storedCursor = event.target.result");
77
78     shouldBeTrue("storedCursor === event.target.result");
79     shouldBeEqualToString("storedCursor.key", "someKey" + counter);
80     shouldBeEqualToString("event.target.result.key", "someKey" + counter);
81     shouldBeEqualToString("storedCursor.value", "someValue" + counter);
82     shouldBeEqualToString("event.target.result.value", "someValue" + counter);
83     counter++;
84     evalAndLog("event.target.result.continue()");
85 }
86
87 function transactionComplete()
88 {
89     debug("transactionComplete()");
90     done();
91 }
92
93
94 </script>
95 </body>
96 </html>