|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that extensions installed through the registry work as expected |
|
6 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
7 |
|
8 // Enable loading extensions from the user and system scopes |
|
9 Services.prefs.setIntPref("extensions.enabledScopes", |
|
10 AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER + |
|
11 AddonManager.SCOPE_SYSTEM); |
|
12 |
|
13 var addon1 = { |
|
14 id: "addon1@tests.mozilla.org", |
|
15 version: "1.0", |
|
16 name: "Test 1", |
|
17 targetApplications: [{ |
|
18 id: "xpcshell@tests.mozilla.org", |
|
19 minVersion: "1", |
|
20 maxVersion: "1" |
|
21 }] |
|
22 }; |
|
23 |
|
24 var addon2 = { |
|
25 id: "addon2@tests.mozilla.org", |
|
26 version: "2.0", |
|
27 name: "Test 2", |
|
28 targetApplications: [{ |
|
29 id: "xpcshell@tests.mozilla.org", |
|
30 minVersion: "1", |
|
31 maxVersion: "2" |
|
32 }] |
|
33 }; |
|
34 |
|
35 const addon1Dir = writeInstallRDFForExtension(addon1, gProfD, "addon1"); |
|
36 const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2"); |
|
37 |
|
38 function run_test() { |
|
39 // This test only works where there is a registry. |
|
40 if (!("nsIWindowsRegKey" in AM_Ci)) |
|
41 return; |
|
42 |
|
43 do_test_pending(); |
|
44 |
|
45 run_test_1(); |
|
46 } |
|
47 |
|
48 // Tests whether basic registry install works |
|
49 function run_test_1() { |
|
50 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
|
51 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
52 "addon1@tests.mozilla.org", addon1Dir.path); |
|
53 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
|
54 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
55 "addon2@tests.mozilla.org", addon2Dir.path); |
|
56 |
|
57 startupManager(); |
|
58 |
|
59 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
60 "addon2@tests.mozilla.org"], function([a1, a2]) { |
|
61 do_check_neq(a1, null); |
|
62 do_check_true(a1.isActive); |
|
63 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
|
64 do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM); |
|
65 |
|
66 do_check_neq(a2, null); |
|
67 do_check_true(a2.isActive); |
|
68 do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
|
69 do_check_eq(a2.scope, AddonManager.SCOPE_USER); |
|
70 |
|
71 do_execute_soon(run_test_2); |
|
72 }); |
|
73 } |
|
74 |
|
75 // Tests whether uninstalling from the registry works |
|
76 function run_test_2() { |
|
77 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
|
78 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
79 "addon1@tests.mozilla.org", null); |
|
80 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
|
81 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
82 "addon2@tests.mozilla.org", null); |
|
83 |
|
84 restartManager(); |
|
85 |
|
86 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
87 "addon2@tests.mozilla.org"], function([a1, a2]) { |
|
88 do_check_eq(a1, null); |
|
89 do_check_eq(a2, null); |
|
90 |
|
91 do_execute_soon(run_test_3); |
|
92 }); |
|
93 } |
|
94 |
|
95 // Checks that the ID in the registry must match that in the install manifest |
|
96 function run_test_3() { |
|
97 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
|
98 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
99 "addon1@tests.mozilla.org", addon2Dir.path); |
|
100 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
|
101 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
102 "addon2@tests.mozilla.org", addon1Dir.path); |
|
103 |
|
104 restartManager(); |
|
105 |
|
106 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
107 "addon2@tests.mozilla.org"], function([a1, a2]) { |
|
108 do_check_eq(a1, null); |
|
109 do_check_eq(a2, null); |
|
110 |
|
111 do_execute_soon(run_test_4); |
|
112 }); |
|
113 } |
|
114 |
|
115 // Tests whether an extension's ID can change without its directory changing |
|
116 function run_test_4() { |
|
117 // Restarting with bad items in the registry should not force an EM restart |
|
118 restartManager(); |
|
119 |
|
120 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
|
121 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
122 "addon1@tests.mozilla.org", null); |
|
123 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
|
124 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
125 "addon2@tests.mozilla.org", null); |
|
126 |
|
127 restartManager(); |
|
128 |
|
129 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
|
130 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
131 "addon1@tests.mozilla.org", addon1Dir.path); |
|
132 restartManager(); |
|
133 |
|
134 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
|
135 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
136 "addon1@tests.mozilla.org", null); |
|
137 MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
|
138 "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
|
139 "addon2@tests.mozilla.org", addon1Dir.path); |
|
140 writeInstallRDFForExtension(addon2, gProfD, "addon1"); |
|
141 |
|
142 restartManager(); |
|
143 |
|
144 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
145 "addon2@tests.mozilla.org"], function([a1, a2]) { |
|
146 do_check_eq(a1, null); |
|
147 do_check_neq(a2, null); |
|
148 |
|
149 do_execute_soon(do_test_finished); |
|
150 }); |
|
151 } |