diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc
index 57d0356c0e4e..1acfbbc3c3dc 100644
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -111,7 +111,7 @@
-
+
diff --git a/browser/base/content/browser-social.js b/browser/base/content/browser-social.js
index 1a6de8739c12..a409567c4d11 100644
--- a/browser/base/content/browser-social.js
+++ b/browser/base/content/browser-social.js
@@ -45,9 +45,9 @@ SocialUI = {
if (!Social.initialized) {
Social.init();
- } else if (Social.enabled) {
- // social was previously initialized, so it's not going to notify us of
- // anything, so handle that now.
+ } else if (Social.providers.length > 0) {
+ // Social was initialized during startup in a previous window. If we have
+ // providers enabled initialize the UI for this window.
this.observe(null, "social:providers-changed", null);
this.observe(null, "social:provider-set", Social.provider ? Social.provider.origin : null);
}
diff --git a/browser/base/content/test/social/browser_social_window.js b/browser/base/content/test/social/browser_social_window.js
index bf536e2a59bb..3f90e2232e3c 100644
--- a/browser/base/content/test/social/browser_social_window.js
+++ b/browser/base/content/test/social/browser_social_window.js
@@ -4,6 +4,8 @@
// Test the top-level window UI for social.
+let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
+
// This function should "reset" Social such that the next time Social.init()
// is called (eg, when a new window is opened), it re-performs all
// initialization.
@@ -12,7 +14,6 @@ function resetSocial() {
Social._provider = null;
Social.providers = [];
// *sob* - listeners keep getting added...
- let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
SocialService._providerListeners.clear();
}
@@ -52,9 +53,10 @@ function test() {
}
let tests = {
- // check when social is totally disabled at startup (ie, no providers)
+ // check when social is totally disabled at startup (ie, no providers enabled)
testInactiveStartup: function(cbnext) {
is(Social.providers.length, 0, "needs zero providers to start this test.");
+ ok(!SocialService.hasEnabledProviders, "no providers are enabled");
resetSocial();
openWindowAndWaitForInit(function(w1) {
checkSocialUI(w1);
@@ -67,12 +69,13 @@ let tests = {
});
},
- // Check when providers exist and social is turned on at startup.
+ // Check when providers are enabled and social is turned on at startup.
testEnabledStartup: function(cbnext) {
runSocialTestWithProvider(manifest, function (finishcb) {
resetSocial();
openWindowAndWaitForInit(function(w1) {
ok(Social.enabled, "social is enabled");
+ ok(SocialService.hasEnabledProviders, "providers are enabled");
checkSocialUI(w1);
// now init is complete, open a second window
openWindowAndWaitForInit(function(w2) {
@@ -91,11 +94,13 @@ let tests = {
}, cbnext);
},
- // Check when providers exist but social is turned off at startup.
+ // Check when providers are enabled but social is turned off at startup.
testDisabledStartup: function(cbnext) {
- runSocialTestWithProvider(manifest, function (finishcb) {
+ setManifestPref("social.manifest.test", manifest);
+ SocialService.addProvider(manifest, function (provider) {
Services.prefs.setBoolPref("social.enabled", false);
resetSocial();
+ ok(SocialService.hasEnabledProviders, "providers are enabled");
openWindowAndWaitForInit(function(w1) {
ok(!Social.enabled, "social is disabled");
checkSocialUI(w1);
@@ -109,36 +114,36 @@ let tests = {
ok(Social.enabled, "social is enabled");
checkSocialUI(w2);
checkSocialUI(w1);
- finishcb();
- });
- });
- });
- }, cbnext);
- },
-
- // Check when the last provider is removed.
- testRemoveProvider: function(cbnext) {
- runSocialTestWithProvider(manifest, function (finishcb) {
- openWindowAndWaitForInit(function(w1) {
- checkSocialUI(w1);
- // now init is complete, open a second window
- openWindowAndWaitForInit(function(w2) {
- checkSocialUI(w2);
- // remove the current provider.
- let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
- SocialService.removeProvider(manifest.origin, function() {
- ok(!Social.enabled, "social is disabled");
- is(Social.providers.length, 0, "no providers");
- checkSocialUI(w2);
- checkSocialUI(w1);
- // *sob* - runSocialTestWithProvider's cleanup fails when it can't
- // remove the provider, so re-add it.
- SocialService.addProvider(manifest, function() {
- finishcb();
+ SocialService.removeProvider(manifest.origin, function() {
+ Services.prefs.clearUserPref("social.manifest.test");
+ cbnext();
});
});
});
});
}, cbnext);
},
+
+ // Check when the last provider is disabled.
+ testRemoveProvider: function(cbnext) {
+ setManifestPref("social.manifest.test", manifest);
+ SocialService.addProvider(manifest, function (provider) {
+ openWindowAndWaitForInit(function(w1) {
+ checkSocialUI(w1);
+ // now init is complete, open a second window
+ openWindowAndWaitForInit(function(w2) {
+ checkSocialUI(w2);
+ // disable the current provider.
+ SocialService.removeProvider(manifest.origin, function() {
+ ok(!Social.enabled, "social is disabled");
+ is(Social.providers.length, 0, "no providers");
+ checkSocialUI(w2);
+ checkSocialUI(w1);
+ Services.prefs.clearUserPref("social.manifest.test");
+ cbnext();
+ });
+ });
+ });
+ }, cbnext);
+ },
}
diff --git a/browser/base/content/test/social/head.js b/browser/base/content/test/social/head.js
index 9a5cf06ffca3..9dc0e87139ed 100644
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -194,6 +194,7 @@ function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
// A fairly large hammer which checks all aspects of the SocialUI for
// internal consistency.
function checkSocialUI(win) {
+ let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
win = win || window;
let doc = win.document;
let provider = Social.provider;
@@ -201,6 +202,14 @@ function checkSocialUI(win) {
let active = Social.providers.length > 0 && !win.SocialUI._chromeless &&
!PrivateBrowsingUtils.isWindowPrivate(win);
+ // if we have enabled providers, we should also have instances of those
+ // providers
+ if (SocialService.hasEnabledProviders) {
+ ok(Social.providers.length > 0, "providers are enabled");
+ } else {
+ is(Social.providers.length, 0, "providers are not enabled");
+ }
+
// some local helpers to avoid log-spew for the many checks made here.
let numGoodTests = 0, numTests = 0;
function _ok(what, msg) {
@@ -246,6 +255,7 @@ function checkSocialUI(win) {
// and for good measure, check all the social commands.
isbool(!doc.getElementById("Social:Toggle").hidden, active, "Social:Toggle visible?");
+ isbool(!doc.getElementById("Social:ToggleSidebar").hidden, enabled, "Social:ToggleSidebar visible?");
isbool(!doc.getElementById("Social:ToggleNotifications").hidden, enabled, "Social:ToggleNotifications visible?");
isbool(!doc.getElementById("Social:FocusChat").hidden, enabled, "Social:FocusChat visible?");
isbool(doc.getElementById("Social:FocusChat").getAttribute("disabled"), enabled ? "false" : "true", "Social:FocusChat disabled?");
diff --git a/browser/modules/Social.jsm b/browser/modules/Social.jsm
index 8a595923eaf2..bbf528fcac10 100644
--- a/browser/modules/Social.jsm
+++ b/browser/modules/Social.jsm
@@ -158,8 +158,9 @@ this.Social = {
return;
}
this.initialized = true;
-
- if (SocialService.enabled) {
+ // if SocialService.hasEnabledProviders, retreive the providers so the
+ // front-end can generate UI
+ if (SocialService.hasEnabledProviders) {
// Retrieve the current set of providers, and set the current provider.
SocialService.getOrderedProviderList(function (providers) {
Social._updateProviderCache(providers);
diff --git a/toolkit/components/social/SocialService.jsm b/toolkit/components/social/SocialService.jsm
index cd53edb0c389..6df13e068e3c 100644
--- a/toolkit/components/social/SocialService.jsm
+++ b/toolkit/components/social/SocialService.jsm
@@ -350,6 +350,16 @@ function schedule(callback) {
// Public API
this.SocialService = {
+ get hasEnabledProviders() {
+ // used as an optimization during startup, can be used to check if further
+ // initialization should be done (e.g. creating the instances of
+ // SocialProvider and turning on UI). ActiveProviders may have changed and
+ // not yet flushed so we check the active providers array
+ for (let p in ActiveProviders._providers) {
+ return true;
+ };
+ return false;
+ },
get enabled() {
return SocialServiceInternal.enabled;
},