Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_v999a.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 testfile.copyTo(profileDir, "formhistory.sqlite");
43 do_check_eq(999, getDBVersion(testfile));
45 let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
46 let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
48 // ===== 1 =====
49 testnum++;
50 // Check for expected contents.
51 yield countEntries(null, null, function(num) { do_check_true(num > 0); next_test(); });
52 yield countEntries("name-A", "value-A", checkOne);
53 yield countEntries("name-B", "value-B", checkOne);
54 yield countEntries("name-C", "value-C1", checkOne);
55 yield countEntries("name-C", "value-C2", checkOne);
56 yield countEntries("name-E", "value-E", checkOne);
58 // check for downgraded schema.
59 do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
61 // ===== 2 =====
62 testnum++;
63 // Exercise adding and removing a name/value pair
64 yield countEntries("name-D", "value-D", checkZero);
65 yield updateEntry("add", "name-D", "value-D", next_test);
66 yield countEntries("name-D", "value-D", checkOne);
67 yield updateEntry("remove", "name-D", "value-D", next_test);
68 yield countEntries("name-D", "value-D", checkZero);
70 } catch (e) {
71 throw "FAILED in test #" + testnum + " -- " + e;
72 }
74 do_test_finished();
75 }