1// Opens the database used in this test case
2function openTestDatabase()
3{
4    return openDatabaseWithSuffix("OpenDatabaseWhileTransactionInProgressTest",
5                                  "1.0",
6                                  "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.",
7                                  2100000); // 2MB + epsilon
8}
9
10// See https://bugs.webkit.org/show_bug.cgi?id=28207
11// In order to trigger this bug, the transaction must acquire an exclusive
12// lock on the DB file before trying to obtain a second handle to the same DB.
13// The only way to force SQLite to obtain an exclusive lock is to change more
14// than cache_size * page_size bytes in the database. The default value for
15// cache_size is 2000 pages, and the default page_size is 1024 bytes. So the
16// size of the blob must be at least 2MB.
17function runTest()
18{
19    var db1 = openTestDatabase();
20    db1.transaction(function(tx) {
21        // Create the Test table if it does not exist
22        tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo BLOB);");
23        tx.executeSql("INSERT INTO Test VALUES (ZEROBLOB(2097152));", [],
24                      function(result) {
25                          var db2 = openTestDatabase();
26                          log("openDatabase() succeeded.");
27                      },
28                      function(tx, error) {
29                          log("Executing statement failed: " + error.message);
30                      });
31
32        // Clean up the DB to allow for repeated runs of this test
33        // without needing to increase the default allowed quota (5MB)
34        tx.executeSql("DELETE FROM Test;");
35    }, function(error) {
36        log("Transaction failed: " + error.message);
37    }, function() {
38        if (window.layoutTestController)
39            layoutTestController.notifyDone();
40    });
41}
42