storage/indexeddb/modern/idbobjectstore-get-failures.html is flaky on mac-wk1
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / idbobjectstore-put-and-clear-failures.html
1 This tests some obvious failures that can happen while calling IDBObjectStore.put() and IDBObjectStore.clear().
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("IDBObjectStorePutAndClearFailuresDatabase", 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     request.onsuccess = function() {
28         try {
29             objectStore.put("bar", NaN);
30         } catch(e) {
31             alert("Failed to put record into object store with an invalid key");
32         }
33         
34         database.deleteObjectStore("TestObjectStore");
35         
36         try {
37             objectStore.put("bar", "foo");
38         } catch(e) {
39             alert("Failed to put record into object store that has been deleted");
40         } 
41
42         try {
43             objectStore.clear();
44         } catch(e) {
45             alert("Failed to clear object store that has been deleted");
46         } 
47
48         // Recreate the objectstore because we'll need it in phase 2.
49         var objectStore = database.createObjectStore("TestObjectStore");
50         objectStore.put("bar", "foo");    
51     }
52     
53     versionTransaction.onabort = function(event) {
54         alert("Initial upgrade versionchange transaction unexpected aborted");
55         done();
56     }
57
58     versionTransaction.oncomplete = function(event) {
59         alert("Initial upgrade versionchange transaction complete");
60         continueTest1();
61     }
62
63     versionTransaction.onerror = function(event) {
64         alert("Initial upgrade versionchange transaction unexpected error" + event);
65         done();
66     }
67 }
68
69 function continueTest1()
70 {
71     var transaction = database.transaction("TestObjectStore", "readonly");
72     var objectStore = transaction.objectStore("TestObjectStore");
73     
74     try {
75         objectStore.clear();
76     } catch(e) {
77         alert("Failed to clear object store in read-only transaction");
78     }
79     
80     var transaction = database.transaction("TestObjectStore", "readwrite");
81     var objectStore = transaction.objectStore("TestObjectStore");
82
83     // Queue up some gets to keep the transaction alive long enough for the setTimeout to fire.
84     objectStore.get("foo").onsuccess = function() {
85         objectStore.get("foo");
86     }
87
88     var testWhileInactive = function() {
89         try {
90             objectStore.put("bar", "foo");
91         } catch(e) {
92             alert("Failed to put record into object store with inactive transaction");
93         }
94         
95         try {
96             objectStore.clear();
97         } catch(e) {
98             alert("Failed to clear object store with inactive transaction");
99         } 
100     }
101     
102     setTimeout(testWhileInactive, 0);
103     
104     transaction.onabort = function(event) {
105         alert("readwrite transaction unexpected abort" + event);
106         done();
107     }
108
109     transaction.oncomplete = function(event) {
110         alert("readwrite transaction complete");
111         done();
112     }
113
114     transaction.onerror = function(event) {
115         alert("readwrite transaction unexpected error" + event);
116         done();
117     }
118 }
119
120 </script>