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

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:a96a8e5b3c93
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 // This file tests migration from v1 to v2
6
7 function run_test()
8 {
9 // First import the downloads.sqlite file
10 importDatabaseFile("v1.sqlite");
11
12 // ok, now it is OK to init the download manager - this will perform the
13 // migration!
14 var dm = Cc["@mozilla.org/download-manager;1"].
15 getService(Ci.nsIDownloadManager);
16 var dbConn = dm.DBConnection;
17 var stmt = null;
18
19 // check schema version
20 do_check_true(dbConn.schemaVersion >= 2);
21
22 // Check that the column no longer exists
23 try {
24 // throws when it doesn't exist
25 stmt = dbConn.createStatement("SELECT iconURL FROM moz_downloads");
26 do_throw("should not get here");
27 } catch (e) {
28 do_check_eq(Cr.NS_ERROR_FAILURE, e.result);
29 }
30
31 // now we check the entries
32 stmt = dbConn.createStatement(
33 "SELECT name, source, target, startTime, endTime, state " +
34 "FROM moz_downloads " +
35 "WHERE id = 2");
36 stmt.executeStep();
37 do_check_eq("381603.patch", stmt.getString(0));
38 do_check_eq("https://bugzilla.mozilla.org/attachment.cgi?id=266520",
39 stmt.getUTF8String(1));
40 do_check_eq("file:///Users/sdwilsh/Desktop/381603.patch",
41 stmt.getUTF8String(2));
42 do_check_eq(1180493839859230, stmt.getInt64(3));
43 do_check_eq(1180493839859230, stmt.getInt64(4));
44 do_check_eq(1, stmt.getInt32(5));
45 stmt.finalize();
46
47 cleanup();
48 }
49

mercurial