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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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_v999b.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 var bakFile = profileDir.clone();
michael@0 43 bakFile.append("formhistory.sqlite.corrupt");
michael@0 44 if (bakFile.exists())
michael@0 45 bakFile.remove(false);
michael@0 46
michael@0 47 testfile.copyTo(profileDir, "formhistory.sqlite");
michael@0 48 do_check_eq(999, getDBVersion(testfile));
michael@0 49
michael@0 50 let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
michael@0 51 let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
michael@0 52
michael@0 53 // ===== 1 =====
michael@0 54 testnum++;
michael@0 55
michael@0 56 // Open the DB, ensure that a backup of the corrupt DB is made.
michael@0 57 // DB init is done lazily so the DB shouldn't be created yet.
michael@0 58 do_check_false(bakFile.exists());
michael@0 59 // Doing any request to the DB should create it.
michael@0 60 yield countEntries("", "", next_test);
michael@0 61
michael@0 62 do_check_true(bakFile.exists());
michael@0 63 bakFile.remove(false);
michael@0 64
michael@0 65 // ===== 2 =====
michael@0 66 testnum++;
michael@0 67 // File should be empty
michael@0 68 yield countEntries(null, null, function(num) { do_check_false(num); next_test(); });
michael@0 69 yield countEntries("name-A", "value-A", checkZero);
michael@0 70 // check for current schema.
michael@0 71 do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
michael@0 72
michael@0 73 // ===== 3 =====
michael@0 74 testnum++;
michael@0 75 // Try adding an entry
michael@0 76 yield updateEntry("add", "name-A", "value-A", next_test);
michael@0 77 yield countEntries(null, null, checkOne);
michael@0 78 yield countEntries("name-A", "value-A", checkOne);
michael@0 79
michael@0 80 // ===== 4 =====
michael@0 81 testnum++;
michael@0 82 // Try removing an entry
michael@0 83 yield updateEntry("remove", "name-A", "value-A", next_test);
michael@0 84 yield countEntries(null, null, checkZero);
michael@0 85 yield countEntries("name-A", "value-A", checkZero);
michael@0 86
michael@0 87 } catch (e) {
michael@0 88 throw "FAILED in test #" + testnum + " -- " + e;
michael@0 89 }
michael@0 90
michael@0 91 do_test_finished();
michael@0 92 }

mercurial