Modern IDB: Remove unneeded "Alert: " string from storage/indexeddb/modern tests.
[WebKit-https.git] / LayoutTests / storage / indexeddb / modern / resources / idbobjectstore-put-and-clear-failures.js
1 description("This tests some obvious failures that can happen while calling IDBObjectStore.put() and IDBObjectStore.clear().");
2
3 if (window.testRunner) {
4     testRunner.waitUntilDone();
5     testRunner.dumpAsText();
6 }
7
8 function done()
9 {
10     finishJSTest();
11 }
12
13 var createRequest = window.indexedDB.open("IDBObjectStorePutAndClearFailuresDatabase", 1);
14 var database;
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     database = event.target.result;
21     var objectStore = database.createObjectStore("TestObjectStore");
22     var request = objectStore.put("bar", "foo");
23
24     request.onsuccess = function() {
25         try {
26             objectStore.put("bar", NaN);
27         } catch(e) {
28             debug("Failed to put record into object store with an invalid key");
29         }
30         
31         database.deleteObjectStore("TestObjectStore");
32         
33         try {
34             objectStore.put("bar", "foo");
35         } catch(e) {
36             debug("Failed to put record into object store that has been deleted");
37         } 
38
39         try {
40             objectStore.clear();
41         } catch(e) {
42             debug("Failed to clear object store that has been deleted");
43         } 
44
45         // Recreate the objectstore because we'll need it in phase 2.
46         var objectStore = database.createObjectStore("TestObjectStore");
47         objectStore.put("bar", "foo");    
48     }
49     
50     versionTransaction.onabort = function(event) {
51         debug("Initial upgrade versionchange transaction unexpected aborted");
52         done();
53     }
54
55     versionTransaction.oncomplete = function(event) {
56         debug("Initial upgrade versionchange transaction complete");
57         continueTest1();
58     }
59
60     versionTransaction.onerror = function(event) {
61         debug("Initial upgrade versionchange transaction unexpected error" + event);
62         done();
63     }
64 }
65
66 function continueTest1()
67 {
68     var transaction = database.transaction("TestObjectStore", "readonly");
69     var objectStore = transaction.objectStore("TestObjectStore");
70     
71     try {
72         objectStore.clear();
73     } catch(e) {
74         debug("Failed to clear object store in read-only transaction");
75     }
76     
77     var transaction = database.transaction("TestObjectStore", "readwrite");
78     var objectStore = transaction.objectStore("TestObjectStore");
79
80     // Spin the transaction with get requests to keep it alive long enough for the setTimeout to fire.
81     var canFinish = false;
82     var spinGet = function() { 
83         objectStore.get("foo").onsuccess = function() {
84             if (!canFinish)
85                 spinGet();
86         }
87     }
88     spinGet();
89
90     var testWhileInactive = function() {
91         try {
92             objectStore.put("bar", "foo");
93         } catch(e) {
94             debug("Failed to put record into object store with inactive transaction");
95         }
96         
97         try {
98             objectStore.clear();
99         } catch(e) {
100             debug("Failed to clear object store with inactive transaction");
101         }
102         
103         canFinish = true;
104     }
105     
106     setTimeout(testWhileInactive, 0);
107     
108     transaction.onabort = function(event) {
109         debug("readwrite transaction unexpected abort" + event);
110         done();
111     }
112
113     transaction.oncomplete = function(event) {
114         debug("readwrite transaction complete");
115         done();
116     }
117
118     transaction.onerror = function(event) {
119         debug("readwrite transaction unexpected error" + event);
120         done();
121     }
122 }
123
124