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 var complete = 0;
     11 
     12 function checkCompletion()
     13 {
     14     // The test should end after two transactions
     15     if (++complete == 1 && window.layoutTestController)
     16         layoutTestController.notifyDone();
     17 }
     18 
     19 // Opens the database used in this test case
     20 function openTestDatabase()
     21 {
     22     return openDatabase("OpenDatabaseWhileTransactionInProgressTest",
     23                         "1.0",
     24                         "Test to make sure that calling openDatabase() while a transaction is in progress on a different handle to the same database does not result in a deadlock.",
     25                         2100000); // 2MB + epsilon
     26 }
     27 
     28 // See https://bugs.webkit.org/show_bug.cgi?id=28207
     29 // In order to trigger this bug, the transaction must acquire an exclusive
     30 // lock on the DB file before trying to obtain a second handle to the same DB.
     31 // The only way to force SQLite to obtain an exclusive lock is to change more
     32 // than cache_size * page_size bytes in the database. The default value for
     33 // cache_size is 2000 pages, and the default page_size is 1024 bytes. So the
     34 // size of the blob must be at least 2MB.
     35 function runTest()
     36 {
     37     if (window.layoutTestController) {
     38         layoutTestController.dumpAsText();
     39         layoutTestController.waitUntilDone();
     40     }
     41 
     42     try {
     43         var db1 = openTestDatabase();
     44         db1.transaction(function(tx) {
     45             // Create the Test table if it does not exist
     46             tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo BLOB);");
     47             tx.executeSql("INSERT INTO Test VALUES (ZEROBLOB(2097152));", [],
     48                           function(result) {
     49                               var db2 = openTestDatabase();
     50                               log("openDatabase() succeeded.");
     51                           },
     52                           function(tx, error) {
     53                               log("Executing statement failed: " + error.message);
     54                           });
     55 
     56             // Clean up the DB to allow for repeated runs of this test
     57             // without needing to increase the default allowed quota (5MB)
     58             tx.executeSql("DELETE FROM Test;");
     59         }, function(error) {
     60             log("Transaction failed: " + error.message);
     61         }, function() {
     62             checkCompletion();
     63         });
     64     } catch(err) {}
     65 }
     66 </script>
     67 </head>
     68 <body onload="runTest();">
     69 This is a test to see if opening a database while a transaction is running on a different handle to the same database results in a deadlock.<br>
     70 </body>
     71 </html>
     72