Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / transaction-after-close.js
blob30f0c0cc73641cceb7810ccb8412eeaafa1f3bfd
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Test closing a database connection in IndexedDB.");
8 indexedDBTest(prepareDatabase, runFirstRegularTransaction);
9 function prepareDatabase()
11     db = event.target.result;
12     store = evalAndLog("store = db.createObjectStore('store')");
13     request = evalAndLog("request = store.put('x', 'y')");
14     request.onsuccess = onPutSuccess;
15     request.onerror = unexpectedErrorCallback;
18 function onPutSuccess()
20     testPassed("Put success")
23 function runFirstRegularTransaction()
25     debug("running first transaction")
26     currentTransaction = evalAndLog("currentTransaction = db.transaction(['store'], 'readwrite')");
27     currentTransaction.onabort = unexpectedAbortCallback;
28     currentTransaction.oncomplete = firstTransactionComplete;
29     objectStore = currentTransaction.objectStore('store');
30     request = evalAndLog("objectStore.put('a', 'b')");
31     request.onerror = unexpectedErrorCallback;
34 function firstTransactionComplete()
36     evalAndLog("db.close()");
37     evalAndExpectException("db.transaction(['store'], 'readwrite')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
39     debug("")
40     debug("verify that we can reopen the db after calling close")
41     request = evalAndLog("indexedDB.open(dbname)");
42     request.onsuccess = onSecondOpen
43     request.onerror = unexpectedErrorCallback;
46 function onSecondOpen() {
47     second_db = evalAndLog("second_db = event.target.result");
48     currentTransaction = evalAndLog("currentTransaction = second_db.transaction(['store'], 'readwrite')");
49     store = currentTransaction.objectStore('store');
50     request = evalAndLog("request = store.put('1', '2')");
51     request.onsuccess = onFinalPutSuccess;
52     request.onerror = unexpectedErrorCallback;
53     currentTransaction.oncomplete = finishJSTest;
54     currentTransaction.onabort = unexpectedAbortCallback;
57 function onFinalPutSuccess() {
58     testPassed("final put success");