Modern IDB: Remove unneeded "Alert: " string from storage/indexeddb/modern tests.
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / resources / idbobjectstore-clear-2.js
1 description("This test creates an object store then populates it, then commits that transaction. \
2 It then clears it, but aborts that transaction. \
3 Finally it checks to make sure everything from step 1 is still in there.");
4
5 if (window.testRunner) {
6     testRunner.waitUntilDone();
7     testRunner.dumpAsText();
8 }
9
10 function done()
11 {
12     finishJSTest();
13 }
14
15 var createRequest = window.indexedDB.open("IDBObjectStoreClear2Database", 1);
16
17 createRequest.onupgradeneeded = function(event) {
18     debug("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
19
20     var versionTransaction = createRequest.transaction;
21     var database = event.target.result;
22     var objectStore = database.createObjectStore("TestObjectStore", { autoIncrement: true });
23     var request = objectStore.put("bar1");
24     var request = objectStore.put("bar2");
25     var request = objectStore.put("bar3");
26     var request = objectStore.put("bar4");
27     var request = objectStore.put("bar5");
28     var request = objectStore.put("bar6");
29     var request = objectStore.put("bar7");
30     var request = objectStore.put("bar8");
31     var request = objectStore.put("bar9");
32
33     versionTransaction.onabort = function(event) {
34         debug("Initial upgrade versionchange transaction unexpected aborted");
35         done();
36     }
37
38     versionTransaction.oncomplete = function(event) {
39         debug("Initial upgrade versionchange transaction complete");
40         continueTest1();
41         database.close();
42     }
43
44     versionTransaction.onerror = function(event) {
45         debug("Initial upgrade versionchange transaction unexpected error" + event);
46         done();
47     }
48 }
49
50 function getChecker(event) {
51     debug("Value gotten was " + event.target.result);
52 }
53
54 function continueTest1()
55 {
56     var openRequest = window.indexedDB.open("IDBObjectStoreClear2Database", 1);
57
58     openRequest.onerror = function(event) {
59         debug("Request unexpected error - " + event);
60         done();
61     }
62     openRequest.onblocked = function(event) {
63         debug("Request unexpected blocked - " + event);
64         done();
65     }
66     openRequest.onupgradeneeded = function(event) {
67         debug("Request unexpected upgradeneeded - " + event);
68         done();
69     }
70
71     openRequest.onsuccess = function(event) {
72         debug("Success opening database connection - Starting readwrite transaction");
73         var database = event.target.result;
74         var transaction = database.transaction("TestObjectStore", "readwrite");
75         var objectStore = transaction.objectStore("TestObjectStore");
76     
77         var request;
78         for (var i = 1; i <= 9; ++i) {
79             request = objectStore.get(i);
80             request.onsuccess = getChecker;
81         }
82         
83         request = objectStore.clear();
84         request.onsuccess = function() {
85             debug("Object store cleared, making sure its all gone.");
86             var newRequests;
87             for (var i = 1; i <= 9; ++i) {
88                 newRequests = objectStore.get(i);
89                 newRequests.onsuccess = getChecker;
90             }
91             
92             // We'll be on the last request here, can just override it.
93             newRequests.onsuccess = function(event) {
94                 getChecker(event);
95                 transaction.abort();
96             }
97         }
98         
99         // Just for fun clear it twice, won't change anything
100         objectStore.clear();
101
102         transaction.onabort = function(event) {
103             debug("Readwrite transaction abort");
104             continueTest2();
105         }
106
107         transaction.oncomplete = function(event) {
108             debug("Readwrite transaction unexpected complete");
109             done();
110         }
111
112         transaction.onerror = function(event) {
113             debug("Readwrite transaction unexpected error - " + event);
114             done();
115         }
116     }
117 }
118
119 function continueTest2()
120 {
121     var openRequest = window.indexedDB.open("IDBObjectStoreClear2Database", 1);
122
123     openRequest.onerror = function(event) {
124         debug("Request unexpected error - " + event);
125         done();
126     }
127     openRequest.onblocked = function(event) {
128         debug("Request unexpected blocked - " + event);
129         done();
130     }
131     openRequest.onupgradeneeded = function(event) {
132         debug("Request unexpected upgradeneeded - " + event);
133         done();
134     }
135
136     openRequest.onsuccess = function(event) {
137         debug("Success opening database connection - Starting final transaction");
138         var database = event.target.result;
139         var transaction = database.transaction("TestObjectStore", "readwrite");
140         var objectStore = transaction.objectStore("TestObjectStore");
141     
142         var request;
143         for (var i = 1; i <= 9; ++i) {
144             request = objectStore.get(i);
145             request.onsuccess = getChecker;
146         }
147
148         transaction.onabort = function(event) {
149             debug("Readwrite transaction unexpected abort");
150             done();
151         }
152
153         transaction.oncomplete = function(event) {
154             debug("Readwrite transaction complete");
155             done();
156         }
157
158         transaction.onerror = function(event) {
159             debug("Readwrite transaction unexpected error - " + event);
160             done();
161         }
162     }
163 }