1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test exceptions in IDBRequest handlers cause aborts.");
8 indexedDBTest(prepareDatabase, startTest);
9 function prepareDatabase()
11 db = event.target.result;
12 event.target.transaction.onabort = unexpectedAbortCallback;
13 store = evalAndLog("store = db.createObjectStore('storeName', null)");
14 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
15 request.onerror = unexpectedErrorCallback;
21 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
22 evalAndLog("trans.onabort = transactionAborted1");
23 evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
24 store = evalAndLog("store = trans.objectStore('storeName')");
25 request = evalAndLog("store.add({x: 'value2', y: 'zzz2'}, 'key2')");
26 trans.addEventListener('success', causeException, true);
27 request.onerror = unexpectedErrorCallback;
30 function causeException()
33 evalAndLog("event.preventDefault()");
36 throw "this exception is expected";
39 function transactionAborted1()
42 shouldHaveHadError("this exception is expected");
43 testPassed("The transaction was aborted.");
44 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
45 evalAndLog("trans.onabort = transactionAborted2");
46 evalAndLog("trans.oncomplete = unexpectedCompleteCallback");
47 store = evalAndLog("store = trans.objectStore('storeName')");
48 request = evalAndLog("store.add({x: 'value', y: 'zzz'}, 'key')");
49 request.onsuccess = unexpectedSuccessCallback;
50 db.onerror = causeException;
53 function transactionAborted2()
56 shouldHaveHadError("this exception is expected");
57 testPassed("The transaction was aborted.");
58 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
59 evalAndLog("trans.onabort = unexpectedAbortCallback");
60 evalAndLog("trans.oncomplete = transactionCompleted1");
61 store = evalAndLog("store = trans.objectStore('storeName')");
62 request = evalAndLog("store.add({x: 'value3', y: 'zzz3'}, 'key3')");
63 request.onsuccess = throwAndCatch;
64 request.onerror = unexpectedErrorCallback;
68 function throwAndCatch()
71 evalAndLog("event.preventDefault()");
72 debug("Throwing within a try block");
79 function transactionCompleted1()
82 testPassed("The transaction completed.");
83 trans = evalAndLog("trans = db.transaction(['storeName'], 'readwrite')");
84 evalAndLog("trans.onabort = unexpectedAbortCallback");
85 evalAndLog("trans.oncomplete = transactionCompleted2");
86 store = evalAndLog("store = trans.objectStore('storeName')");
87 request = evalAndLog("store.add({x: 'value4', y: 'zzz4'}, 'key4')");
88 request.onsuccess = function() { testPassed("key4 added"); }
89 request.onerror = unexpectedErrorCallback;
92 function transactionCompleted2()
95 testPassed("The transaction completed.");