Home | History | Annotate | Download | only in storage
      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("ReadTransactionsRunningConcurrentlyTest",
     19                         "1.0",
     20                         "Test to make sure that multiple read transactions on different DB handles to the same DB run concurrently.",
     21                         32768);
     22 }
     23 
     24 var readTransactionsInProgress = 0;
     25 
     26 function runReadTransaction(db)
     27 {
     28     db.readTransaction(function(tx) {
     29             readTransactionsInProgress++;
     30         }, function(error) {
     31             log("Read transaction failed: " + error.message);
     32             terminateTest();
     33         }, function() {
     34             if (readTransactionsInProgress == 2)
     35                 log("Read transactions running concurrently.");
     36             readTransactionsInProgress--;
     37             if (readTransactionsInProgress == 0)
     38                 terminateTest();
     39         });
     40 }
     41 
     42 function runTest() {
     43     if (window.layoutTestController) {
     44         layoutTestController.dumpAsText();
     45         layoutTestController.waitUntilDone();
     46     }
     47 
     48     try {
     49         var db1 = openTestDatabase();
     50         var db2 = openTestDatabase();
     51         db1.transaction(function(tx) {
     52                 tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);");
     53             }, function(error) {
     54                 log("Cannot create the Test table: " + error.message);
     55                 terminateTest();
     56             }, function() {
     57                 runReadTransaction(db1);
     58                 runReadTransaction(db2);
     59             });
     60      } catch(err) { log(err); }
     61 }
     62 </script>
     63 </head>
     64 <body onload="runTest();">
     65 This test tests that two read-only transactions on different handles to the same database run concurrently.<br>
     66 </body>
     67 </html>
     68