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, a=bajaj.
authorShane Caraveo <scaraveo@mozilla.com>
Thu, 31 Oct 2013 10:59:35 +1100
changeset 166531 e75cd4c5c2a182b82bff4b8980520f489f101200
parent 166530 bedeac830273c18e25bc5c573ef549ad7d03c568
child 166532 668f855471bb1e0d71e17afd432423b1c12f8af3
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, bajaj
bugs906839
milestone27.0a2
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, a=bajaj.
browser/app/profile/firefox.js
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/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1311,16 +1311,18 @@ pref("shumway.disabled", true);
 pref("image.mem.max_decoded_image_kb", 256000);
 
 // Default social providers
 pref("social.manifest.facebook", "{\"origin\":\"https://www.facebook.com\",\"name\":\"Facebook Messenger\",\"workerURL\":\"https://www.facebook.com/desktop/fbdesktop2/socialfox/fbworker.js.php\",\"shareURL\":\"https://www.facebook.com/sharer/sharer.php?u=%{url}\",\"iconURL\":\"data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAAX0lEQVQ4jWP4%2F%2F8%2FAyUYTFhHzjgDxP9JxGeQDSBVMxgTbUBCxer%2Fr999%2BQ8DJBuArJksA9A10s8AXIBoA0B%2BR%2FY%2FjD%2BEwoBoA1yT5v3PbdmCE8MAshhID%2FUMoDgzUYIBj0Cgi7ar4coAAAAASUVORK5CYII%3D\",\"sidebarURL\":\"https://www.facebook.com/desktop/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+9eBLRPg0q2+s5UvHG6bMNqJYPHw7nXutxZYvIIiMoCSgbrPVX/fv7syS+3AKfC5MOmF4iRpP6RjrId8O5vrNhS1NpUWQLUholUr6muXEoatP3emrWNR9e/avk9R8P+HuxNypPkrk93pGdnK0VtXemaN6UdOHo55vdE5b/0NKx+K4AxtAAAAABJRU5ErkJggg==\", \"description\":\"Keep up with friends wherever you go on the web.\",\"author\":\"Facebook\",\"homepageURL\":\"https://www.facebook.com/about/messenger-for-firefox\",\"builtin\":\"true\"}");
 
 pref("social.sidebar.open", true);
 pref("social.sidebar.unload_timeout_ms", 10000);
 
+pref("social.allowMultipleWorkers", true);
+
 pref("dom.identity.enabled", false);
 
 // Turn on the CSP 1.0 parser for Content Security Policy headers
 pref("security.csp.speccompliant", true);
 
 // Block insecure active content on https pages
 pref("security.mixed_content.block_active_content", true);
 
--- 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,17 @@ 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");
+    return Services.prefs.getBoolPref("social.allowMultipleWorkers");
   },
 
   get _currentProviderPref() {
     try {
       return Services.prefs.getComplexValue("social.provider.current",
                                             Ci.nsISupportsString).data;
     } catch (ex) {}
     return null;
@@ -136,16 +135,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
@@ -194,25 +194,23 @@ 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")) {
+    if (Services.prefs.getBoolPref("social.allowMultipleWorkers"))
       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,17 @@ 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");
+      is(provider2.enabled, Services.prefs.getBoolPref("social.allowMultipleWorkers"), "provider2 is enabled status is correct");
       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");