toolkit/components/downloads/test/schema_migration/test_migration_to_3.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/downloads/test/schema_migration/test_migration_to_3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,45 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +// This file tests migration from v1 to v2
     1.9 +
    1.10 +function run_test()
    1.11 +{
    1.12 +  // First import the downloads.sqlite file
    1.13 +  importDatabaseFile("v2.sqlite");
    1.14 +
    1.15 +  // ok, now it is OK to init the download manager - this will perform the
    1.16 +  // migration!
    1.17 +  var dm = Cc["@mozilla.org/download-manager;1"].
    1.18 +           getService(Ci.nsIDownloadManager);
    1.19 +  var dbConn = dm.DBConnection;
    1.20 +  var stmt = null;
    1.21 +
    1.22 +  // check schema version
    1.23 +  do_check_true(dbConn.schemaVersion >= 3);
    1.24 +
    1.25 +  // Check that the column exists (statement should not throw)
    1.26 +  stmt = dbConn.createStatement("SELECT referrer FROM moz_downloads");
    1.27 +  stmt.finalize();
    1.28 +
    1.29 +  // now we check the entries
    1.30 +  stmt = dbConn.createStatement(
    1.31 +    "SELECT name, source, target, startTime, endTime, state, referrer " +
    1.32 +    "FROM moz_downloads " +
    1.33 +    "WHERE id = 2");
    1.34 +  stmt.executeStep();
    1.35 +  do_check_eq("381603.patch", stmt.getString(0));
    1.36 +  do_check_eq("https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    1.37 +              stmt.getUTF8String(1));
    1.38 +  do_check_eq("file:///Users/sdwilsh/Desktop/381603.patch",
    1.39 +              stmt.getUTF8String(2));
    1.40 +  do_check_eq(1180493839859230, stmt.getInt64(3));
    1.41 +  do_check_eq(1180493839859230, stmt.getInt64(4));
    1.42 +  do_check_eq(1, stmt.getInt32(5));
    1.43 +  do_check_true(stmt.getIsNull(6));
    1.44 +  stmt.finalize();
    1.45 +
    1.46 +  cleanup();
    1.47 +}
    1.48 +

mercurial