Modern IDB: Remove unneeded "Alert: " string from storage/indexeddb/modern tests.
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / resources / autoincrement-abort.js
1 description("This test creates a new database with an objectstore that autoincrements. \
2 It then puts some things in that object store, checking the keys that were used. \
3 But it then aborts that transaction. \
4 Then it opens a new one and puts something in it, double checking that the key generator was reverted when the above transaction was aborted.");
5
6
7
8 if (window.testRunner) {
9     testRunner.waitUntilDone();
10     testRunner.dumpAsText();
11 }
12
13 function done()
14 {
15     finishJSTest();
16 }
17
18 var createRequest = window.indexedDB.open("AutoincrementAbortDatabase", 1);
19 var database;
20
21 createRequest.onupgradeneeded = function(event) {
22     debug("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
23
24     var versionTransaction = createRequest.transaction;
25     database = event.target.result;
26     var objectStore = database.createObjectStore('TestObjectStore', { autoIncrement: true });
27     
28     versionTransaction.onabort = function(event) {
29         debug("Initial upgrade versionchange transaction unexpected abort");
30         done();
31     }
32
33     versionTransaction.oncomplete = function(event) {
34         debug("Initial upgrade versionchange transaction complete");
35         continueTest1();
36     }
37
38     versionTransaction.onerror = function(event) {
39         debug("Initial upgrade versionchange transaction unexpected error" + event);
40         done();
41     }
42 }
43
44 function putChecker(event) {
45     debug("Key used for put was " + event.target.result);
46 }
47
48 function continueTest1()
49 {
50     debug("Opening readwrite transaction to bump the key generator, but it will be aborted");
51     var transaction = database.transaction('TestObjectStore', "readwrite");
52     var objectStore = transaction.objectStore('TestObjectStore');
53     
54     var request = objectStore.put("bar1");
55     request.onsuccess = putChecker;
56     var request = objectStore.put("bar2");
57     request.onsuccess = putChecker;
58     var request = objectStore.put("bar3");
59     request.onsuccess = putChecker;
60     var request = objectStore.put("bar4");
61     request.onsuccess = putChecker;
62     var request = objectStore.put("bar5");
63     request.onsuccess = putChecker;
64     var request = objectStore.put("bar6");
65     request.onsuccess = function(event) {
66         putChecker(event);
67         transaction.abort();
68     }
69     
70     transaction.onabort = function(event) {
71         debug("readwrite transaction abort");
72         continueTest2();
73     }
74
75     transaction.oncomplete = function(event) {
76         debug("readwrite transaction unexpected complete");
77         done();
78     }
79
80     transaction.onerror = function(event) {
81         debug("readwrite transaction unexpected error");
82         done();
83     }
84 }
85
86 function continueTest2()
87 {
88     debug("Opening readwrite transaction to make sure the key generator had successfully reverted");
89     
90     var transaction = database.transaction('TestObjectStore', "readwrite");
91     var objectStore = transaction.objectStore('TestObjectStore');
92
93     var request = objectStore.put("bar1");
94     request.onsuccess = putChecker;
95     var request = objectStore.put("bar2");
96     request.onsuccess = putChecker;
97     var request = objectStore.put("bar3");
98     request.onsuccess = putChecker;
99     var request = objectStore.put("bar4");
100     request.onsuccess = putChecker;
101     var request = objectStore.put("bar5");
102     request.onsuccess = putChecker;
103     var request = objectStore.put("bar6");
104     request.onsuccess = putChecker;
105
106     transaction.onabort = function(event) {
107         debug("readwrite transaction unexpected abort");
108         done();
109     }
110
111     transaction.oncomplete = function(event) {
112         debug("readwrite transaction complete");
113         continueTest3();
114     }
115
116     transaction.onerror = function(event) {
117         debug("readwrite transaction unexpected error");
118         done();
119     }
120 }
121
122 function continueTest3()
123 {
124     debug("Opening readwrite transaction to make sure the key generator picks up where it should've left off");
125     
126     var transaction = database.transaction('TestObjectStore', "readwrite");
127     var objectStore = transaction.objectStore('TestObjectStore');
128
129     var request = objectStore.put("bar1");
130     request.onsuccess = putChecker;
131     var request = objectStore.put("bar2");
132     request.onsuccess = putChecker;
133     var request = objectStore.put("bar3");
134     request.onsuccess = putChecker;
135     var request = objectStore.put("bar4");
136     request.onsuccess = putChecker;
137     var request = objectStore.put("bar5");
138     request.onsuccess = putChecker;
139     var request = objectStore.put("bar6");
140     request.onsuccess = putChecker;
141
142     transaction.onabort = function(event) {
143         debug("readwrite transaction unexpected abort");
144         done();
145     }
146
147     transaction.oncomplete = function(event) {
148         debug("readwrite transaction complete");
149         done();
150     }
151
152     transaction.onerror = function(event) {
153         debug("readwrite transaction unexpected error");
154         done();
155     }
156 }
157
158