summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/change-version.html
blob: 79bb9df588b94cddc03b2f79ac9aa4f06646b95a (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<html>
<head>
<title>Test database.changeVersion</title>
<script>
var db1;
var EXPECTED_VERSION_AFTER_HIXIE_TEST = '2';
var EXPECTED_VERSION_AFTER_RELOAD = '3';

function emptyFunction() { }

function changeVersionCallback(tx)
{
    tx.executeSql("DROP table if exists info;", [], emptyFunction, emptyFunction);
    tx.executeSql("CREATE table if not exists info (version INTEGER);", [], emptyFunction, emptyFunction);
    tx.executeSql("INSERT into info values(?);", [EXPECTED_VERSION_AFTER_RELOAD], emptyFunction, emptyFunction);
}

function changeVersionSuccess()
{
    log("Successfully changed version to " + db1.version + ". Reloading.");
    window.location.href = window.location + '?2';
}

function changeVersionError(error)
{
    log("Error: " + error.message);
    finishTest();
}

function finishTest()
{
    if (window.layoutTestController)
        layoutTestController.notifyDone();
    log("TEST COMPLETE");
}

function log(message)
{
    document.getElementById("console").innerText += message + "\n";
}

function runTest()
{
    if (window.location.search == "?2") {
        db1 = window.openDatabase("changeversion-test", "", "Test for the database.changeVersion() function", 1024);
        log("Finished tests with version " + db1.version + "; expected version: " + EXPECTED_VERSION_AFTER_RELOAD);

        // Reset the DB version or the next run might fail.
        db1.changeVersion(db1.version, "1");

        finishTest();
    } else
        testPart1();
}

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

    db1 = window.openDatabase("changeversion-test", "1", "Test for the database.changeVersion() function", 1024);
    var db2 = window.openDatabase("changeversion-test", "1", "Test for the database.changeVersion() function", 1024);

    // First run Hixie's test to ensure basic changeVersion functionality works (see bug 28418).
    db1.changeVersion("1", EXPECTED_VERSION_AFTER_HIXIE_TEST, null, function (e) {
        log("FAIL in changeVersion:" + e);
        finishTest();
    }, function () {
        // Make sure the version change has propagated to db2 too.
        // All transactions on db2 should fail.
        if (db2.version != db1.version) {
            log("FAIL: changing db1's version (" + db1.version + ") did not change db2's version (" + db2.version + ") as expected.");
            finishTest();
        }
        db2.transaction(function(tx) {
          tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
        }, function(error) { }, function() {
            log("FAIL: The DB version changed, all transactions on db2 should fail.");
            finishTest();
        });

        // Make sure any new handle to the same DB sees the new version
        try {
            var db3 = openDatabase("change-version-test", EXPECTED_VERSION_AFTER_HIXIE_TEST, "", 0);
        } catch (e) {
            log("FAIL in openDatabase: " + e);
            finishTest();
        }
        if (db1.version != db3.version) {
            log("FAIL: db.version(" + db1.version + ") does not match db3.version(" + db3.version +")");
            finishTest();
        }

        // Now try a test to ensure the version persists after reloading (see bug 27836)
        db1.changeVersion(EXPECTED_VERSION_AFTER_HIXIE_TEST, EXPECTED_VERSION_AFTER_RELOAD, changeVersionCallback, changeVersionError, changeVersionSuccess);
    });
}
</script>
</head>
<body onload="runTest();">
This test verifies that the JS database.changeVersion() function works as expected.
<pre id="console"></pre>
</body>
</html>