summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/multiple-databases-garbage-collection.js
blob: 9a2b27f47f6a900d84b98d1848d76ef64420d86f (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
function GC()
{
    // Force GC.
    if (window.GCController)
        GCController.collect();
    else {
        for (var i = 0; i < 10000; ++i) {
            ({ });
        }
    }
}

// Variable for the database that will never be forgotten
var persistentDB = 0;
// Variable for the forgotten database
var forgottenDB = 0;

var completed = 0;
function checkCompletion()
{
    if (++completed == 2 && window.layoutTestController)
        layoutTestController.notifyDone();
}

function runTest()
{
    persistentDB = openDatabaseWithSuffix("MultipleDatabasesTest1", "1.0", "Test one out of a set of databases being destroyed (1)", 32768);
    forgottenDB = openDatabaseWithSuffix("MultipleDatabasesTest2", "1.0", "Test one out of a set of databases being destroyed (2)", 32768);

    persistentDB.transaction(function(tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS DataTest (randomData)", [], function(tx, result) { 
            for (var i = 0; i < 25; ++i)
                tx.executeSql("INSERT INTO DataTest (randomData) VALUES (1)", []);
        }); 
    }, function(err) {
        log("Persistent Database Transaction Errored - " + err);
        checkCompletion();
    }, function() {
        log("Persistent Database Transaction Complete");
        checkCompletion();
    });

    forgottenDB.transaction(function(tx) {
        tx.executeSql("CREATE TABLE IF NOT EXISTS EmptyTable (unimportantData)", []);
    }, function(err) {
        log("Forgotten Database Transaction Errored - " + err);
        forgottenDB = 0;
        GC();
        checkCompletion();
    }, function() {
        log("Forgotten Database Transaction Complete");
        forgottenDB = 0;
        GC();
        checkCompletion();
    });
}