1 <html> 2 <head> 3 <script> 4 5 function log(message) 6 { 7 document.body.innerHTML += message + "<br>"; 8 } 9 10 function terminateTest() 11 { 12 if (window.layoutTestController) 13 layoutTestController.notifyDone(); 14 } 15 16 function openTestDatabase() 17 { 18 return openDatabase("ReadAndWriteTransactionsDontRunTogetherTest", 19 "1.0", 20 "Test to make sure that read and write transactions on different DB handles to the same DB don't run at the same time.", 21 32768); 22 } 23 24 var readTransactionsInProgress = 0; 25 var writeTransactionsInProgress = 0; 26 var totalTransactions = 0; 27 var finishedTransactions = 0; 28 29 function runTransaction(db, readOnly) 30 { 31 var transactionFunction = (readOnly ? db.readTransaction : db.transaction); 32 transactionFunction.call(db, function(tx) { 33 if (readOnly) { 34 if (writeTransactionsInProgress != 0) { 35 log("Read transaction starting while write transaction in progress."); 36 terminateTest(); 37 } 38 readTransactionsInProgress++; 39 } else { 40 if ((readTransactionsInProgress != 0) || (writeTransactionsInProgress != 0)) { 41 log("Write transaction starting while another transaction in progress."); 42 terminateTest(); 43 } 44 writeTransactionsInProgress++; 45 } 46 tx.executeSql("SELECT * FROM Test;"); 47 }, function(error) { 48 log((readOnly ? "Read" : "Write") + " transaction failed: " + error.message); 49 terminateTest(); 50 }, function() { 51 finishedTransactions++; 52 if (readOnly) 53 readTransactionsInProgress--; 54 else 55 writeTransactionsInProgress--; 56 log("Transaction successful."); 57 if ((finishedTransactions == totalTransactions) && (readTransactionsInProgress == 0) && (writeTransactionsInProgress == 0)) 58 terminateTest(); 59 }); 60 } 61 62 function runReadAndWriteTransactions(db1, db2, db3) 63 { 64 totalTransactions = 10; 65 finishedTransactions = 0; 66 runTransaction(db1, true); 67 runTransaction(db2, true); 68 runTransaction(db1, false); 69 runTransaction(db1, true); 70 runTransaction(db2, true); 71 runTransaction(db3, true); 72 runTransaction(db1, false); 73 runTransaction(db2, false); 74 runTransaction(db1, true); 75 runTransaction(db3, true); 76 } 77 78 function runTest() { 79 if (window.layoutTestController) { 80 layoutTestController.dumpAsText(); 81 layoutTestController.waitUntilDone(); 82 } 83 84 try { 85 var db1 = openTestDatabase(); 86 var db2 = openTestDatabase(); 87 var db3 = openTestDatabase(); 88 db1.transaction(function(tx) { 89 tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);"); 90 }, function(error) { 91 log("Cannot create the Test table: " + error.message); 92 terminateTest(); 93 }, function() { 94 runReadAndWriteTransactions(db1, db2, db3); 95 }); 96 } catch(err) {} 97 } 98 </script> 99 </head> 100 <body onload="runTest();"> 101 This test tests that read and write transactions on different handles to the same database don't run together.<br> 102 </body> 103 </html> 104