michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function run_test() michael@0: { michael@0: // We're testing migration to this version from one version below michael@0: var targetVersion = 7; michael@0: michael@0: // First import the downloads.sqlite file michael@0: importDatabaseFile("v" + (targetVersion - 1) + ".sqlite"); michael@0: michael@0: // Init the download manager which will try migrating to the new version michael@0: var dm = Cc["@mozilla.org/download-manager;1"]. michael@0: getService(Ci.nsIDownloadManager); michael@0: var dbConn = dm.DBConnection; michael@0: michael@0: // Check schema version michael@0: do_check_true(dbConn.schemaVersion >= targetVersion); michael@0: michael@0: // Make sure all the columns are there michael@0: var stmt = dbConn.createStatement( michael@0: "SELECT name, source, target, tempPath, startTime, endTime, state, " + michael@0: "referrer, entityID, currBytes, maxBytes, mimeType, " + michael@0: "preferredApplication, preferredAction " + michael@0: "FROM moz_downloads " + michael@0: "WHERE id = 28"); michael@0: stmt.executeStep(); michael@0: michael@0: // This data is based on the original values in the table michael@0: var data = [ michael@0: "firefox-3.0a9pre.en-US.linux-i686.tar.bz2", michael@0: "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/firefox-3.0a9pre.en-US.linux-i686.tar.bz2", michael@0: "file:///Users/Ed/Desktop/firefox-3.0a9pre.en-US.linux-i686.tar.bz2", michael@0: "/Users/Ed/Desktop/+EZWafFQ.bz2.part", michael@0: 1192469856209164, michael@0: 1192469877017396, michael@0: Ci.nsIDownloadManager.DOWNLOAD_FINISHED, michael@0: "http://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/latest-trunk/", michael@0: "%2210e66c1-8a2d6b-9b33f380%22/9055595/Mon, 15 Oct 2007 11:45:34 GMT", michael@0: 1210772, michael@0: 9055595, michael@0: // For the new columns added, check for null or default values michael@0: true, michael@0: true, michael@0: 0, michael@0: ]; michael@0: michael@0: // Make sure the values are correct after the migration michael@0: var i = 0; michael@0: do_check_eq(data[i], stmt.getString(i++)); michael@0: do_check_eq(data[i], stmt.getUTF8String(i++)); michael@0: do_check_eq(data[i], stmt.getUTF8String(i++)); michael@0: do_check_eq(data[i], stmt.getString(i++)); michael@0: do_check_eq(data[i], stmt.getInt64(i++)); michael@0: do_check_eq(data[i], stmt.getInt64(i++)); michael@0: do_check_eq(data[i], stmt.getInt32(i++)); michael@0: do_check_eq(data[i], stmt.getUTF8String(i++)); michael@0: do_check_eq(data[i], stmt.getUTF8String(i++)); michael@0: do_check_eq(data[i], stmt.getInt64(i++)); michael@0: do_check_eq(data[i], stmt.getInt64(i++)); michael@0: do_check_eq(data[i], stmt.getIsNull(i++)); michael@0: do_check_eq(data[i], stmt.getIsNull(i++)); michael@0: do_check_eq(data[i], stmt.getInt32(i++)); michael@0: michael@0: stmt.reset(); michael@0: stmt.finalize(); michael@0: michael@0: cleanup(); michael@0: }