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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /*
michael@0 6 * This test uses a formhistory.sqlite with schema version set to 999 (a
michael@0 7 * future version). This exercies the code that allows using a future schema
michael@0 8 * version as long as the expected columns are present.
michael@0 9 *
michael@0 10 * Part A tests this when the columns do match, so the DB is used.
michael@0 11 * Part B tests this when the columns do *not* match, so the DB is reset.
michael@0 12 */
michael@0 13
michael@0 14 let iter = tests();
michael@0 15
michael@0 16 function run_test()
michael@0 17 {
michael@0 18 do_test_pending();
michael@0 19 iter.next();
michael@0 20 }
michael@0 21
michael@0 22 function next_test()
michael@0 23 {
michael@0 24 iter.next();
michael@0 25 }
michael@0 26
michael@0 27 function tests()
michael@0 28 {
michael@0 29 try {
michael@0 30 var testnum = 0;
michael@0 31
michael@0 32 // ===== test init =====
michael@0 33 var testfile = do_get_file("formhistory_v999a.sqlite");
michael@0 34 var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
michael@0 35
michael@0 36 // Cleanup from any previous tests or failures.
michael@0 37 var destFile = profileDir.clone();
michael@0 38 destFile.append("formhistory.sqlite");
michael@0 39 if (destFile.exists())
michael@0 40 destFile.remove(false);
michael@0 41
michael@0 42 testfile.copyTo(profileDir, "formhistory.sqlite");
michael@0 43 do_check_eq(999, getDBVersion(testfile));
michael@0 44
michael@0 45 let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
michael@0 46 let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
michael@0 47
michael@0 48 // ===== 1 =====
michael@0 49 testnum++;
michael@0 50 // Check for expected contents.
michael@0 51 yield countEntries(null, null, function(num) { do_check_true(num > 0); next_test(); });
michael@0 52 yield countEntries("name-A", "value-A", checkOne);
michael@0 53 yield countEntries("name-B", "value-B", checkOne);
michael@0 54 yield countEntries("name-C", "value-C1", checkOne);
michael@0 55 yield countEntries("name-C", "value-C2", checkOne);
michael@0 56 yield countEntries("name-E", "value-E", checkOne);
michael@0 57
michael@0 58 // check for downgraded schema.
michael@0 59 do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
michael@0 60
michael@0 61 // ===== 2 =====
michael@0 62 testnum++;
michael@0 63 // Exercise adding and removing a name/value pair
michael@0 64 yield countEntries("name-D", "value-D", checkZero);
michael@0 65 yield updateEntry("add", "name-D", "value-D", next_test);
michael@0 66 yield countEntries("name-D", "value-D", checkOne);
michael@0 67 yield updateEntry("remove", "name-D", "value-D", next_test);
michael@0 68 yield countEntries("name-D", "value-D", checkZero);
michael@0 69
michael@0 70 } catch (e) {
michael@0 71 throw "FAILED in test #" + testnum + " -- " + e;
michael@0 72 }
michael@0 73
michael@0 74 do_test_finished();
michael@0 75 }

mercurial