|
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/. */ |
|
4 |
|
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 */ |
|
13 |
|
14 let iter = tests(); |
|
15 |
|
16 function run_test() |
|
17 { |
|
18 do_test_pending(); |
|
19 iter.next(); |
|
20 } |
|
21 |
|
22 function next_test() |
|
23 { |
|
24 iter.next(); |
|
25 } |
|
26 |
|
27 function tests() |
|
28 { |
|
29 try { |
|
30 var testnum = 0; |
|
31 |
|
32 // ===== test init ===== |
|
33 var testfile = do_get_file("formhistory_v999a.sqlite"); |
|
34 var profileDir = dirSvc.get("ProfD", Ci.nsIFile); |
|
35 |
|
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); |
|
41 |
|
42 testfile.copyTo(profileDir, "formhistory.sqlite"); |
|
43 do_check_eq(999, getDBVersion(testfile)); |
|
44 |
|
45 let checkZero = function(num) { do_check_eq(num, 0); next_test(); } |
|
46 let checkOne = function(num) { do_check_eq(num, 1); next_test(); } |
|
47 |
|
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); |
|
57 |
|
58 // check for downgraded schema. |
|
59 do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion); |
|
60 |
|
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); |
|
69 |
|
70 } catch (e) { |
|
71 throw "FAILED in test #" + testnum + " -- " + e; |
|
72 } |
|
73 |
|
74 do_test_finished(); |
|
75 } |