• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<title>Test database.changeVersion</title>
4<script>
5var db1;
6var EXPECTED_VERSION_AFTER_HIXIE_TEST = '2';
7var EXPECTED_VERSION_AFTER_RELOAD = '3';
8
9function emptyFunction() { }
10
11function changeVersionCallback(tx)
12{
13    tx.executeSql("DROP table if exists info;", [], emptyFunction, emptyFunction);
14    tx.executeSql("CREATE table if not exists info (version INTEGER);", [], emptyFunction, emptyFunction);
15    tx.executeSql("INSERT into info values(?);", [EXPECTED_VERSION_AFTER_RELOAD], emptyFunction, emptyFunction);
16}
17
18function changeVersionSuccess()
19{
20    log("Successfully changed version to " + db1.version + ". Reloading.");
21    window.location.href = window.location + '?2';
22}
23
24function changeVersionError(error)
25{
26    log("Error: " + error.message);
27    finishTest();
28}
29
30function finishTest()
31{
32    if (window.layoutTestController)
33        layoutTestController.notifyDone();
34    log("TEST COMPLETE");
35}
36
37function log(message)
38{
39    document.getElementById("console").innerText += message + "\n";
40}
41
42function runTest()
43{
44    if (window.location.search == "?2") {
45        db1 = window.openDatabase("changeversion-test", "", "Test for the database.changeVersion() function", 1024);
46        log("Finished tests with version " + db1.version + "; expected version: " + EXPECTED_VERSION_AFTER_RELOAD);
47
48        // Reset the DB version or the next run might fail.
49        db1.changeVersion(db1.version, "1");
50
51        finishTest();
52    } else
53        testPart1();
54}
55
56function testPart1() {
57    if (window.layoutTestController) {
58        layoutTestController.clearAllDatabases();
59        layoutTestController.dumpAsText();
60        layoutTestController.waitUntilDone();
61    }
62
63    db1 = window.openDatabase("changeversion-test", "1", "Test for the database.changeVersion() function", 1024);
64    var db2 = window.openDatabase("changeversion-test", "1", "Test for the database.changeVersion() function", 1024);
65
66    // First run Hixie's test to ensure basic changeVersion functionality works (see bug 28418).
67    db1.changeVersion("1", EXPECTED_VERSION_AFTER_HIXIE_TEST, null, function (e) {
68        log("FAIL in changeVersion:" + e);
69        finishTest();
70    }, function () {
71        // Make sure the version change has propagated to db2 too.
72        // All transactions on db2 should fail.
73        if (db2.version != db1.version) {
74            log("FAIL: changing db1's version (" + db1.version + ") did not change db2's version (" + db2.version + ") as expected.");
75            finishTest();
76        }
77        db2.transaction(function(tx) {
78          tx.executeSql("CREATE TABLE IF NOT EXISTS Test (Foo INT)");
79        }, function(error) { }, function() {
80            log("FAIL: The DB version changed, all transactions on db2 should fail.");
81            finishTest();
82        });
83
84        // Make sure any new handle to the same DB sees the new version
85        try {
86            var db3 = openDatabase("change-version-test", EXPECTED_VERSION_AFTER_HIXIE_TEST, "", 0);
87        } catch (e) {
88            log("FAIL in openDatabase: " + e);
89            finishTest();
90        }
91        if (db1.version != db3.version) {
92            log("FAIL: db.version(" + db1.version + ") does not match db3.version(" + db3.version +")");
93            finishTest();
94        }
95
96        // Now try a test to ensure the version persists after reloading (see bug 27836)
97        db1.changeVersion(EXPECTED_VERSION_AFTER_HIXIE_TEST, EXPECTED_VERSION_AFTER_RELOAD, changeVersionCallback, changeVersionError, changeVersionSuccess);
98    });
99}
100</script>
101</head>
102<body onload="runTest();">
103This test verifies that the JS database.changeVersion() function works as expected.
104<pre id="console"></pre>
105</body>
106</html>
107