f0b3b970f9973c8a91793eddd6addaa2ccddab41
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / deleteobjectstore-1.html
1 This test creates an object store then populates it, then commits that transaction.<br>
2 It then deletes it, but aborts that transaction.<br>
3 Finally it checks to make sure everything from step 1 is there as expected.<br>
4 <script>
5
6 if (window.testRunner) {
7     testRunner.waitUntilDone();
8     testRunner.dumpAsText();
9 }
10
11 function done()
12 {
13     alert("Done");
14     if (window.testRunner)
15         testRunner.notifyDone();
16 }
17
18 var createRequest = window.indexedDB.open("DeleteObjectStore1Database", 1);
19
20 createRequest.onupgradeneeded = function(event) {
21     alert("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
22
23     var versionTransaction = createRequest.transaction;
24     var database = event.target.result;
25     var objectStore = database.createObjectStore("TestObjectStore");
26     for (var i = 0; i < 10; ++i)
27         objectStore.put("AH AH AH AH AH", i + " puts");
28
29     versionTransaction.onabort = function(event) {
30         alert("Initial upgrade versionchange transaction unexpected aborted");
31         done();
32     }
33
34     versionTransaction.oncomplete = function(event) {
35         alert("Initial upgrade versionchange transaction complete");
36         continueTest1();
37         database.close();
38     }
39
40     versionTransaction.onerror = function(event) {
41         alert("Initial upgrade versionchange transaction unexpected error" + event);
42         done();
43     }
44 }
45
46 function getChecker(event) {
47     alert("Value gotten was " + event.target.result);
48 }
49
50 function continueTest1()
51 {
52     var openRequest = window.indexedDB.open("DeleteObjectStore1Database", 2);
53
54     openRequest.onerror = function(event) {
55         alert("Request unexpected error - " + event);
56         done();
57     }
58     openRequest.onblocked = function(event) {
59         alert("Request unexpected blocked - " + event);
60         done();
61     }
62     openRequest.onsuccess = function(event) {
63         alert("Request unexpected success - " + event);
64         done();
65     }
66
67     openRequest.onupgradeneeded = function(event) {
68         alert("Second upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
69         var versionTransaction = openRequest.transaction;
70         var database = event.target.result;
71         var objectStore = versionTransaction.objectStore("TestObjectStore");
72         
73         alert("Deleting object store");        
74         database.deleteObjectStore("TestObjectStore");
75
76         versionTransaction.abort();
77
78         versionTransaction.onabort = function(event) {
79             alert("Second version change transaction abort");
80             continueTest2();
81             database.close();
82         }
83
84         versionTransaction.oncomplete = function(event) {
85             alert("Second version change transaction unexpected complete");
86             done();
87         }
88
89         versionTransaction.onerror = function(event) {
90             alert("Second version change transaction unexpected error - " + event);
91             done();
92         }
93     }
94 }
95
96 function continueTest2()
97 {
98     var openRequest = window.indexedDB.open("DeleteObjectStore1Database", 1);
99
100     openRequest.onerror = function(event) {
101         alert("Request unexpected error - " + event);
102         done();
103     }
104     openRequest.onblocked = function(event) {
105         alert("Request unexpected blocked - " + event);
106         done();
107     }
108     openRequest.onupgradeneeded = function(event) {
109         alert("Request unexpected upgradeneeded - " + event);
110         done();
111     }
112
113     openRequest.onsuccess = function(event) {
114         alert("Success opening database connection - Starting final transaction");
115         var database = event.target.result;
116         var transaction = database.transaction("TestObjectStore", "readwrite");
117         var objectStore = transaction.objectStore("TestObjectStore");
118     
119         var request;
120         for (var i = 0; i < 10; ++i) {
121             request = objectStore.get(i + " puts");
122             request.onsuccess = getChecker;
123         }
124
125         transaction.onabort = function(event) {
126             alert("Final transaction unexpected abort");
127             done();
128         }
129
130         transaction.oncomplete = function(event) {
131             alert("Final transaction complete");
132             done();
133         }
134
135         transaction.onerror = function(event) {
136             alert("Final transaction unexpected error - " + event);
137             done();
138         }
139     }
140 }
141 </script>