|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Bug 586574 - Provide way to set a default for automatic updates |
|
6 // Bug 710064 - Make the "Update Add-ons Automatically" checkbox state |
|
7 // also depend on the extensions.update.enabled pref |
|
8 |
|
9 // TEST_PATH=toolkit/mozapps/extensions/test/browser/browser_bug586574.js make -C obj-ff mochitest-browser-chrome |
|
10 |
|
11 const PREF_UPDATE_ENABLED = "extensions.update.enabled"; |
|
12 const PREF_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"; |
|
13 |
|
14 var gManagerWindow; |
|
15 var gProvider; |
|
16 |
|
17 var gUtilsBtn; |
|
18 var gUtilsMenu; |
|
19 var gDropdownMenu; |
|
20 var gSetDefault; |
|
21 var gResetToAutomatic; |
|
22 var gResetToManual; |
|
23 |
|
24 function test() { |
|
25 waitForExplicitFinish(); |
|
26 |
|
27 gProvider = new MockProvider(); |
|
28 |
|
29 gProvider.createAddons([{ |
|
30 id: "addon1@tests.mozilla.org", |
|
31 name: "addon 1", |
|
32 version: "1.0", |
|
33 applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE |
|
34 }]); |
|
35 |
|
36 open_manager("addons://list/extension", function(aWindow) { |
|
37 gManagerWindow = aWindow; |
|
38 |
|
39 gUtilsBtn = gManagerWindow.document.getElementById("header-utils-btn"); |
|
40 gUtilsMenu = gManagerWindow.document.getElementById("utils-menu"); |
|
41 |
|
42 run_next_test(); |
|
43 }); |
|
44 } |
|
45 |
|
46 |
|
47 function end_test() { |
|
48 close_manager(gManagerWindow, finish); |
|
49 } |
|
50 |
|
51 |
|
52 function wait_for_popup(aCallback) { |
|
53 if (gUtilsMenu.state == "open") { |
|
54 aCallback(); |
|
55 return; |
|
56 } |
|
57 |
|
58 gUtilsMenu.addEventListener("popupshown", function() { |
|
59 gUtilsMenu.removeEventListener("popupshown", arguments.callee, false); |
|
60 info("Utilities menu shown"); |
|
61 aCallback(); |
|
62 }, false); |
|
63 } |
|
64 |
|
65 function wait_for_hide(aCallback) { |
|
66 if (gUtilsMenu.state == "closed") { |
|
67 aCallback(); |
|
68 return; |
|
69 } |
|
70 |
|
71 gUtilsMenu.addEventListener("popuphidden", function() { |
|
72 gUtilsMenu.removeEventListener("popuphidden", arguments.callee, false); |
|
73 info("Utilities menu hidden"); |
|
74 aCallback(); |
|
75 }, false); |
|
76 } |
|
77 |
|
78 add_test(function() { |
|
79 gSetDefault = gManagerWindow.document.getElementById("utils-autoUpdateDefault"); |
|
80 gResetToAutomatic = gManagerWindow.document.getElementById("utils-resetAddonUpdatesToAutomatic"); |
|
81 gResetToManual = gManagerWindow.document.getElementById("utils-resetAddonUpdatesToManual"); |
|
82 |
|
83 info("Ensuring default prefs are set to true"); |
|
84 Services.prefs.setBoolPref(PREF_UPDATE_ENABLED, true); |
|
85 Services.prefs.setBoolPref(PREF_AUTOUPDATE_DEFAULT, true); |
|
86 |
|
87 wait_for_popup(function() { |
|
88 is(gSetDefault.getAttribute("checked"), "true", |
|
89 "#1 Set Default menuitem should be checked"); |
|
90 is_element_visible(gResetToAutomatic, |
|
91 "#1 Reset to Automatic menuitem should be visible"); |
|
92 is_element_hidden(gResetToManual, |
|
93 "#1 Reset to Manual menuitem should be hidden"); |
|
94 |
|
95 var listener = { |
|
96 onPropertyChanged: function(aAddon, aProperties) { |
|
97 AddonManager.removeAddonListener(listener); |
|
98 is(aAddon.id, gProvider.addons[0].id, |
|
99 "Should get onPropertyChanged event for correct addon"); |
|
100 ok(!("applyBackgroundUpdates" in aProperties), |
|
101 "Should have gotten applyBackgroundUpdates in properties array"); |
|
102 is(aAddon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT, |
|
103 "Addon.applyBackgroundUpdates should have been reset to default"); |
|
104 |
|
105 info("Setting Addon.applyBackgroundUpdates back to disabled"); |
|
106 aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; |
|
107 |
|
108 wait_for_hide(run_next_test); |
|
109 } |
|
110 }; |
|
111 AddonManager.addAddonListener(listener); |
|
112 |
|
113 info("Clicking Reset to Automatic menuitem"); |
|
114 EventUtils.synthesizeMouseAtCenter(gResetToAutomatic, { }, gManagerWindow); |
|
115 }); |
|
116 |
|
117 info("Opening utilities menu"); |
|
118 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
119 }); |
|
120 |
|
121 |
|
122 add_test(function() { |
|
123 info("Disabling extensions.update.enabled"); |
|
124 Services.prefs.setBoolPref(PREF_UPDATE_ENABLED, false); |
|
125 |
|
126 wait_for_popup(function() { |
|
127 isnot(gSetDefault.getAttribute("checked"), "true", |
|
128 "#2 Set Default menuitem should not be checked"); |
|
129 is_element_visible(gResetToAutomatic, |
|
130 "#2 Reset to Automatic menuitem should be visible"); |
|
131 is_element_hidden(gResetToManual, |
|
132 "#2 Reset to Manual menuitem should be hidden"); |
|
133 |
|
134 wait_for_hide(run_next_test); |
|
135 |
|
136 info("Clicking Set Default menuitem to reenable"); |
|
137 EventUtils.synthesizeMouseAtCenter(gSetDefault, { }, gManagerWindow); |
|
138 }); |
|
139 |
|
140 info("Opening utilities menu"); |
|
141 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
142 }); |
|
143 |
|
144 |
|
145 add_test(function() { |
|
146 ok(Services.prefs.getBoolPref(PREF_UPDATE_ENABLED), |
|
147 "extensions.update.enabled should be true after the previous test"); |
|
148 ok(Services.prefs.getBoolPref(PREF_AUTOUPDATE_DEFAULT), |
|
149 "extensions.update.autoUpdateDefault should be true after the previous test"); |
|
150 |
|
151 info("Disabling both extensions.update.enabled and extensions.update.autoUpdateDefault"); |
|
152 Services.prefs.setBoolPref(PREF_UPDATE_ENABLED, false); |
|
153 Services.prefs.setBoolPref(PREF_AUTOUPDATE_DEFAULT, false); |
|
154 |
|
155 wait_for_popup(function() { |
|
156 isnot(gSetDefault.getAttribute("checked"), "true", |
|
157 "#3 Set Default menuitem should not be checked"); |
|
158 is_element_hidden(gResetToAutomatic, |
|
159 "#3 Reset to automatic menuitem should be hidden"); |
|
160 is_element_visible(gResetToManual, |
|
161 "#3 Reset to manual menuitem should be visible"); |
|
162 |
|
163 wait_for_hide(run_next_test); |
|
164 |
|
165 info("Clicking Set Default menuitem to reenable"); |
|
166 EventUtils.synthesizeMouseAtCenter(gSetDefault, { }, gManagerWindow); |
|
167 }); |
|
168 |
|
169 info("Opening utilities menu"); |
|
170 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
171 }); |
|
172 |
|
173 |
|
174 add_test(function() { |
|
175 ok(Services.prefs.getBoolPref(PREF_UPDATE_ENABLED), |
|
176 "extensions.update.enabled should be true after the previous test"); |
|
177 ok(Services.prefs.getBoolPref(PREF_AUTOUPDATE_DEFAULT), |
|
178 "extensions.update.autoUpdateDefault should be true after the previous test"); |
|
179 |
|
180 info("clicking the button to disable extensions.update.autoUpdateDefault"); |
|
181 wait_for_popup(function() { |
|
182 is(gSetDefault.getAttribute("checked"), "true", |
|
183 "#4 Set Default menuitem should be checked"); |
|
184 is_element_visible(gResetToAutomatic, |
|
185 "#4 Reset to Automatic menuitem should be visible"); |
|
186 is_element_hidden(gResetToManual, |
|
187 "#4 Reset to Manual menuitem should be hidden"); |
|
188 |
|
189 wait_for_hide(run_next_test); |
|
190 |
|
191 info("Clicking Set Default menuitem to disable"); |
|
192 EventUtils.synthesizeMouseAtCenter(gSetDefault, { }, gManagerWindow); |
|
193 }); |
|
194 |
|
195 info("Opening utilities menu"); |
|
196 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
197 }); |
|
198 |
|
199 |
|
200 add_test(function() { |
|
201 ok(Services.prefs.getBoolPref(PREF_UPDATE_ENABLED), |
|
202 "extensions.update.enabled should be true after the previous test"); |
|
203 is(Services.prefs.getBoolPref(PREF_AUTOUPDATE_DEFAULT), false, |
|
204 "extensions.update.autoUpdateDefault should be false after the previous test"); |
|
205 |
|
206 wait_for_popup(function() { |
|
207 isnot(gSetDefault.getAttribute("checked"), "true", |
|
208 "#5 Set Default menuitem should not be checked"); |
|
209 is_element_hidden(gResetToAutomatic, |
|
210 "#5 Reset to automatic menuitem should be hidden"); |
|
211 is_element_visible(gResetToManual, |
|
212 "#5 Reset to manual menuitem should be visible"); |
|
213 |
|
214 var listener = { |
|
215 onPropertyChanged: function(aAddon, aProperties) { |
|
216 AddonManager.removeAddonListener(listener); |
|
217 is(aAddon.id, gProvider.addons[0].id, |
|
218 "Should get onPropertyChanged event for correct addon"); |
|
219 ok(!("applyBackgroundUpdates" in aProperties), |
|
220 "Should have gotten applyBackgroundUpdates in properties array"); |
|
221 is(aAddon.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT, |
|
222 "Addon.applyBackgroundUpdates should have been reset to default"); |
|
223 |
|
224 info("Setting Addon.applyBackgroundUpdates back to disabled"); |
|
225 aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE; |
|
226 |
|
227 wait_for_hide(run_next_test); |
|
228 } |
|
229 }; |
|
230 AddonManager.addAddonListener(listener); |
|
231 |
|
232 info("Clicking Reset to Manual menuitem"); |
|
233 EventUtils.synthesizeMouseAtCenter(gResetToManual, { }, gManagerWindow); |
|
234 |
|
235 }); |
|
236 |
|
237 info("Opening utilities menu"); |
|
238 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
239 }); |
|
240 |
|
241 |
|
242 add_test(function() { |
|
243 wait_for_popup(function() { |
|
244 isnot(gSetDefault.getAttribute("checked"), "true", |
|
245 "#6 Set Default menuitem should not be checked"); |
|
246 is_element_hidden(gResetToAutomatic, |
|
247 "#6 Reset to automatic menuitem should be hidden"); |
|
248 is_element_visible(gResetToManual, |
|
249 "#6 Reset to manual menuitem should be visible"); |
|
250 |
|
251 wait_for_hide(run_next_test); |
|
252 |
|
253 info("Clicking Set Default menuitem"); |
|
254 EventUtils.synthesizeMouseAtCenter(gSetDefault, { }, gManagerWindow); |
|
255 }); |
|
256 |
|
257 info("Opening utilities menu"); |
|
258 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
259 }); |
|
260 |
|
261 |
|
262 add_test(function() { |
|
263 wait_for_popup(function() { |
|
264 is(gSetDefault.getAttribute("checked"), "true", |
|
265 "#7 Set Default menuitem should be checked"); |
|
266 is_element_visible(gResetToAutomatic, |
|
267 "#7 Reset to Automatic menuitem should be visible"); |
|
268 is_element_hidden(gResetToManual, |
|
269 "#7 Reset to Manual menuitem should be hidden"); |
|
270 |
|
271 wait_for_hide(run_next_test); |
|
272 |
|
273 gUtilsMenu.hidePopup(); |
|
274 }); |
|
275 |
|
276 info("Opening utilities menu"); |
|
277 EventUtils.synthesizeMouseAtCenter(gUtilsBtn, { }, gManagerWindow); |
|
278 }); |
|
279 |