bug 891221 add tests for chat from multiple providers, r=markh
authorShane Caraveo <scaraveo@mozilla.com>
Wed, 21 Aug 2013 11:38:33 -0700
changeset 143694 d0064759d81786c6f09df497380674adcb546c13
parent 143693 373a939065397a614f90804e7f35f5db7fe3b571
child 143695 71dbfbd1449bb6a9b3d05ef9fe1328374b16a707
push id25135
push userryanvm@gmail.com
push dateWed, 21 Aug 2013 21:13:17 +0000
treeherdermozilla-central@438cc1848c96 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs891221
milestone26.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 891221 add tests for chat from multiple providers, r=markh
browser/base/content/test/social/browser_social_chatwindow.js
browser/base/content/test/social/head.js
--- a/browser/base/content/test/social/browser_social_chatwindow.js
+++ b/browser/base/content/test/social/browser_social_chatwindow.js
@@ -1,32 +1,86 @@
 /* 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/. */
 
+let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
+
+let manifests = [
+  {
+    name: "provider@example.com",
+    origin: "https://example.com",
+    sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?example.com",
+    workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
+    iconURL: "chrome://branding/content/icon48.png"
+  },
+  {
+    name: "provider@test1",
+    origin: "https://test1.example.com",
+    sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?test1",
+    workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
+    iconURL: "chrome://branding/content/icon48.png"
+  },
+  {
+    name: "provider@test2",
+    origin: "https://test2.example.com",
+    sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?test2",
+    workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js",
+    iconURL: "chrome://branding/content/icon48.png"
+  }
+];
+
+let chatId = 0;
+function openChat(provider, callback) {
+  let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
+  let port = provider.getWorkerPort();
+  port.onmessage = function(e) {
+    if (e.data.topic == "got-chatbox-message") {
+      port.close();
+      callback();
+    }
+  }
+  let url = chatUrl + "?" + (chatId++);
+  port.postMessage({topic: "test-init"});
+  port.postMessage({topic: "test-worker-chat", data: url});
+  gURLsNotRemembered.push(url);
+}
+
+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 manifest = { // normal provider
-    name: "provider 1",
-    origin: "https://example.com",
-    sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
-    workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
-    iconURL: "https://example.com/browser/browser/base/content/test/moz.png"
-  };
   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();
   };
-  runSocialTestWithProvider(manifest, function (finishcb) {
+  runSocialTestWithProvider(manifests, function (finishcb) {
     runSocialTests(tests, undefined, postSubTest, function() {
       window.moveTo(oldleft, window.screenY)
       window.resizeTo(oldwidth, window.outerHeight);
       finishcb();
     });
   });
 }
 
@@ -142,17 +196,17 @@ var tests = {
           port.close();
           next();
           break;
       }
     }
     maybeOpenAnother();
   },
   testWorkerChatWindow: function(next) {
-    const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
+    const chatUrl = Social.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
     let chats = document.getElementById("pinnedchats");
     let port = Social.provider.getWorkerPort();
     ok(port, "provider has a port");
     port.postMessage({topic: "test-init"});
     port.onmessage = function (e) {
       let topic = e.data.topic;
       switch (topic) {
         case "got-chatbox-message":
@@ -379,17 +433,17 @@ var tests = {
           });
       }
     }
     port.postMessage({topic: "test-init", data: { id: 1 }});
   },
 
   testSecondTopLevelWindow: function(next) {
     // Bug 817782 - check chats work in new top-level windows.
-    const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
+    const chatUrl = Social.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
     let port = Social.provider.getWorkerPort();
     let secondWindow;
     port.onmessage = function(e) {
       if (e.data.topic == "test-init-done") {
         secondWindow = OpenBrowserWindow();
         secondWindow.addEventListener("load", function loadListener() {
           secondWindow.removeEventListener("load", loadListener);
           port.postMessage({topic: "test-worker-chat", data: chatUrl});
@@ -402,61 +456,75 @@ var tests = {
       }
     }
     port.postMessage({topic: "test-init"});
   },
 
   testChatWindowChooser: function(next) {
     // Tests that when a worker creates a chat, it is opened in the correct
     // window.
-    const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
-    let chatId = 1;
-    let port = Social.provider.getWorkerPort();
-    port.postMessage({topic: "test-init"});
-
-    function openChat(callback) {
-      port.onmessage = function(e) {
-        if (e.data.topic == "got-chatbox-message")
-          callback();
-      }
-      let url = chatUrl + "?" + (chatId++);
-      port.postMessage({topic: "test-worker-chat", data: url});
-    }
-
     // open a chat (it will open in the main window)
     ok(!window.SocialChatBar.hasChats, "first window should start with no chats");
-    openChat(function() {
+    openChat(Social.provider, function() {
       ok(window.SocialChatBar.hasChats, "first window has the chat");
       // create a second window - this will be the "most recent" and will
       // therefore be the window that hosts the new chat (see bug 835111)
       let secondWindow = OpenBrowserWindow();
       secondWindow.addEventListener("load", function loadListener() {
         secondWindow.removeEventListener("load", loadListener);
         ok(!secondWindow.SocialChatBar.hasChats, "second window has no chats");
-        openChat(function() {
+        openChat(Social.provider, function() {
           ok(secondWindow.SocialChatBar.hasChats, "second window now has chats");
           is(window.SocialChatBar.chatbar.childElementCount, 1, "first window still has 1 chat");
           window.SocialChatBar.chatbar.removeAll();
           // now open another chat - it should still open in the second.
-          openChat(function() {
+          openChat(Social.provider, function() {
             ok(!window.SocialChatBar.hasChats, "first window has no chats");
             ok(secondWindow.SocialChatBar.hasChats, "second window has a chat");
             secondWindow.close();
-            port.close();
             next();
           });
         });
       })
     });
   },
+  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");
+          });
+        });
+      });
+    });
+  },
 
   // XXX - note this must be the last test until we restore the login state
   // between tests...
   testCloseOnLogout: function(next) {
-    const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
+    const chatUrl = Social.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
     let port = Social.provider.getWorkerPort();
     ok(port, "provider has a port");
     let opened = false;
     port.onmessage = function (e) {
       let topic = e.data.topic;
       switch (topic) {
         case "test-init-done":
           info("open first chat window");
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -412,18 +412,18 @@ function get3ChatsForCollapsing(mode, cb
         }, mode);
       }, mode);
     });
   }, mode);
 }
 
 function makeChat(mode, uniqueid, cb) {
   info("making a chat window '" + uniqueid +"'");
-  const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
   let provider = Social.provider;
+  const chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
   let isOpened = window.SocialChatBar.openChat(provider, chatUrl + "?id=" + uniqueid, function(chat) {
     info("chat window has opened");
     // we can't callback immediately or we might close the chat during
     // this event which upsets the implementation - it is only 1/2 way through
     // handling the load event.
     chat.document.title = uniqueid;
     executeSoon(cb);
   }, mode);