JS Test Harness: Remove successfullyParsed from more tests
[WebKit-https.git] / LayoutTests / storage / indexeddb / cursor-index-delete.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 IndexedDB's openCursor.");
12 if (window.layoutTestController)
13     layoutTestController.waitUntilDone();
14
15 test();
16
17 function test()
18 {
19     request = evalAndLog("webkitIndexedDB.open('cursor-index-delete')");
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 = openCursor;
40
41     deleteAllObjectStores(db);
42
43     objectStore = evalAndLog("objectStore = db.createObjectStore('test')");
44     evalAndLog("objectStore.createIndex('testIndex', 'x')");
45
46     evalAndLog("objectStore.add({x: 1}, 'myKey1')");
47     evalAndLog("objectStore.add({x: 2}, 'myKey2')");
48     evalAndLog("objectStore.add({x: 3}, 'myKey3')");
49     evalAndLog("objectStore.add({x: 4}, 'myKey4')");
50 }
51
52 function openCursor()
53 {
54     debug("openCursor1");
55     evalAndLog("trans = db.transaction(['test'], webkitIDBTransaction.READ_WRITE)");
56     keyRange = webkitIDBKeyRange.lowerBound(1);
57     request = evalAndLog("trans.objectStore('test').index('testIndex').openCursor(keyRange)");
58     request.onsuccess = cursorSuccess;
59     request.onerror = unexpectedErrorCallback;
60     counter = 1;
61 }
62
63 function cursorSuccess()
64 {
65     if (event.target.result == null) {
66         shouldBe("counter", "5");
67         request = evalAndLog("trans.objectStore('test').index('testIndex').openCursor(keyRange)");
68         request.onsuccess = cursorEmpty;
69         request.onerror = unexpectedErrorCallback;
70         return;
71     }
72     var deleteRequest = evalAndLog("event.target.result.delete()");
73     deleteRequest.onerror = unexpectedErrorCallback;
74     shouldBe("event.target.result.key", "counter++");
75     evalAndLog("event.target.result.continue()");
76 }
77
78 function cursorEmpty()
79 {
80     shouldBeNull("event.target.result");
81     trans.oncomplete = addObject;
82 }
83
84 function addObject()
85 {
86     evalAndLog("trans = db.transaction(['test'], webkitIDBTransaction.READ_WRITE)");
87     objectStore = evalAndLog("objectStore = trans.objectStore('test')");
88     request = evalAndLog("objectStore.add({x: 1}, 'myKey1')");
89     request.onsuccess = openCursor2;
90     request.onerror = unexpectedErrorCallback;
91 }
92
93 function openCursor2()
94 {
95     debug("openCursor2");
96     evalAndLog("index = event.target.source.index('testIndex')");
97     request = evalAndLog("index.openCursor(keyRange)");
98     request.onsuccess = deleteObject;
99     request.onerror = unexpectedErrorCallback;
100 }
101
102 function deleteObject()
103 {
104     shouldBeNonNull(event.target.result);
105     evalAndLog("event.target.result.delete()");
106     request = evalAndLog("index.get(1)");
107     request.onsuccess = unexpectedSuccessCallback;
108     request.onerror = verifyObjectDeleted;
109 }
110
111 function verifyObjectDeleted()
112 {
113     evalAndLog("event.preventDefault()");
114     done();
115 }
116
117
118 </script>
119 </body>
120 </html>