1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Test IndexedDB workers, recursion, and transaction termination.");
8 indexedDBTest(prepareDatabase, createTransaction);
9 function prepareDatabase(evt)
12 db = event.target.result;
13 event.target.transaction.onabort = unexpectedAbortCallback;
14 evalAndLog("db.createObjectStore('store')");
17 function createTransaction()
20 debug("createTransaction():");
21 evalAndLog("transaction = db.transaction('store')");
22 evalAndLog("store = transaction.objectStore('store')");
23 transaction.onerror = unexpectedErrorCallback;
24 transaction.onabort = unexpectedAbortCallback;
25 transaction.oncomplete = emptyTransactionCompleted;
28 function emptyTransactionCompleted()
30 testPassed("Transaction completed");
31 evalAndExpectException("store.get(0)", "0", "'TransactionInactiveError'");
35 function recursionTest()
38 debug("recursionTest():");
39 evalAndLog("transaction = db.transaction('store')");
40 evalAndLog("store = transaction.objectStore('store')");
41 transaction.oncomplete = transactionCompleted;
42 transaction.onabort = unexpectedAbortCallback;
43 evalAndLog("store.get(0)");
44 testPassed("transaction is active");
48 function recurse(count)
50 debug("recursion depth: " + count);
51 evalAndLog("store.get(0)");
52 testPassed("transaction is still active");
56 debug("recursion depth: " + count);
57 evalAndLog("store.get(0)");
58 testPassed("transaction is still active");
61 function transactionCompleted()
63 testPassed("transaction completed");
64 evalAndExpectException("store.get(0)", "0", "'TransactionInactiveError'");
67 debug("trying a timeout callback:");
68 evalAndLog("setTimeout(timeoutTest, 0)");
71 function timeoutTest()
74 debug("timeoutTest():");
76 evalAndLog("transaction = db.transaction('store')");
77 evalAndLog("store = transaction.objectStore('store')");
78 transaction.onabort = unexpectedAbortCallback;
79 transaction.oncomplete = function () {
80 testPassed("transaction started in setTimeout() callback completed");
81 evalAndExpectException("store.get(0)", "0", "'TransactionInactiveError'");
90 debug("errorTest():");
91 evalAndLog("self.old_onerror = self.onerror");
92 evalAndLog("self.onerror = errorHandler");
93 throw new Error("ignore this");
96 function errorHandler(e)
99 debug("errorHandler():");
100 // FIXME: Should be able to stop the error here, but it isn't an Event object.
101 // evalAndLog("event.preventDefault()");
102 evalAndLog("self.onerror = self.old_onerror");
103 evalAndLog("transaction = db.transaction('store')");
104 evalAndLog("store = transaction.objectStore('store')");
105 transaction.onerror = unexpectedErrorCallback;
106 transaction.onabort = unexpectedAbortCallback;
107 transaction.oncomplete = errorTransactionCompleted;
110 function errorTransactionCompleted()
112 testPassed("Transaction completed");
113 evalAndExpectException("store.get(0)", "0", "'TransactionInactiveError'");