• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<script>
4
5function log(message)
6{
7    document.body.innerHTML += message + "<br>";
8}
9
10var complete = 0;
11
12function checkCompletion()
13{
14    // The test should end after two transactions
15    if (++complete == 2 && window.layoutTestController)
16        layoutTestController.notifyDone();
17}
18
19// Opens the database used in this test case
20function openTestDatabase()
21{
22    return openDatabase("MultipleTransactionsOnDifferentHandlesTest",
23                        "1.0",
24                        "Test to make sure that queueing multiple transactions on different DB handles does not result in a deadlock.",
25                        32768);
26}
27
28function statementSuccessCallback(dbName, statementType)
29{
30    log(dbName + " " + statementType + " statement succeeded");
31}
32
33function statementErrorCallback(dbName, statementType, error)
34{
35    log(dbName + " " + statementType + " statement failed: " + error.message);
36}
37
38// Runs a transaction on the given database
39function runTransaction(db, dbName, val)
40{
41    db.transaction(function(tx) {
42       // Execute a read-only statement
43       tx.executeSql("SELECT COUNT(*) FROM Test;", [],
44                     function(result) { statementSuccessCallback(dbName, "read"); },
45                     function(tx, error) { statementErrorCallback(dbName, "read", error); });
46
47       // Execute a write statement to make sure SQLite tries to acquire an exclusive lock on the DB file
48       tx.executeSql("INSERT INTO Test VALUES (?);", [val],
49                     function(result) { statementSuccessCallback(dbName, "write"); },
50                     function(tx, error) { statementErrorCallback(dbName, "write", error); });
51       }, function(error) {
52           // Transaction failure callback
53           log(dbName + " transaction failed: " + error.message);
54           checkCompletion();
55       }, function() {
56           // Transaction success callback
57           log(dbName + " transaction succeeded");
58           checkCompletion();
59       });
60}
61
62// We need to guarantee that the Test table exists before we run our test.
63// Therefore, the test code is in the successCallback of the transaction that creates the table.
64function runTest() {
65    if (window.layoutTestController) {
66        layoutTestController.dumpAsText();
67        layoutTestController.waitUntilDone();
68    }
69
70    try {
71        var db = openTestDatabase();
72        db.transaction(function(tx) {
73            // Create the Test table if it does not exist
74            tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);", [],
75                          function(result) {}, function(tx, error) {});
76            }, function(error) {
77                log("Creating the Test table failed: " + error.message);
78            }, function() {
79                // The Test table was created successfully
80                var db1 = openTestDatabase();
81                var db2 = openTestDatabase();
82                if (db1 == db2)
83                    log("failure: db1 == db2");
84                else {
85                    runTransaction(db1, "db1", 1);
86                    runTransaction(db2, "db2", 2);
87                }
88            });
89    } catch(err) {}
90}
91</script>
92</head>
93<body onload="runTest();">
94This is a test to see if queueing up multiple transactions on different handles to the same database results in a deadlock.<br>
95</body>
96</html>
97