Home | History | Annotate | Download | only in indexeddb
      1 <html>
      2 <head>
      3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
      4 <script src="../../fast/js/resources/js-test-pre.js"></script>
      5 <script src="../../fast/js/resources/js-test-post-function.js"></script>
      6 <script src="resources/shared.js"></script>
      7 </head>
      8 <body>
      9 <p id="description"></p>
     10 <div id="console"></div>
     11 <script>
     12 
     13 description("Test closing a database connection in IndexedDB.");
     14 if (window.layoutTestController)
     15     layoutTestController.waitUntilDone();
     16 
     17 function test()
     18 {
     19     shouldBeTrue("'webkitIndexedDB' in window");
     20     shouldBeFalse("webkitIndexedDB == null");
     21 
     22     request = evalAndLog("webkitIndexedDB.open('transaction-after-close')");
     23     request.onsuccess = openSuccess;
     24     request.onerror = unexpectedErrorCallback;
     25 }
     26 
     27 function openSuccess()
     28 {
     29     debug("openSuccess():");
     30     window.db = evalAndLog("db = event.target.result");
     31     request = evalAndLog("request = db.setVersion('version 1')");
     32     request.onsuccess = inSetVersion;
     33     request.onerror = unexpectedErrorCallback;
     34 }
     35 
     36 function inSetVersion()
     37 {
     38     deleteAllObjectStores(db);
     39 
     40     event.target.result.oncomplete = runFirstRegularTransaction;
     41     event.target.result.onabort = unexpectedAbortCallback;
     42     store = evalAndLog("store = db.createObjectStore('store')");
     43     request = evalAndLog("request = store.put('x', 'y')");
     44     request.onsuccess = onPutSuccess;
     45     request.onerror = unexpectedErrorCallback;
     46 }
     47 
     48 function onPutSuccess()
     49 {
     50     testPassed("Put success")
     51 }
     52 
     53 function runFirstRegularTransaction()
     54 {
     55     debug("running first transaction")
     56     currentTransaction = evalAndLog("currentTransaction = db.transaction([], webkitIDBTransaction.READ_WRITE)");
     57     currentTransaction.onabort = unexpectedAbortCallback;
     58     currentTransaction.oncomplete = firstTransactionComplete;
     59     objectStore = currentTransaction.objectStore('store');
     60     request = evalAndLog("objectStore.put('a', 'b')");
     61     request.onerror = unexpectedErrorCallback;
     62 }
     63 
     64 function firstTransactionComplete()
     65 {
     66     evalAndLog("db.close()");
     67     evalAndExpectException("db.transaction([], webkitIDBTransaction.READ_WRITE)", "webkitIDBDatabaseException.NOT_ALLOWED_ERR");
     68 
     69     debug("")
     70     debug("verify that we can reopen the db after calling close")
     71     request = evalAndLog("webkitIndexedDB.open('transaction-after-close')");
     72     request.onsuccess = onSecondOpen
     73     request.onerror = unexpectedErrorCallback;
     74 }
     75 
     76 function onSecondOpen() {
     77     second_db = evalAndLog("second_db = event.target.result");
     78     currentTransaction = evalAndLog("currentTransaction = second_db.transaction([], webkitIDBTransaction.READ_WRITE)");
     79     store = currentTransaction.objectStore('store');
     80     request = evalAndLog("request = store.put('1', '2')");
     81     request.onsuccess = onFinalPutSuccess;
     82     request.onerror = unexpectedErrorCallback;
     83     currentTransaction.oncomplete = done;
     84     currentTransaction.onabort = unexpectedAbortCallback;
     85 }
     86 
     87 function onFinalPutSuccess() {
     88     testPassed("final put success");
     89 }
     90 
     91 var successfullyParsed = true;
     92 
     93 test();
     94 
     95 </script>
     96 </body>
     97 </html>
     98