1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/satchel/test/unit/test_db_update_v999b.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,92 @@ 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 +/* 1.9 + * This test uses a formhistory.sqlite with schema version set to 999 (a 1.10 + * future version). This exercies the code that allows using a future schema 1.11 + * version as long as the expected columns are present. 1.12 + * 1.13 + * Part A tests this when the columns do match, so the DB is used. 1.14 + * Part B tests this when the columns do *not* match, so the DB is reset. 1.15 + */ 1.16 + 1.17 +let iter = tests(); 1.18 + 1.19 +function run_test() 1.20 +{ 1.21 + do_test_pending(); 1.22 + iter.next(); 1.23 +} 1.24 + 1.25 +function next_test() 1.26 +{ 1.27 + iter.next(); 1.28 +} 1.29 + 1.30 +function tests() 1.31 +{ 1.32 + try { 1.33 + var testnum = 0; 1.34 + 1.35 + // ===== test init ===== 1.36 + var testfile = do_get_file("formhistory_v999b.sqlite"); 1.37 + var profileDir = dirSvc.get("ProfD", Ci.nsIFile); 1.38 + 1.39 + // Cleanup from any previous tests or failures. 1.40 + var destFile = profileDir.clone(); 1.41 + destFile.append("formhistory.sqlite"); 1.42 + if (destFile.exists()) 1.43 + destFile.remove(false); 1.44 + 1.45 + var bakFile = profileDir.clone(); 1.46 + bakFile.append("formhistory.sqlite.corrupt"); 1.47 + if (bakFile.exists()) 1.48 + bakFile.remove(false); 1.49 + 1.50 + testfile.copyTo(profileDir, "formhistory.sqlite"); 1.51 + do_check_eq(999, getDBVersion(testfile)); 1.52 + 1.53 + let checkZero = function(num) { do_check_eq(num, 0); next_test(); } 1.54 + let checkOne = function(num) { do_check_eq(num, 1); next_test(); } 1.55 + 1.56 + // ===== 1 ===== 1.57 + testnum++; 1.58 + 1.59 + // Open the DB, ensure that a backup of the corrupt DB is made. 1.60 + // DB init is done lazily so the DB shouldn't be created yet. 1.61 + do_check_false(bakFile.exists()); 1.62 + // Doing any request to the DB should create it. 1.63 + yield countEntries("", "", next_test); 1.64 + 1.65 + do_check_true(bakFile.exists()); 1.66 + bakFile.remove(false); 1.67 + 1.68 + // ===== 2 ===== 1.69 + testnum++; 1.70 + // File should be empty 1.71 + yield countEntries(null, null, function(num) { do_check_false(num); next_test(); }); 1.72 + yield countEntries("name-A", "value-A", checkZero); 1.73 + // check for current schema. 1.74 + do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion); 1.75 + 1.76 + // ===== 3 ===== 1.77 + testnum++; 1.78 + // Try adding an entry 1.79 + yield updateEntry("add", "name-A", "value-A", next_test); 1.80 + yield countEntries(null, null, checkOne); 1.81 + yield countEntries("name-A", "value-A", checkOne); 1.82 + 1.83 + // ===== 4 ===== 1.84 + testnum++; 1.85 + // Try removing an entry 1.86 + yield updateEntry("remove", "name-A", "value-A", next_test); 1.87 + yield countEntries(null, null, checkZero); 1.88 + yield countEntries("name-A", "value-A", checkZero); 1.89 + 1.90 + } catch (e) { 1.91 + throw "FAILED in test #" + testnum + " -- " + e; 1.92 + } 1.93 + 1.94 + do_test_finished(); 1.95 +}