summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/read-transactions-running-concurrently.html
blob: b2d862c1e6ce824f408858584b958719b95cc0bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<html>
<head>
<script>

function log(message)
{
    document.body.innerHTML += message + "<br>";
}

function terminateTest()
{
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

function openTestDatabase()
{
    return openDatabase("ReadTransactionsRunningConcurrentlyTest",
                        "1.0",
                        "Test to make sure that multiple read transactions on different DB handles to the same DB run concurrently.",
                        32768);
}

var readTransactionsInProgress = 0;

function runReadTransaction(db)
{
    db.readTransaction(function(tx) {
            readTransactionsInProgress++;
        }, function(error) {
            log("Read transaction failed: " + error.message);
            terminateTest();
        }, function() {
            if (readTransactionsInProgress == 2)
                log("Read transactions running concurrently.");
            readTransactionsInProgress--;
            if (readTransactionsInProgress == 0)
                terminateTest();
        });
}

function runTest() {
    if (window.layoutTestController) {
        layoutTestController.dumpAsText();
        layoutTestController.waitUntilDone();
    }

    try {
        var db1 = openTestDatabase();
        var db2 = openTestDatabase();
        db1.transaction(function(tx) {
                tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo int);");
            }, function(error) {
                log("Cannot create the Test table: " + error.message);
                terminateTest();
            }, function() {
                runReadTransaction(db1);
                runReadTransaction(db2);
            });
     } catch(err) { log(err); }
}
</script>
</head>
<body onload="runTest();">
This test tests that two read-only transactions on different handles to the same database run concurrently.<br>
</body>
</html>