Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | |
michael@0 | 3 | let AddonManager = Cu.import("resource://gre/modules/AddonManager.jsm", {}).AddonManager; |
michael@0 | 4 | let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; |
michael@0 | 5 | |
michael@0 | 6 | const ADDON_TYPE_SERVICE = "service"; |
michael@0 | 7 | const ID_SUFFIX = "@services.mozilla.org"; |
michael@0 | 8 | const STRING_TYPE_NAME = "type.%ID%.name"; |
michael@0 | 9 | const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul"; |
michael@0 | 10 | |
michael@0 | 11 | let manifest = { // builtin provider |
michael@0 | 12 | name: "provider 1", |
michael@0 | 13 | origin: "https://example.com", |
michael@0 | 14 | sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 15 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 16 | iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" |
michael@0 | 17 | }; |
michael@0 | 18 | let manifest2 = { // used for testing install |
michael@0 | 19 | name: "provider 2", |
michael@0 | 20 | origin: "https://test1.example.com", |
michael@0 | 21 | sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 22 | workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 23 | iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png", |
michael@0 | 24 | version: 1 |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | function test() { |
michael@0 | 28 | waitForExplicitFinish(); |
michael@0 | 29 | |
michael@0 | 30 | let prefname = getManifestPrefname(manifest); |
michael@0 | 31 | setBuiltinManifestPref(prefname, manifest); |
michael@0 | 32 | // ensure that manifest2 is NOT showing as builtin |
michael@0 | 33 | is(SocialService.getOriginActivationType(manifest.origin), "builtin", "manifest is builtin"); |
michael@0 | 34 | is(SocialService.getOriginActivationType(manifest2.origin), "foreign", "manifest2 is not builtin"); |
michael@0 | 35 | |
michael@0 | 36 | Services.prefs.setBoolPref("social.remote-install.enabled", true); |
michael@0 | 37 | runSocialTests(tests, undefined, undefined, function () { |
michael@0 | 38 | Services.prefs.clearUserPref("social.remote-install.enabled"); |
michael@0 | 39 | // clear our builtin pref |
michael@0 | 40 | ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs"); |
michael@0 | 41 | resetBuiltinManifestPref(prefname); |
michael@0 | 42 | // just in case the tests failed, clear these here as well |
michael@0 | 43 | Services.prefs.clearUserPref("social.whitelist"); |
michael@0 | 44 | Services.prefs.clearUserPref("social.directories"); |
michael@0 | 45 | finish(); |
michael@0 | 46 | }); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function installListener(next, aManifest) { |
michael@0 | 50 | let expectEvent = "onInstalling"; |
michael@0 | 51 | let prefname = getManifestPrefname(aManifest); |
michael@0 | 52 | // wait for the actual removal to call next |
michael@0 | 53 | SocialService.registerProviderListener(function providerListener(topic, origin, providers) { |
michael@0 | 54 | if (topic == "provider-disabled") { |
michael@0 | 55 | SocialService.unregisterProviderListener(providerListener); |
michael@0 | 56 | is(origin, aManifest.origin, "provider disabled"); |
michael@0 | 57 | executeSoon(next); |
michael@0 | 58 | } |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | return { |
michael@0 | 62 | onInstalling: function(addon) { |
michael@0 | 63 | is(expectEvent, "onInstalling", "install started"); |
michael@0 | 64 | is(addon.manifest.origin, aManifest.origin, "provider about to be installed"); |
michael@0 | 65 | ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs"); |
michael@0 | 66 | expectEvent = "onInstalled"; |
michael@0 | 67 | }, |
michael@0 | 68 | onInstalled: function(addon) { |
michael@0 | 69 | is(addon.manifest.origin, aManifest.origin, "provider installed"); |
michael@0 | 70 | ok(addon.installDate.getTime() > 0, "addon has installDate"); |
michael@0 | 71 | ok(addon.updateDate.getTime() > 0, "addon has updateDate"); |
michael@0 | 72 | ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs"); |
michael@0 | 73 | expectEvent = "onUninstalling"; |
michael@0 | 74 | }, |
michael@0 | 75 | onUninstalling: function(addon) { |
michael@0 | 76 | is(expectEvent, "onUninstalling", "uninstall started"); |
michael@0 | 77 | is(addon.manifest.origin, aManifest.origin, "provider about to be uninstalled"); |
michael@0 | 78 | ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs"); |
michael@0 | 79 | expectEvent = "onUninstalled"; |
michael@0 | 80 | }, |
michael@0 | 81 | onUninstalled: function(addon) { |
michael@0 | 82 | is(expectEvent, "onUninstalled", "provider has been uninstalled"); |
michael@0 | 83 | is(addon.manifest.origin, aManifest.origin, "provider uninstalled"); |
michael@0 | 84 | ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs"); |
michael@0 | 85 | AddonManager.removeAddonListener(this); |
michael@0 | 86 | } |
michael@0 | 87 | }; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | var tests = { |
michael@0 | 91 | testAddonEnableToggle: function(next) { |
michael@0 | 92 | let expectEvent; |
michael@0 | 93 | let prefname = getManifestPrefname(manifest); |
michael@0 | 94 | let listener = { |
michael@0 | 95 | onEnabled: function(addon) { |
michael@0 | 96 | is(expectEvent, "onEnabled", "provider onEnabled"); |
michael@0 | 97 | ok(!addon.userDisabled, "provider enabled"); |
michael@0 | 98 | executeSoon(function() { |
michael@0 | 99 | expectEvent = "onDisabling"; |
michael@0 | 100 | addon.userDisabled = true; |
michael@0 | 101 | }); |
michael@0 | 102 | }, |
michael@0 | 103 | onEnabling: function(addon) { |
michael@0 | 104 | is(expectEvent, "onEnabling", "provider onEnabling"); |
michael@0 | 105 | expectEvent = "onEnabled"; |
michael@0 | 106 | }, |
michael@0 | 107 | onDisabled: function(addon) { |
michael@0 | 108 | is(expectEvent, "onDisabled", "provider onDisabled"); |
michael@0 | 109 | ok(addon.userDisabled, "provider disabled"); |
michael@0 | 110 | AddonManager.removeAddonListener(listener); |
michael@0 | 111 | // clear the provider user-level pref |
michael@0 | 112 | Services.prefs.clearUserPref(prefname); |
michael@0 | 113 | executeSoon(next); |
michael@0 | 114 | }, |
michael@0 | 115 | onDisabling: function(addon) { |
michael@0 | 116 | is(expectEvent, "onDisabling", "provider onDisabling"); |
michael@0 | 117 | expectEvent = "onDisabled"; |
michael@0 | 118 | } |
michael@0 | 119 | }; |
michael@0 | 120 | AddonManager.addAddonListener(listener); |
michael@0 | 121 | |
michael@0 | 122 | // we're only testing enable disable, so we quickly set the user-level pref |
michael@0 | 123 | // for this provider and test enable/disable toggling |
michael@0 | 124 | setManifestPref(prefname, manifest); |
michael@0 | 125 | ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs"); |
michael@0 | 126 | AddonManager.getAddonsByTypes([ADDON_TYPE_SERVICE], function(addons) { |
michael@0 | 127 | for (let addon of addons) { |
michael@0 | 128 | if (addon.userDisabled) { |
michael@0 | 129 | expectEvent = "onEnabling"; |
michael@0 | 130 | addon.userDisabled = false; |
michael@0 | 131 | // only test with one addon |
michael@0 | 132 | return; |
michael@0 | 133 | } |
michael@0 | 134 | } |
michael@0 | 135 | ok(false, "no addons toggled"); |
michael@0 | 136 | next(); |
michael@0 | 137 | }); |
michael@0 | 138 | }, |
michael@0 | 139 | testProviderEnableToggle: function(next) { |
michael@0 | 140 | // enable and disabel a provider from the SocialService interface, check |
michael@0 | 141 | // that the addon manager is updated |
michael@0 | 142 | |
michael@0 | 143 | let expectEvent; |
michael@0 | 144 | let prefname = getManifestPrefname(manifest); |
michael@0 | 145 | |
michael@0 | 146 | let listener = { |
michael@0 | 147 | onEnabled: function(addon) { |
michael@0 | 148 | is(expectEvent, "onEnabled", "provider onEnabled"); |
michael@0 | 149 | is(addon.manifest.origin, manifest.origin, "provider enabled"); |
michael@0 | 150 | ok(!addon.userDisabled, "provider !userDisabled"); |
michael@0 | 151 | }, |
michael@0 | 152 | onEnabling: function(addon) { |
michael@0 | 153 | is(expectEvent, "onEnabling", "provider onEnabling"); |
michael@0 | 154 | is(addon.manifest.origin, manifest.origin, "provider about to be enabled"); |
michael@0 | 155 | expectEvent = "onEnabled"; |
michael@0 | 156 | }, |
michael@0 | 157 | onDisabled: function(addon) { |
michael@0 | 158 | is(expectEvent, "onDisabled", "provider onDisabled"); |
michael@0 | 159 | is(addon.manifest.origin, manifest.origin, "provider disabled"); |
michael@0 | 160 | ok(addon.userDisabled, "provider userDisabled"); |
michael@0 | 161 | }, |
michael@0 | 162 | onDisabling: function(addon) { |
michael@0 | 163 | is(expectEvent, "onDisabling", "provider onDisabling"); |
michael@0 | 164 | is(addon.manifest.origin, manifest.origin, "provider about to be disabled"); |
michael@0 | 165 | expectEvent = "onDisabled"; |
michael@0 | 166 | } |
michael@0 | 167 | }; |
michael@0 | 168 | AddonManager.addAddonListener(listener); |
michael@0 | 169 | |
michael@0 | 170 | expectEvent = "onEnabling"; |
michael@0 | 171 | setManifestPref(prefname, manifest); |
michael@0 | 172 | SocialService.addBuiltinProvider(manifest.origin, function(provider) { |
michael@0 | 173 | expectEvent = "onDisabling"; |
michael@0 | 174 | SocialService.removeProvider(provider.origin, function() { |
michael@0 | 175 | AddonManager.removeAddonListener(listener); |
michael@0 | 176 | Services.prefs.clearUserPref(prefname); |
michael@0 | 177 | next(); |
michael@0 | 178 | }); |
michael@0 | 179 | }); |
michael@0 | 180 | }, |
michael@0 | 181 | testForeignInstall: function(next) { |
michael@0 | 182 | AddonManager.addAddonListener(installListener(next, manifest2)); |
michael@0 | 183 | |
michael@0 | 184 | // we expect the addon install dialog to appear, we need to accept the |
michael@0 | 185 | // install from the dialog. |
michael@0 | 186 | info("Waiting for install dialog"); |
michael@0 | 187 | let panel = document.getElementById("servicesInstall-notification"); |
michael@0 | 188 | PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
michael@0 | 189 | PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
michael@0 | 190 | info("servicesInstall-notification panel opened"); |
michael@0 | 191 | panel.button.click(); |
michael@0 | 192 | }) |
michael@0 | 193 | |
michael@0 | 194 | let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 195 | addTab(activationURL, function(tab) { |
michael@0 | 196 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 197 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 198 | Services.prefs.setCharPref("social.whitelist", ""); |
michael@0 | 199 | is(SocialService.getOriginActivationType(installFrom), "foreign", "testing foriegn install"); |
michael@0 | 200 | Social.installProvider(doc, manifest2, function(addonManifest) { |
michael@0 | 201 | Services.prefs.clearUserPref("social.whitelist"); |
michael@0 | 202 | SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { |
michael@0 | 203 | Social.uninstallProvider(addonManifest.origin); |
michael@0 | 204 | gBrowser.removeTab(tab); |
michael@0 | 205 | }); |
michael@0 | 206 | }); |
michael@0 | 207 | }); |
michael@0 | 208 | }, |
michael@0 | 209 | testBuiltinInstallWithoutManifest: function(next) { |
michael@0 | 210 | // send installProvider null for the manifest |
michael@0 | 211 | AddonManager.addAddonListener(installListener(next, manifest)); |
michael@0 | 212 | let panel = document.getElementById("servicesInstall-notification"); |
michael@0 | 213 | PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
michael@0 | 214 | PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
michael@0 | 215 | info("servicesInstall-notification panel opened"); |
michael@0 | 216 | panel.button.click(); |
michael@0 | 217 | }); |
michael@0 | 218 | |
michael@0 | 219 | let prefname = getManifestPrefname(manifest); |
michael@0 | 220 | let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 221 | addTab(activationURL, function(tab) { |
michael@0 | 222 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 223 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 224 | is(SocialService.getOriginActivationType(installFrom), "builtin", "testing builtin install"); |
michael@0 | 225 | ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs"); |
michael@0 | 226 | Social.installProvider(doc, null, function(addonManifest) { |
michael@0 | 227 | ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs"); |
michael@0 | 228 | SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { |
michael@0 | 229 | Social.uninstallProvider(addonManifest.origin); |
michael@0 | 230 | gBrowser.removeTab(tab); |
michael@0 | 231 | }); |
michael@0 | 232 | }); |
michael@0 | 233 | }); |
michael@0 | 234 | }, |
michael@0 | 235 | testBuiltinInstall: function(next) { |
michael@0 | 236 | // send installProvider a json object for the manifest |
michael@0 | 237 | AddonManager.addAddonListener(installListener(next, manifest)); |
michael@0 | 238 | let panel = document.getElementById("servicesInstall-notification"); |
michael@0 | 239 | PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
michael@0 | 240 | PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
michael@0 | 241 | info("servicesInstall-notification panel opened"); |
michael@0 | 242 | panel.button.click(); |
michael@0 | 243 | }); |
michael@0 | 244 | |
michael@0 | 245 | let prefname = getManifestPrefname(manifest); |
michael@0 | 246 | let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 247 | addTab(activationURL, function(tab) { |
michael@0 | 248 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 249 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 250 | is(SocialService.getOriginActivationType(installFrom), "builtin", "testing builtin install"); |
michael@0 | 251 | ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs"); |
michael@0 | 252 | Social.installProvider(doc, manifest, function(addonManifest) { |
michael@0 | 253 | ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs"); |
michael@0 | 254 | SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { |
michael@0 | 255 | Social.uninstallProvider(addonManifest.origin); |
michael@0 | 256 | gBrowser.removeTab(tab); |
michael@0 | 257 | }); |
michael@0 | 258 | }); |
michael@0 | 259 | }); |
michael@0 | 260 | }, |
michael@0 | 261 | testWhitelistInstall: function(next) { |
michael@0 | 262 | AddonManager.addAddonListener(installListener(next, manifest2)); |
michael@0 | 263 | let panel = document.getElementById("servicesInstall-notification"); |
michael@0 | 264 | PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
michael@0 | 265 | PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
michael@0 | 266 | info("servicesInstall-notification panel opened"); |
michael@0 | 267 | panel.button.click(); |
michael@0 | 268 | }); |
michael@0 | 269 | |
michael@0 | 270 | let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 271 | addTab(activationURL, function(tab) { |
michael@0 | 272 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 273 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 274 | Services.prefs.setCharPref("social.whitelist", installFrom); |
michael@0 | 275 | is(SocialService.getOriginActivationType(installFrom), "whitelist", "testing whitelist install"); |
michael@0 | 276 | Social.installProvider(doc, manifest2, function(addonManifest) { |
michael@0 | 277 | Services.prefs.clearUserPref("social.whitelist"); |
michael@0 | 278 | SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { |
michael@0 | 279 | Social.uninstallProvider(addonManifest.origin); |
michael@0 | 280 | gBrowser.removeTab(tab); |
michael@0 | 281 | }); |
michael@0 | 282 | }); |
michael@0 | 283 | }); |
michael@0 | 284 | }, |
michael@0 | 285 | testDirectoryInstall: function(next) { |
michael@0 | 286 | AddonManager.addAddonListener(installListener(next, manifest2)); |
michael@0 | 287 | let panel = document.getElementById("servicesInstall-notification"); |
michael@0 | 288 | PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
michael@0 | 289 | PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
michael@0 | 290 | info("servicesInstall-notification panel opened"); |
michael@0 | 291 | panel.button.click(); |
michael@0 | 292 | }); |
michael@0 | 293 | |
michael@0 | 294 | let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 295 | addTab(activationURL, function(tab) { |
michael@0 | 296 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 297 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 298 | Services.prefs.setCharPref("social.directories", installFrom); |
michael@0 | 299 | is(SocialService.getOriginActivationType(installFrom), "directory", "testing directory install"); |
michael@0 | 300 | Social.installProvider(doc, manifest2, function(addonManifest) { |
michael@0 | 301 | Services.prefs.clearUserPref("social.directories"); |
michael@0 | 302 | SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { |
michael@0 | 303 | Social.uninstallProvider(addonManifest.origin); |
michael@0 | 304 | gBrowser.removeTab(tab); |
michael@0 | 305 | }); |
michael@0 | 306 | }); |
michael@0 | 307 | }); |
michael@0 | 308 | }, |
michael@0 | 309 | testUpgradeProviderFromWorker: function(next) { |
michael@0 | 310 | // add the provider, change the pref, add it again. The provider at that |
michael@0 | 311 | // point should be upgraded |
michael@0 | 312 | let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 313 | let panel = document.getElementById("servicesInstall-notification"); |
michael@0 | 314 | PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
michael@0 | 315 | PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
michael@0 | 316 | info("servicesInstall-notification panel opened"); |
michael@0 | 317 | panel.button.click(); |
michael@0 | 318 | }); |
michael@0 | 319 | |
michael@0 | 320 | addTab(activationURL, function(tab) { |
michael@0 | 321 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 322 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 323 | Services.prefs.setCharPref("social.whitelist", installFrom); |
michael@0 | 324 | Social.installProvider(doc, manifest2, function(addonManifest) { |
michael@0 | 325 | SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { |
michael@0 | 326 | is(provider.manifest.version, 1, "manifest version is 1"); |
michael@0 | 327 | |
michael@0 | 328 | // watch for the provider-update and test the new version |
michael@0 | 329 | SocialService.registerProviderListener(function providerListener(topic, origin, providers) { |
michael@0 | 330 | if (topic != "provider-update") |
michael@0 | 331 | return; |
michael@0 | 332 | is(origin, addonManifest.origin, "provider updated") |
michael@0 | 333 | SocialService.unregisterProviderListener(providerListener); |
michael@0 | 334 | Services.prefs.clearUserPref("social.whitelist"); |
michael@0 | 335 | let provider = Social._getProviderFromOrigin(origin); |
michael@0 | 336 | is(provider.manifest.version, 2, "manifest version is 2"); |
michael@0 | 337 | Social.uninstallProvider(origin, function() { |
michael@0 | 338 | gBrowser.removeTab(tab); |
michael@0 | 339 | next(); |
michael@0 | 340 | }); |
michael@0 | 341 | }); |
michael@0 | 342 | |
michael@0 | 343 | let port = provider.getWorkerPort(); |
michael@0 | 344 | port.postMessage({topic: "worker.update", data: true}); |
michael@0 | 345 | |
michael@0 | 346 | }); |
michael@0 | 347 | }); |
michael@0 | 348 | }); |
michael@0 | 349 | } |
michael@0 | 350 | } |