3 <title>Test database.changeVersion
</title>
6 var EXPECTED_VERSION_AFTER_HIXIE_TEST
= '2';
7 var EXPECTED_VERSION_AFTER_RELOAD
= '3';
9 function emptyFunction() { }
11 function changeVersionCallback(tx
)
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
);
18 function changeVersionSuccess()
20 log("Successfully changed version to " + db1
.version
+ ". Reloading.");
21 window
.location
.href
= window
.location
+ '?2';
24 function changeVersionError(error
)
26 log("Error: " + error
.message
);
32 if (window
.testRunner
)
33 testRunner
.notifyDone();
39 document
.getElementById("console").innerText
+= message
+ "\n";
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
);
48 // Reset the DB version or the next run might fail.
49 db1
.changeVersion(db1
.version
, "1");
56 function testPart1() {
57 if (window
.testRunner
) {
58 testRunner
.clearAllDatabases();
59 testRunner
.dumpAsText();
60 testRunner
.waitUntilDone();
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);
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
);
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.");
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.");
84 // Make sure any new handle to the same DB sees the new version
86 var db3
= openDatabase("change-version-test", EXPECTED_VERSION_AFTER_HIXIE_TEST
, "", 0);
88 log("FAIL in openDatabase: " + e
);
91 if (db1
.version
!= db3
.version
) {
92 log("FAIL: db.version(" + db1
.version
+ ") does not match db3.version(" + db3
.version
+")");
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
);
102 <body onload=
"runTest();">
103 This test verifies that the JS database.changeVersion() function works as expected.
104 <pre id=
"console"></pre>