diff --git a/browser/base/content/test/social/browser_social_multiworker.js b/browser/base/content/test/social/browser_social_multiworker.js index 452ab98bf96..1306a89da30 100644 --- a/browser/base/content/test/social/browser_social_multiworker.js +++ b/browser/base/content/test/social/browser_social_multiworker.js @@ -7,7 +7,6 @@ function test() { Services.prefs.setBoolPref("social.allowMultipleWorkers", true); runSocialTestWithProvider(gProviders, function (finishcb) { - Social.enabled = true; runSocialTests(tests, undefined, undefined, function() { Services.prefs.clearUserPref("social.allowMultipleWorkers"); finishcb(); diff --git a/browser/modules/Social.jsm b/browser/modules/Social.jsm index ee2d1c430d5..6652a1c7746 100644 --- a/browser/modules/Social.jsm +++ b/browser/modules/Social.jsm @@ -34,8 +34,9 @@ function prefObserver(subject, topic, data) { if (enable && !Social.provider) { // this will result in setting Social.provider SocialService.getOrderedProviderList(function(providers) { - Social.enabled = true; Social._updateProviderCache(providers); + Social.enabled = true; + Services.obs.notifyObservers(null, "social:providers-changed", null); }); } else if (!enable && Social.provider) { Social.provider = null; @@ -167,7 +168,7 @@ this.Social = { // Retrieve the current set of providers, and set the current provider. SocialService.getOrderedProviderList(function (providers) { Social._updateProviderCache(providers); - Social._updateWorkerState(SocialService.enabled); + Social._updateWorkerState(true); }); } @@ -180,16 +181,10 @@ this.Social = { Services.obs.notifyObservers(null, "social:" + topic, origin); return; } - if (topic == "provider-enabled") { - Social._updateProviderCache(providers); - Social._updateWorkerState(Social.enabled); - Services.obs.notifyObservers(null, "social:" + topic, origin); - return; - } - if (topic == "provider-disabled") { - // a provider was removed from the list of providers, that does not - // affect worker state for other providers + if (topic == "provider-enabled" || topic == "provider-disabled") { Social._updateProviderCache(providers); + Social._updateWorkerState(true); + Services.obs.notifyObservers(null, "social:providers-changed", null); Services.obs.notifyObservers(null, "social:" + topic, origin); return; } @@ -199,6 +194,7 @@ this.Social = { Social._updateProviderCache(providers); let provider = Social._getProviderFromOrigin(origin); provider.reload(); + Services.obs.notifyObservers(null, "social:providers-changed", null); } }); }, @@ -214,7 +210,6 @@ this.Social = { // Called to update our cache of providers and set the current provider _updateProviderCache: function (providers) { this.providers = providers; - Services.obs.notifyObservers(null, "social:providers-changed", null); // If social is currently disabled there's nothing else to do other than // to notify about the lack of a provider. diff --git a/browser/modules/test/moz.build b/browser/modules/test/moz.build index 0b19f7d22fb..5cfff8ca7d3 100644 --- a/browser/modules/test/moz.build +++ b/browser/modules/test/moz.build @@ -4,4 +4,4 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -DIRS += ['chrome', 'unit'] +DIRS += ['chrome'] diff --git a/browser/modules/test/unit/moz.build b/browser/modules/test/unit/moz.build deleted file mode 100644 index fb6e74855b3..00000000000 --- a/browser/modules/test/unit/moz.build +++ /dev/null @@ -1,9 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DIRS += ['social'] - -XPCSHELL_TESTS_MANIFESTS += ['social/xpcshell.ini'] diff --git a/browser/modules/test/unit/social/Makefile.in b/browser/modules/test/unit/social/Makefile.in deleted file mode 100644 index a060fd25e47..00000000000 --- a/browser/modules/test/unit/social/Makefile.in +++ /dev/null @@ -1,11 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -XPCSHELL_RESOURCES = \ - xpcshell.ini \ - head.js \ - blocklist.xml \ - test_social.js \ - test_socialDisabledStartup.js \ - $(NULL) diff --git a/browser/modules/test/unit/social/blocklist.xml b/browser/modules/test/unit/social/blocklist.xml deleted file mode 100644 index c8d72d62422..00000000000 --- a/browser/modules/test/unit/social/blocklist.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/browser/modules/test/unit/social/head.js b/browser/modules/test/unit/social/head.js deleted file mode 100644 index ab61acd3279..00000000000 --- a/browser/modules/test/unit/social/head.js +++ /dev/null @@ -1,146 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); - -var Social, SocialService; - -let manifests = [ - { - name: "provider 1", - origin: "https://example1.com", - sidebarURL: "https://example1.com/sidebar/", - }, - { - name: "provider 2", - origin: "https://example2.com", - sidebarURL: "https://example1.com/sidebar/", - } -]; - -const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest."); - -// SocialProvider class relies on blocklisting being enabled. To enable -// blocklisting, we have to setup an app and initialize the blocklist (see -// initApp below). -const gProfD = do_get_profile(); - -const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1"; -const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}"); - -function createAppInfo(id, name, version, platformVersion) { - gAppInfo = { - // nsIXULAppInfo - vendor: "Mozilla", - name: name, - ID: id, - version: version, - appBuildID: "2007010101", - platformVersion: platformVersion ? platformVersion : "1.0", - platformBuildID: "2007010101", - - // nsIXULRuntime - inSafeMode: false, - logConsoleErrors: true, - OS: "XPCShell", - XPCOMABI: "noarch-spidermonkey", - invalidateCachesOnRestart: function invalidateCachesOnRestart() { - // Do nothing - }, - - // nsICrashReporter - annotations: {}, - - annotateCrashReport: function(key, data) { - this.annotations[key] = data; - }, - - QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, - Ci.nsIXULRuntime, - Ci.nsICrashReporter, - Ci.nsISupports]) - }; - - var XULAppInfoFactory = { - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - return gAppInfo.QueryInterface(iid); - } - }; - var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); - registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo", - XULAPPINFO_CONTRACTID, XULAppInfoFactory); -} - -function initApp() { - createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); - // prepare a blocklist file for the blocklist service - var blocklistFile = gProfD.clone(); - blocklistFile.append("blocklist.xml"); - if (blocklistFile.exists()) - blocklistFile.remove(false); - var source = do_get_file("blocklist.xml"); - source.copyTo(gProfD, "blocklist.xml"); -} - -function setManifestPref(manifest) { - let string = Cc["@mozilla.org/supports-string;1"]. - createInstance(Ci.nsISupportsString); - string.data = JSON.stringify(manifest); - Services.prefs.setComplexValue("social.manifest." + manifest.origin, Ci.nsISupportsString, string); -} - -function do_wait_observer(topic, cb) { - function observer(subject, topic, data) { - Services.obs.removeObserver(observer, topic); - cb(); - } - Services.obs.addObserver(observer, topic, false); -} - -function do_initialize_social(enabledOnStartup, cb) { - initApp(); - - manifests.forEach(function (manifest) { - setManifestPref(manifest); - }); - // Set both providers active and flag the first one as "current" - let activeVal = Cc["@mozilla.org/supports-string;1"]. - createInstance(Ci.nsISupportsString); - let active = {}; - for (let m of manifests) - active[m.origin] = 1; - activeVal.data = JSON.stringify(active); - Services.prefs.setComplexValue("social.activeProviders", - Ci.nsISupportsString, activeVal); - Services.prefs.setCharPref("social.provider.current", manifests[0].origin); - Services.prefs.setBoolPref("social.enabled", enabledOnStartup); - - do_register_cleanup(function() { - manifests.forEach(function (manifest) { - Services.prefs.clearUserPref("social.manifest." + manifest.origin); - }); - Services.prefs.clearUserPref("social.enabled"); - Services.prefs.clearUserPref("social.provider.current"); - Services.prefs.clearUserPref("social.activeProviders"); - }); - - // expecting 2 providers installed - do_wait_observer("social:providers-changed", function() { - do_check_eq(Social.providers.length, 2, "2 providers installed"); - cb(); - }); - - // import and initialize everything - SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; - do_check_eq(SocialService.enabled, enabledOnStartup, "service is doing its thing"); - do_check_true(SocialService.hasEnabledProviders, "Service has enabled providers"); - Social = Cu.import("resource:///modules/Social.jsm", {}).Social; - do_check_false(Social.initialized, "Social is not initialized"); - Social.init(); - do_check_true(Social.initialized, "Social is initialized"); -} diff --git a/browser/modules/test/unit/social/moz.build b/browser/modules/test/unit/social/moz.build deleted file mode 100644 index 895d11993cf..00000000000 --- a/browser/modules/test/unit/social/moz.build +++ /dev/null @@ -1,6 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - diff --git a/browser/modules/test/unit/social/test_social.js b/browser/modules/test/unit/social/test_social.js deleted file mode 100644 index 0152f43e95f..00000000000 --- a/browser/modules/test/unit/social/test_social.js +++ /dev/null @@ -1,34 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function run_test() { - // we are testing worker startup specifically - Services.prefs.setBoolPref("social.allowMultipleWorkers", true); - do_register_cleanup(function() { - Services.prefs.clearUserPref("social.allowMultipleWorkers"); - }); - do_test_pending(); - add_test(testStartupEnabled); - add_test(testDisableAfterStartup); - do_initialize_social(true, run_next_test); -} - -function testStartupEnabled() { - // wait on startup before continuing - do_check_eq(Social.providers.length, 2, "two social providers enabled"); - do_check_true(Social.providers[0].enabled, "provider is enabled"); - do_check_true(Social.providers[1].enabled, "provider is enabled"); - run_next_test(); -} - -function testDisableAfterStartup() { - do_wait_observer("social:provider-set", function() { - do_check_eq(Social.enabled, false, "Social is disabled"); - do_check_false(Social.providers[0].enabled, "provider is enabled"); - do_check_false(Social.providers[1].enabled, "provider is enabled"); - do_test_finished(); - run_next_test(); - }); - Social.enabled = false; -} diff --git a/browser/modules/test/unit/social/test_socialDisabledStartup.js b/browser/modules/test/unit/social/test_socialDisabledStartup.js deleted file mode 100644 index b6b2f0cbf69..00000000000 --- a/browser/modules/test/unit/social/test_socialDisabledStartup.js +++ /dev/null @@ -1,35 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -function run_test() { - // we are testing worker startup specifically - Services.prefs.setBoolPref("social.allowMultipleWorkers", true); - do_register_cleanup(function() { - Services.prefs.clearUserPref("social.allowMultipleWorkers"); - }); - do_test_pending(); - add_test(testStartupDisabled); - add_test(testEnableAfterStartup); - do_initialize_social(false, run_next_test); -} - -function testStartupDisabled() { - // wait on startup before continuing - do_check_eq(Social.providers.length, 2, "two social providers available"); - do_check_false(Social.providers[0].enabled, "provider is enabled"); - do_check_false(Social.providers[1].enabled, "provider is enabled"); - run_next_test(); -} - -function testEnableAfterStartup() { - do_wait_observer("social:provider-set", function() { - do_check_true(Social.enabled, "Social is enabled"); - do_check_eq(Social.providers.length, 2, "two social providers available"); - do_check_true(Social.providers[0].enabled, "provider is enabled"); - do_check_true(Social.providers[1].enabled, "provider is enabled"); - do_test_finished(); - run_next_test(); - }); - Social.enabled = true; -} diff --git a/browser/modules/test/unit/social/xpcshell.ini b/browser/modules/test/unit/social/xpcshell.ini deleted file mode 100644 index 632d40533f8..00000000000 --- a/browser/modules/test/unit/social/xpcshell.ini +++ /dev/null @@ -1,8 +0,0 @@ -[DEFAULT] -head = head.js -tail = -firefox-appdir = browser - -[test_social.js] - -[test_socialDisabledStartup.js]