storage/indexeddb/modern/idbobjectstore-get-failures.html is flaky on mac-wk1
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / idbdatabase-deleteobjectstore-failures.html
1 This tests some obvious failures that can happen while calling IDBDatabase.deleteObjectStore()
2 <script>
3
4 if (window.testRunner) {
5     testRunner.waitUntilDone();
6     testRunner.dumpAsText();
7 }
8
9 function done()
10 {
11     alert("Done");
12     if (window.testRunner)
13         testRunner.notifyDone();
14 }
15
16 var createRequest = window.indexedDB.open("IDBDatabaseDeleteObjectStoreFailuresDatabase", 1);
17 var database;
18
19 createRequest.onupgradeneeded = function(event) {
20     alert("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
21
22     var versionTransaction = createRequest.transaction;
23     database = event.target.result;
24     var objectStore = database.createObjectStore("TestObjectStore");
25     var request = objectStore.put("bar", "foo");
26
27     versionTransaction.onabort = function(event) {
28         alert("Initial upgrade versionchange transaction unexpected aborted");
29         done();
30     }
31
32     versionTransaction.oncomplete = function(event) {
33         alert("Initial upgrade versionchange transaction complete");
34         continueTest1();
35     }
36
37     versionTransaction.onerror = function(event) {
38         alert("Initial upgrade versionchange transaction unexpected error" + event);
39         done();
40     }
41 }
42
43 function continueTest1()
44 {
45     var transaction = database.transaction("TestObjectStore", "readwrite");
46     var objectStore = transaction.objectStore("TestObjectStore");
47     var request = objectStore.put("baz", "foo");
48
49     request.onsuccess = function() {
50         alert("readwrite put success - about to try to delete an objectstore");
51         try {
52             database.deleteObjectStore("TestObjectStore");
53         } catch(e) {
54             alert("Failed to deleteObjectStore without a versionchange transaction - " + e);
55         }
56     }
57     
58     transaction.onabort = function(event) {
59         alert("readwrite transaction unexpected aborted");
60         done();
61     }
62
63     transaction.oncomplete = function(event) {
64         alert("readwrite transaction complete");
65         continueTest2();
66         database.close();
67     }
68
69     transaction.onerror = function(event) {
70         alert("readwrite transaction unexpected error" + event);
71         done();
72     }
73 }
74
75 function continueTest2()
76 {
77     var openRequest = window.indexedDB.open("IDBDatabaseDeleteObjectStoreFailuresDatabase", 2);
78
79     openRequest.onerror = function(event) {
80         alert("Request unexpected error - " + event);
81         done();
82     }
83     openRequest.onblocked = function(event) {
84         alert("Request unexpected blocked - " + event);
85         done();
86     }
87     openRequest.onsuccess = function(event) {
88         alert("Request unexpected success - " + event);
89         done();
90     }
91
92     openRequest.onupgradeneeded = function(event) {
93         alert("Second upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
94     
95         var versionTransaction = openRequest.transaction;
96         database = event.target.result;
97
98         try {
99             database.deleteObjectStore("NonexistentObjectStore");
100         } catch(e) {
101             alert("Failed to deleteObjectStore with a non-existent objectstore - " + e);
102         }
103
104         // Queue up some puts to keep the transaction alive long enough for the setTimeout to fire.
105         var objectStore = versionTransaction.objectStore("TestObjectStore");
106         objectStore.put("we will we will", 1).onsuccess = function() {
107             objectStore.put("rock you", 2);
108         }
109         
110         // After the versionChange transaction becomes inactive, but while it's still in-progress, try to delete the objectstore
111         var tryInactiveDelete = function() 
112         {
113             try {
114                 database.deleteObjectStore("TestObjectStore");
115             } catch(e) {
116                 alert("Failed to deleteObjectStore with an in-progress versionchange transaction that is inactive - " + e);
117             }
118         }
119         
120         setTimeout(tryInactiveDelete, 0);
121
122         versionTransaction.onabort = function(event) {
123             alert("Second version change transaction unexpected abort");
124             done();
125         }
126
127         versionTransaction.oncomplete = function(event) {
128             alert("Second version change transaction complete");
129             done();
130         }
131
132         versionTransaction.onerror = function(event) {
133             alert("Second version change transaction unexpected error - " + event);
134             done();
135         }
136     }
137 }
138 </script>