Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / transaction-complete-workers.js
blob48f5731c1209131dce32b02d6bbd86beefcd5665
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)
11     preamble(evt);
12     db = event.target.result;
13     event.target.transaction.onabort = unexpectedAbortCallback;
14     evalAndLog("db.createObjectStore('store')");
17 function createTransaction()
19     debug("");
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'");
32     recursionTest();
35 function recursionTest()
37     debug("");
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");
45     recurse(1);
48 function recurse(count)
50     debug("recursion depth: " + count);
51     evalAndLog("store.get(0)");
52     testPassed("transaction is still active");
53     if (count < 3) {
54         recurse(count + 1);
55     }
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'");
66     debug("");
67     debug("trying a timeout callback:");
68     evalAndLog("setTimeout(timeoutTest, 0)");
71 function timeoutTest()
73     debug("");
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'");
83         errorTest();
84     };
87 function errorTest()
89     debug("");
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)
98     debug("");
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'");
114     finishJSTest();