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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/satchel/test/unit/test_db_update_v999a.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,75 @@
     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_v999a.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 +  testfile.copyTo(profileDir, "formhistory.sqlite");
    1.46 +  do_check_eq(999, getDBVersion(testfile));
    1.47 +
    1.48 +  let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
    1.49 +  let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
    1.50 +
    1.51 +  // ===== 1 =====
    1.52 +  testnum++;
    1.53 +  // Check for expected contents.
    1.54 +  yield countEntries(null, null, function(num) { do_check_true(num > 0); next_test(); });
    1.55 +  yield countEntries("name-A", "value-A", checkOne);
    1.56 +  yield countEntries("name-B", "value-B", checkOne);
    1.57 +  yield countEntries("name-C", "value-C1", checkOne);
    1.58 +  yield countEntries("name-C", "value-C2", checkOne);
    1.59 +  yield countEntries("name-E", "value-E", checkOne);
    1.60 +
    1.61 +  // check for downgraded schema.
    1.62 +  do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
    1.63 +
    1.64 +  // ===== 2 =====
    1.65 +  testnum++;
    1.66 +  // Exercise adding and removing a name/value pair
    1.67 +  yield countEntries("name-D", "value-D", checkZero);
    1.68 +  yield updateEntry("add", "name-D", "value-D", next_test);
    1.69 +  yield countEntries("name-D", "value-D", checkOne);
    1.70 +  yield updateEntry("remove", "name-D", "value-D", next_test);
    1.71 +  yield countEntries("name-D", "value-D", checkZero);
    1.72 +
    1.73 +  } catch (e) {
    1.74 +    throw "FAILED in test #" + testnum + " -- " + e;
    1.75 +  }
    1.76 +
    1.77 +  do_test_finished();
    1.78 +}

mercurial