Modern IDB: Remove unneeded "Alert: " string from storage/indexeddb/modern tests.
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / resources / idbobjectstore-clear-1.js
1 description("This test creates an object store then populates it. \
2 It then clears it and makes sure it has nothing left in it.");
3
4 if (window.testRunner) {
5     testRunner.waitUntilDone();
6     testRunner.dumpAsText();
7 }
8
9 function done()
10 {
11     finishJSTest();
12 }
13
14 var createRequest = window.indexedDB.open("IDBObjectStoreClearDatabase", 1);
15
16 createRequest.onupgradeneeded = function(event) {
17     debug("Initial upgrade needed: Old version - " + event.oldVersion + " New version - " + event.newVersion);
18
19     var versionTransaction = createRequest.transaction;
20     var database = event.target.result;
21     var objectStore = database.createObjectStore("TestObjectStore", { autoIncrement: true });
22     var request = objectStore.put("bar1");
23     var request = objectStore.put("bar2");
24     var request = objectStore.put("bar3");
25     var request = objectStore.put("bar4");
26     var request = objectStore.put("bar5");
27     var request = objectStore.put("bar6");
28     var request = objectStore.put("bar7");
29     var request = objectStore.put("bar8");
30     var request = objectStore.put("bar9");
31
32     versionTransaction.onabort = function(event) {
33         debug("Initial upgrade versionchange transaction unexpected aborted");
34         done();
35     }
36
37     versionTransaction.oncomplete = function(event) {
38         debug("Initial upgrade versionchange transaction complete");
39         continueTest1();
40         database.close();
41     }
42
43     versionTransaction.onerror = function(event) {
44         debug("Initial upgrade versionchange transaction unexpected error" + event);
45         done();
46     }
47 }
48
49 function getChecker(event) {
50     debug("Value gotten was " + event.target.result);
51 }
52
53 function continueTest1()
54 {
55     var openRequest = window.indexedDB.open("IDBObjectStoreClearDatabase", 1);
56
57     openRequest.onerror = function(event) {
58         debug("Request unexpected error - " + event);
59         done();
60     }
61     openRequest.onblocked = function(event) {
62         debug("Request unexpected blocked - " + event);
63         done();
64     }
65     openRequest.onupgradeneeded = function(event) {
66         debug("Request unexpected upgradeneeded - " + event);
67         done();
68     }
69
70     openRequest.onsuccess = function(event) {
71         debug("Success opening database connection - Starting readwrite transaction");
72         var database = event.target.result;
73         var transaction = database.transaction("TestObjectStore", "readwrite");
74         var objectStore = transaction.objectStore("TestObjectStore");
75     
76         var request;
77         for (var i = 1; i <= 9; ++i) {
78             request = objectStore.get(i);
79             request.onsuccess = getChecker;
80         }
81         
82         request = objectStore.clear();
83         request.onsuccess = function() {
84             debug("Object store cleared");
85             var newRequests;
86             for (var i = 1; i <= 9; ++i) {
87                 newRequests = objectStore.get(i);
88                 newRequests.onsuccess = getChecker;
89             }    
90         }
91
92         transaction.onabort = function(event) {
93             debug("Readwrite transaction unexpected abort");
94             done();
95         }
96
97         transaction.oncomplete = function(event) {
98             debug("Readwrite transaction complete");
99             done();
100         }
101
102         transaction.onerror = function(event) {
103             debug("Readwrite transaction unexpected error - " + event);
104             done();
105         }
106     }
107 }