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