|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Test startup and restart when no add-ons are installed |
|
6 // bug 944006 |
|
7 |
|
8 Components.utils.import("resource://gre/modules/Promise.jsm"); |
|
9 |
|
10 // Load XPI Provider to get schema version ID |
|
11 let XPIScope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm"); |
|
12 const DB_SCHEMA = XPIScope.DB_SCHEMA; |
|
13 |
|
14 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
15 |
|
16 function run_test() { |
|
17 // Kick off the task-based tests... |
|
18 run_next_test(); |
|
19 } |
|
20 |
|
21 // Test for a preference to either exist with a specified value, or not exist at all |
|
22 function checkPending() { |
|
23 try { |
|
24 do_check_false(Services.prefs.getBoolPref("extensions.pendingOperations")); |
|
25 } |
|
26 catch (e) { |
|
27 // OK |
|
28 } |
|
29 } |
|
30 |
|
31 function checkString(aPref, aValue) { |
|
32 try { |
|
33 do_check_eq(Services.prefs.getCharPref(aPref), aValue) |
|
34 } |
|
35 catch (e) { |
|
36 //OK |
|
37 } |
|
38 } |
|
39 |
|
40 // Make sure all our extension state is empty/nonexistent |
|
41 function check_empty_state() { |
|
42 do_check_false(gExtensionsJSON.exists()); |
|
43 do_check_false(gExtensionsINI.exists()); |
|
44 |
|
45 do_check_eq(Services.prefs.getIntPref("extensions.databaseSchema"), DB_SCHEMA); |
|
46 |
|
47 checkString("extensions.bootstrappedAddons", "{}"); |
|
48 checkString("extensions.installCache", "[]"); |
|
49 checkPending(); |
|
50 } |
|
51 |
|
52 // After first run with no add-ons, we expect: |
|
53 // no extensions.json is created |
|
54 // no extensions.ini |
|
55 // database schema version preference is set |
|
56 // bootstrap add-ons preference is not found |
|
57 // add-on directory state preference is an empty array |
|
58 // no pending operations |
|
59 add_task(function first_run() { |
|
60 startupManager(); |
|
61 check_empty_state(); |
|
62 yield true; |
|
63 }); |
|
64 |
|
65 // Now do something that causes a DB load, and re-check |
|
66 function trigger_db_load() { |
|
67 let addonDefer = Promise.defer(); |
|
68 AddonManager.getAddonsByTypes(['extension'], addonDefer.resolve); |
|
69 let addonList = yield addonDefer.promise; |
|
70 |
|
71 do_check_eq(addonList.length, 0); |
|
72 check_empty_state(); |
|
73 |
|
74 yield true; |
|
75 }; |
|
76 add_task(trigger_db_load); |
|
77 |
|
78 // Now restart the manager and check again |
|
79 add_task(function restart_and_recheck() { |
|
80 restartManager(); |
|
81 check_empty_state(); |
|
82 yield true; |
|
83 }); |
|
84 |
|
85 // and reload the DB again |
|
86 add_task(trigger_db_load); |
|
87 |
|
88 // When we start up with no DB and an old database schema, we should update the |
|
89 // schema number but not create a database |
|
90 add_task(function upgrade_schema_version() { |
|
91 shutdownManager(); |
|
92 Services.prefs.setIntPref("extensions.databaseSchema", 1); |
|
93 |
|
94 startupManager(); |
|
95 do_check_eq(Services.prefs.getIntPref("extensions.databaseSchema"), DB_SCHEMA); |
|
96 check_empty_state(); |
|
97 }); |
|
98 |