toolkit/components/satchel/test/unit/test_db_update_v999b.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     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/. */
     5 /*
     6  * This test uses a formhistory.sqlite with schema version set to 999 (a
     7  * future version). This exercies the code that allows using a future schema
     8  * version as long as the expected columns are present.
     9  *
    10  * Part A tests this when the columns do match, so the DB is used.
    11  * Part B tests this when the columns do *not* match, so the DB is reset.
    12  */
    14 let iter = tests();
    16 function run_test()
    17 {
    18   do_test_pending();
    19   iter.next();
    20 }
    22 function next_test()
    23 {
    24   iter.next();
    25 }
    27 function tests()
    28 {
    29   try {
    30   var testnum = 0;
    32   // ===== test init =====
    33   var testfile = do_get_file("formhistory_v999b.sqlite");
    34   var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
    36   // Cleanup from any previous tests or failures.
    37   var destFile = profileDir.clone();
    38   destFile.append("formhistory.sqlite");
    39   if (destFile.exists())
    40     destFile.remove(false);
    42   var bakFile = profileDir.clone();
    43   bakFile.append("formhistory.sqlite.corrupt");
    44   if (bakFile.exists())
    45     bakFile.remove(false);
    47   testfile.copyTo(profileDir, "formhistory.sqlite");
    48   do_check_eq(999, getDBVersion(testfile));
    50   let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
    51   let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
    53   // ===== 1 =====
    54   testnum++;
    56   // Open the DB, ensure that a backup of the corrupt DB is made.
    57   // DB init is done lazily so the DB shouldn't be created yet.
    58   do_check_false(bakFile.exists());
    59   // Doing any request to the DB should create it.
    60   yield countEntries("", "", next_test);
    62   do_check_true(bakFile.exists());
    63   bakFile.remove(false);
    65   // ===== 2 =====
    66   testnum++;
    67   // File should be empty
    68   yield countEntries(null, null, function(num) { do_check_false(num); next_test(); });
    69   yield countEntries("name-A", "value-A", checkZero);
    70   // check for current schema.
    71   do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
    73   // ===== 3 =====
    74   testnum++;
    75   // Try adding an entry
    76   yield updateEntry("add", "name-A", "value-A", next_test);
    77   yield countEntries(null, null, checkOne);
    78   yield countEntries("name-A", "value-A", checkOne);
    80   // ===== 4 =====
    81   testnum++;
    82   // Try removing an entry
    83   yield updateEntry("remove", "name-A", "value-A", next_test);
    84   yield countEntries(null, null, checkZero);
    85   yield countEntries("name-A", "value-A", checkZero);
    87   } catch (e) {
    88     throw "FAILED in test #" + testnum + " -- " + e;
    89   }
    91   do_test_finished();
    92 }

mercurial