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