1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test event propogation on IDBRequest.");
8 indexedDBTest(prepareDatabase, startTest);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
14 store = evalAndLog("store = db.createObjectStore('storeName', null)");
15 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
16 request.onerror = unexpectedErrorCallback;
21 debug("Verify that handler fires and that not preventing default will result in an abort");
22 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
23 evalAndLog("trans.onabort = transactionAborted");
24 evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
25 evalAndLog("trans.onerror = allowDefault");
26 store = evalAndLog("store = trans.objectStore('storeName')");
27 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
28 request.onsuccess = unexpectedSuccessCallback;
32 function allowDefault()
34 testPassed("Event handler fired");
35 debug("Doing nothing to prevent the default action...");
39 function transactionAborted()
41 shouldBeTrue("handlerFired");
43 debug("Verifing error");
44 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
45 evalAndLog("trans.onabort = transactionAborted2");
46 evalAndLog("trans.oncomplete = unexpectedAbortCallback");
47 evalAndLog("trans.addEventListener('error', errorCaptureCallback, true)");
48 evalAndLog("trans.addEventListener('error', errorBubbleCallback, false)");
49 evalAndLog("trans.addEventListener('success', unexpectedSuccessCallback, true)");
50 evalAndLog("trans.addEventListener('success', unexpectedSuccessCallback, false)");
51 evalAndLog("db.addEventListener('error', dbErrorCaptureCallback, true)");
52 evalAndLog("db.addEventListener('error', dbErrorBubbleCallback, false)");
53 evalAndLog("db.addEventListener('success', unexpectedSuccessCallback, true)");
54 evalAndLog("db.addEventListener('success', unexpectedSuccessCallback, false)");
55 store = evalAndLog("store = trans.objectStore('storeName')");
56 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
57 request.onsuccess = unexpectedSuccessCallback;
58 request.onerror = errorFiredCallback;
59 dbCaptureFired = false;
63 dbBubbleFired = false;
66 function dbErrorCaptureCallback()
69 debug("In IDBDatabase error capture");
70 shouldBeFalse("dbCaptureFired");
71 shouldBeFalse("captureFired");
72 shouldBeFalse("requestFired");
73 shouldBeFalse("bubbleFired");
74 shouldBeFalse("dbBubbleFired");
75 shouldBe("event.target", "request");
76 shouldBe("event.currentTarget", "db");
77 dbCaptureFired = true;
80 function errorCaptureCallback()
83 debug("In IDBTransaction error capture");
84 shouldBeTrue("dbCaptureFired");
85 shouldBeFalse("captureFired");
86 shouldBeFalse("requestFired");
87 shouldBeFalse("bubbleFired");
88 shouldBeFalse("dbBubbleFired");
89 shouldBe("event.target", "request");
90 shouldBe("event.currentTarget", "trans");
94 function errorFiredCallback()
97 debug("In IDBRequest handler");
98 shouldBeTrue("dbCaptureFired");
99 shouldBeTrue("captureFired");
100 shouldBeFalse("requestFired");
101 shouldBeFalse("bubbleFired");
102 shouldBeFalse("dbBubbleFired");
103 shouldBe("event.target", "request");
104 shouldBe("event.currentTarget", "request");
108 function errorBubbleCallback()
111 debug("In IDBTransaction error bubble");
112 shouldBeTrue("dbCaptureFired");
113 shouldBeTrue("captureFired");
114 shouldBeTrue("requestFired");
115 shouldBeFalse("bubbleFired");
116 shouldBeFalse("dbBubbleFired");
117 shouldBe("event.target", "request");
118 shouldBe("event.currentTarget", "trans");
122 function dbErrorBubbleCallback()
125 debug("In IDBDatabase error bubble");
126 shouldBeTrue("dbCaptureFired");
127 shouldBeTrue("captureFired");
128 shouldBeTrue("requestFired");
129 shouldBeTrue("bubbleFired");
130 shouldBeFalse("dbBubbleFired");
131 shouldBe("event.target", "request");
132 shouldBe("event.currentTarget", "db");
133 dbBubbleFired = true;
136 function transactionAborted2()
139 debug("Transaction aborted");
140 shouldBeTrue("dbCaptureFired");
141 shouldBeTrue("captureFired");
142 shouldBeTrue("requestFired");
143 shouldBeTrue("bubbleFired");
144 shouldBeTrue("dbBubbleFired");
146 debug("Verifing success.");
147 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
148 evalAndLog("trans.oncomplete = transactionComplete");
149 evalAndLog("trans.onabort = unexpectedAbortCallback");
150 evalAndLog("trans.addEventListener('success', successCaptureCallback, true)");
151 evalAndLog("trans.addEventListener('success', successBubbleCallback, false)");
152 evalAndLog("trans.addEventListener('error', unexpectedErrorCallback, true)");
153 evalAndLog("trans.addEventListener('error', unexpectedErrorCallback, false)");
154 evalAndLog("db.removeEventListener('error', dbErrorCaptureCallback, true)");
155 evalAndLog("db.removeEventListener('error', dbErrorBubbleCallback, false)");
156 evalAndLog("db.removeEventListener('success', unexpectedSuccessCallback, true)");
157 evalAndLog("db.removeEventListener('success', unexpectedSuccessCallback, false)");
158 evalAndLog("db.addEventListener('success', dbSuccessCaptureCallback, true)");
159 evalAndLog("db.addEventListener('success', dbSuccessBubbleCallback, false)");
160 evalAndLog("db.addEventListener('error', unexpectedErrorCallback, true)");
161 evalAndLog("db.addEventListener('error', unexpectedErrorCallback, false)");
162 store = evalAndLog("store = trans.objectStore('storeName')");
163 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key2')");
164 request.onerror = unexpectedErrorCallback;
165 request.onsuccess = successFiredCallback;
166 dbCaptureFired = false;
167 captureFired = false;
168 requestFired = false;
170 dbBubbleFired = false;
173 function dbSuccessCaptureCallback()
176 debug("In IDBDatabase success capture");
177 shouldBeFalse("dbCaptureFired");
178 shouldBeFalse("captureFired");
179 shouldBeFalse("requestFired");
180 shouldBeFalse("bubbleFired");
181 shouldBeFalse("dbBubbleFired");
182 shouldBe("event.target", "request");
183 shouldBe("event.currentTarget", "db");
184 dbCaptureFired = true;
187 function successCaptureCallback()
190 debug("In IDBTransaction success capture");
191 shouldBeTrue("dbCaptureFired");
192 shouldBeFalse("captureFired");
193 shouldBeFalse("requestFired");
194 shouldBeFalse("bubbleFired");
195 shouldBeFalse("dbBubbleFired");
196 shouldBe("event.target", "request");
197 shouldBe("event.currentTarget", "trans");
201 function successFiredCallback()
204 debug("In IDBRequest handler");
205 shouldBeTrue("dbCaptureFired");
206 shouldBeTrue("captureFired");
207 shouldBeFalse("requestFired");
208 shouldBeFalse("bubbleFired");
209 shouldBeFalse("dbBubbleFired");
210 shouldBe("event.target", "request");
211 shouldBe("event.currentTarget", "request");
215 function successBubbleCallback()
218 debug("In IDBTransaction success bubble");
219 testFailed("Success bubble callback should NOT fire");
223 function dbSuccessBubbleCallback()
226 debug("In IDBDatabase success bubble");
227 testFailed("Success bubble callback should NOT fire");
228 dbBubbleFired = true;
231 function transactionComplete()
234 debug("Transaction completed");
235 shouldBeTrue("dbCaptureFired");
236 shouldBeTrue("captureFired");
237 shouldBeTrue("requestFired");
238 shouldBeFalse("bubbleFired");
239 shouldBeFalse("dbBubbleFired");