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