Bug 906839 - enable by default social.allowMultipleWorkers - update tests to work pref'd on and fix a missing update to the worker state, r=markh.
☠☠ backed out by 45a18b183676 ☠ ☠
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 24 Oct 2013 15:53:36 +0200
changeset 165903 9eaf00ec189aa84b2f03a8249854fad9b2ccb441
parent 165902 fb8fabe1e2bc327dd7fba6ba6dd5eacebbe3ac0b
child 165904 6c3eb5fd4ade2bdc433f1a9015106e43153b353e
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs906839
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 906839 - enable by default social.allowMultipleWorkers - update tests to work pref'd on and fix a missing update to the worker state, r=markh.
browser/base/content/test/social/browser_social_chatwindow.js
browser/base/content/test/social/social_worker.js
browser/modules/Social.jsm
toolkit/components/social/FrameWorker.jsm
toolkit/components/social/test/browser/browser_SocialProvider.js
--- a/browser/base/content/test/social/browser_social_chatwindow.js
+++ b/browser/base/content/test/social/browser_social_chatwindow.js
@@ -46,42 +46,37 @@ function openChat(provider, callback) {
 
 function waitPrefChange(cb) {
   Services.prefs.addObserver("social.enabled", function prefObserver(subject, topic, data) {
     Services.prefs.removeObserver("social.enabled", prefObserver);
     executeSoon(cb);
   }, false);
 }
 
-function setWorkerMode(multiple, cb) {
-  waitPrefChange(function() {
-    if (multiple)
-      Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
-    else
-      Services.prefs.clearUserPref("social.allowMultipleWorkers");
-    waitPrefChange(cb);
-    Social.enabled = true;
-  });
-  Social.enabled = false;
-}
-
 function test() {
   requestLongerTimeout(2); // only debug builds seem to need more time...
   waitForExplicitFinish();
 
   let oldwidth = window.outerWidth; // we futz with these, so we restore them
   let oldleft = window.screenX;
   window.moveTo(0, window.screenY)
   let postSubTest = function(cb) {
     let chats = document.getElementById("pinnedchats");
     ok(chats.children.length == 0, "no chatty children left behind");
     cb();
   };
+  // always run chat tests with multiple workers.
+  Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
   runSocialTestWithProvider(manifests, function (finishcb) {
+    ok(Social.enabled, "Social is enabled");
+    ok(Social.providers[0].getWorkerPort(), "provider 0 has port");
+    ok(Social.providers[1].getWorkerPort(), "provider 1 has port");
+    ok(Social.providers[2].getWorkerPort(), "provider 2 has port");
     runSocialTests(tests, undefined, postSubTest, function() {
+      Services.prefs.clearUserPref("social.allowMultipleWorkers");
       window.moveTo(oldleft, window.screenY)
       window.resizeTo(oldwidth, window.outerHeight);
       finishcb();
     });
   });
 }
 
 var tests = {
@@ -512,40 +507,41 @@ var tests = {
             });
             window.focus();
           });
         });
       })
     });
   },
   testMultipleProviderChat: function(next) {
-    // while pref'd off, we need to set the worker mode to multiple providers
-    setWorkerMode(true, function() {
-      // test incomming chats from all providers
-      openChat(Social.providers[0], function() {
-        openChat(Social.providers[1], function() {
-          openChat(Social.providers[2], function() {
-            let chats = document.getElementById("pinnedchats");
-            waitForCondition(function() chats.children.length == Social.providers.length,
-              function() {
-                ok(true, "one chat window per provider opened");
-                // test logout of a single provider
-                let provider = Social.providers[0];
-                let port = provider.getWorkerPort();
-                port.postMessage({topic: "test-logout"});
-                waitForCondition(function() chats.children.length == Social.providers.length - 1,
-                  function() {
-                    port.close();
-                    chats.removeAll();
-                    ok(!chats.selectedChat, "chats are all closed");
-                    setWorkerMode(false, next);
-                  },
-                  "chat window didn't close");
-              }, "chat windows did not open");
-          });
+    // test incomming chats from all providers
+    openChat(Social.providers[0], function() {
+      openChat(Social.providers[1], function() {
+        openChat(Social.providers[2], function() {
+          let chats = document.getElementById("pinnedchats");
+          waitForCondition(function() chats.children.length == Social.providers.length,
+            function() {
+              ok(true, "one chat window per provider opened");
+              // test logout of a single provider
+              let provider = Social.providers[2];
+              let port = provider.getWorkerPort();
+              port.postMessage({topic: "test-logout"});
+              waitForCondition(function() chats.children.length == Social.providers.length - 1,
+                function() {
+                  chats.removeAll();
+                  waitForCondition(function() chats.children.length == 0,
+                                   function() {
+                                    ok(!chats.selectedChat, "multiprovider chats are all closed");
+                                    port.close();
+                                    next();
+                                   },
+                                   "chat windows didn't close");
+                },
+                "chat window didn't close");
+            }, "chat windows did not open");
         });
       });
     });
   },
 
   // XXX - note this must be the last test until we restore the login state
   // between tests...
   testCloseOnLogout: function(next) {
@@ -573,11 +569,15 @@ var tests = {
           } else {
             // open a second chat window
             opened = true;
             port.postMessage({topic: "test-worker-chat", data: chatUrl+"?id=1"});
           }
           break;
       }
     }
+    // make sure a user profile is set for this provider as chat windows are
+    // only closed on *change* of the profile data rather than merely setting
+    // profile data.
+    port.postMessage({topic: "test-set-profile"});
     port.postMessage({topic: "test-init"});
   }
 }
--- a/browser/base/content/test/social/social_worker.js
+++ b/browser/base/content/test/social/social_worker.js
@@ -79,32 +79,34 @@ onconnect = function(e) {
       case "test-worker-chat":
         apiPort.postMessage({topic: "social.request-chat", data: event.data.data });
         break;
       case "social.initialize":
         // This is the workerAPI port, respond and set up a notification icon.
         // For multiprovider tests, we support acting like different providers
         // based on the domain we load from.
         apiPort = port;
+        // purposely fall through and set the profile on initialization
+      case "test-set-profile":
         let profile;
         if (location.href.indexOf("https://test1.example.com") == 0) {
           profile = {
             portrait: "https://test1.example.com/portrait.jpg",
             userName: "tester",
             displayName: "Test1 User",
           };
         } else {
           profile = {
             portrait: "https://example.com/portrait.jpg",
             userName: "trickster",
             displayName: "Kuma Lisa",
             profileURL: "http://en.wikipedia.org/wiki/Kuma_Lisa"
           };
         }
-        port.postMessage({topic: "social.user-profile", data: profile});
+        apiPort.postMessage({topic: "social.user-profile", data: profile});
         break;
       case "test-ambient-notification":
         apiPort.postMessage({topic: "social.ambient-notification", data: event.data.data});
         break;
       case "test-isVisible":
         sidebarPort.postMessage({topic: "test-isVisible"});
         break;
       case "test-isVisible-response":
--- a/browser/modules/Social.jsm
+++ b/browser/modules/Social.jsm
@@ -90,18 +90,21 @@ function promiseGetAnnotation(aURI) {
 
 this.Social = {
   initialized: false,
   lastEventReceived: 0,
   providers: [],
   _disabledForSafeMode: false,
 
   get allowMultipleWorkers() {
-    return Services.prefs.prefHasUserValue("social.allowMultipleWorkers") &&
-           Services.prefs.getBoolPref("social.allowMultipleWorkers");
+    try {
+      return Services.prefs.getBoolPref("social.allowMultipleWorkers");
+    } catch(e) {
+      return false;
+    }
   },
 
   get _currentProviderPref() {
     try {
       return Services.prefs.getComplexValue("social.provider.current",
                                             Ci.nsISupportsString).data;
     } catch (ex) {}
     return null;
@@ -136,16 +139,17 @@ this.Social = {
 
     if (this._provider) {
       this._provider.enabled = true;
       this._currentProviderPref = this._provider.origin;
     }
     let enabled = !!provider;
     if (enabled != SocialService.enabled) {
       SocialService.enabled = enabled;
+      this._updateWorkerState(enabled);
     }
 
     let origin = this._provider && this._provider.origin;
     Services.obs.notifyObservers(null, "social:provider-set", origin);
   },
 
   get defaultProvider() {
     if (this.providers.length == 0)
--- a/toolkit/components/social/FrameWorker.jsm
+++ b/toolkit/components/social/FrameWorker.jsm
@@ -193,25 +193,29 @@ function makeRemoteBrowser() {
   // Create a HTML iframe with a chrome URL, then this can host the browser.
   let iframe = hiddenDoc.createElementNS(HTML_NS, "iframe");
   iframe.setAttribute("src", "chrome://global/content/mozilla.xhtml");
   iframe.addEventListener("load", function onLoad() {
     iframe.removeEventListener("load", onLoad, true);
     let browser = iframe.contentDocument.createElementNS(XUL_NS, "browser");
     browser.setAttribute("type", "content");
     browser.setAttribute("disableglobalhistory", "true");
-    let remote;
     // for now we use the same preference that enabled multiple workers - the
     // idea is that there is no point in having people help test multiple
     // "old" frameworkers - so anyone who wants multiple workers is forced to
     // help us test remote frameworkers too.
-    if (Services.prefs.prefHasUserValue("social.allowMultipleWorkers") &&
-        Services.prefs.getBoolPref("social.allowMultipleWorkers")) {
+    let useMultiProvider;
+    try {
+      useMultiProvider = Services.prefs.getBoolPref("social.allowMultipleWorkers");
+    } catch(e) {
+      useMultiProvider = false;
+    }
+    if (useMultiProvider)
       browser.setAttribute("remote", "true");
-    }
+
     iframe.contentDocument.documentElement.appendChild(browser);
     deferred.resolve(browser);
   }, true);
   hiddenDoc.documentElement.appendChild(iframe);
   return deferred.promise;
 }
 
 function notifyWorkerError(origin) {
--- a/toolkit/components/social/test/browser/browser_SocialProvider.js
+++ b/toolkit/components/social/test/browser/browser_SocialProvider.js
@@ -57,17 +57,22 @@ let tests = {
     // add another provider, test both workers
     let manifest = {
       origin: 'http://test2.example.com',
       name: "Example Provider 2",
       workerURL: "http://test2.example.com/browser/toolkit/components/social/test/browser/worker_social.js"
     };
     SocialService.addProvider(manifest, function (provider2) {
       ok(provider.enabled, "provider is initially enabled");
-      ok(!provider2.enabled, "provider2 is not initially enabled");
+      try {
+        is(provider2.enabled, Services.prefs.getBoolPref("social.allowMultipleWorkers"), "provider2 is enabled status is correct");
+      } catch(e) {
+        // default is false if pref is not set
+        ok(!provider2.enabled, "provider2 is not initially enabled");
+      }
       provider2.enabled = true;
       let port = provider.getWorkerPort();
       let port2 = provider2.getWorkerPort();
       ok(port, "have port for provider");
       ok(port2, "have port for provider2");
       port.onmessage = function(e) {
         if (e.data.topic == "test-initialization-complete") {
           ok(true, "first provider initialized");