Home | History | Annotate | Download | only in storage
      1 <html> 
      2 <head>
      3 <title>Test database.changeVersion</title>
      4 <script> 
      5 var db;
      6 var EXPECTED_VERSION_AFTER_HIXIE_TEST = '2';
      7 var EXPECTED_VERSION_AFTER_RELOAD = '3';
      8  
      9 function emptyFunction() { }
     10  
     11 function 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  
     18 function changeVersionSuccess()
     19 {
     20     log("Successfully changed version to ' + db.version + '. Reloading.");
     21     window.location.href = window.location + '?2';
     22 }
     23  
     24 function changeVersionError(error)
     25 {
     26     log("Error: " + error.message);
     27     finishTest();
     28 }
     29 
     30 function finishTest()
     31 {
     32     if (window.layoutTestController)
     33         layoutTestController.notifyDone();
     34     log("TEST COMPLETE");
     35 }
     36 
     37 function log(message)
     38 {
     39     document.getElementById("console").innerText += message + "\n";
     40 }
     41 
     42 function runTest()
     43 {
     44     if (window.location.search == "?2") {
     45         db = window.openDatabase("changeversion-test", "", "Test for the database.changeVersion() function", 1024);
     46         log("Finished tests with version " + db.version + "; expected version: " + EXPECTED_VERSION_AFTER_RELOAD);
     47         finishTest();
     48     } else
     49         testPart1();
     50 }
     51 
     52 function testPart1() {
     53     if (window.layoutTestController) {
     54         layoutTestController.clearAllDatabases();
     55         layoutTestController.dumpAsText();
     56         layoutTestController.waitUntilDone();
     57     }
     58     
     59     db = window.openDatabase("changeversion-test", "", "Test for the database.changeVersion() function", 1024);
     60 
     61     if (db.version != EXPECTED_VERSION_AFTER_RELOAD) {
     62         // First run Hixie's test to ensure basic changeVersion functionality works (see bug 28418).
     63         db.changeVersion("", EXPECTED_VERSION_AFTER_HIXIE_TEST, emptyFunction, function (e) {
     64             log('FAIL in changeVersion:' + e);
     65             finishTest();
     66         }, function () {
     67             try {
     68                 var db2 = openDatabase("change-version-test", EXPECTED_VERSION_AFTER_HIXIE_TEST, "", 0);
     69             } catch (e) {
     70                 log('FAIL in openDatabase: ' + e);
     71                 finishTest();
     72             }
     73             // The two database versions should match.
     74             if (db.version == db2.version)
     75                 log("PASS: db.version(" + db.version + ") matches db2.version(" + db2.version +") as expected.");
     76             else
     77                 log("FAIL: db.version(" + db.version + ") does not match db2.version(" + db2.version +")");
     78 
     79             // Now try a test to ensure the version persists after reloading (see bug 27836)
     80             db.changeVersion(EXPECTED_VERSION_AFTER_HIXIE_TEST, EXPECTED_VERSION_AFTER_RELOAD, changeVersionCallback, changeVersionError, changeVersionSuccess);
     81         });
     82     }
     83 }
     84 </script>
     85 </head>
     86 <body onload="runTest();">
     87 This test verifies that the JS database.changeVersion() function works as expected.
     88 <pre id="console"></pre>
     89 </body>
     90 </html>
     91