summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/change-version.html
blob: d81c6b564f3c2790abec5e5954020f584b0cc39b (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
<html> 
<head>
<title>Test database.changeVersion</title>
<script> 
var db;
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 ' + db.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") {
        db = window.openDatabase("changeversion-test", "", "Test for the database.changeVersion() function", 1024);
        log("Finished tests with version " + db.version + "; expected version: " + EXPECTED_VERSION_AFTER_RELOAD);
        finishTest();
    } else
        testPart1();
}

function testPart1() {
    if (window.layoutTestController) {
        layoutTestController.clearAllDatabases();
        layoutTestController.dumpAsText();
        layoutTestController.waitUntilDone();
    }
    
    db = window.openDatabase("changeversion-test", "", "Test for the database.changeVersion() function", 1024);

    if (db.version != EXPECTED_VERSION_AFTER_RELOAD) {
        // First run Hixie's test to ensure basic changeVersion functionality works (see bug 28418).
        db.changeVersion("", EXPECTED_VERSION_AFTER_HIXIE_TEST, emptyFunction, function (e) {
            log('FAIL in changeVersion:' + e);
            finishTest();
        }, function () {
            try {
                var db2 = openDatabase("change-version-test", EXPECTED_VERSION_AFTER_HIXIE_TEST, "", 0);
            } catch (e) {
                log('FAIL in openDatabase: ' + e);
                finishTest();
            }
            // The two database versions should match.
            if (db.version == db2.version)
                log("PASS: db.version(" + db.version + ") matches db2.version(" + db2.version +") as expected.");
            else
                log("FAIL: db.version(" + db.version + ") does not match db2.version(" + db2.version +")");

            // Now try a test to ensure the version persists after reloading (see bug 27836)
            db.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>