Bug 874566 - Chat boxes should be opened in the currently active window (Linux/Mac), r=markh.
authorFlorian Quèze <florian@queze.net>
Wed, 28 Aug 2013 11:49:48 +0200
changeset 144698 28d046b9513e4e0c3ebd143e95c509e794d6ed33
parent 144697 6882de8ed28aef423d662c83421b5f56c8b53f93
child 144699 2d9dd881ee261ef40cbc7ab9df77bb01c5621feb
push id25172
push useremorley@mozilla.com
push dateWed, 28 Aug 2013 15:20:54 +0000
treeherdermozilla-central@85c8745ac6c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs874566
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 874566 - Chat boxes should be opened in the currently active window (Linux/Mac), r=markh.
browser/base/content/test/social/browser_social_chatwindow.js
toolkit/components/social/MozSocialAPI.jsm
--- a/browser/base/content/test/social/browser_social_chatwindow.js
+++ b/browser/base/content/test/social/browser_social_chatwindow.js
@@ -474,18 +474,48 @@ var tests = {
         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(Social.provider, function() {
             ok(!window.SocialChatBar.hasChats, "first window has no chats");
             ok(secondWindow.SocialChatBar.hasChats, "second window has a chat");
-            secondWindow.close();
-            next();
+
+            // focus the first window, and open yet another chat - it
+            // should open in the first window.
+            waitForFocus(function() {
+              openChat(Social.provider, function() {
+                ok(window.SocialChatBar.hasChats, "first window has chats");
+                window.SocialChatBar.chatbar.removeAll();
+                ok(!window.SocialChatBar.hasChats, "first window has no chats");
+
+                let privateWindow = OpenBrowserWindow({private: true});
+                privateWindow.addEventListener("load", function loadListener() {
+                  privateWindow.removeEventListener("load", loadListener);
+
+                  // open a last chat - the focused window can't accept
+                  // chats (it's a private window), so the chat should open
+                  // in the window that was selected before. This is known
+                  // to be broken on Linux.
+                  openChat(Social.provider, function() {
+                    let os = Services.appinfo.OS;
+                    const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin";
+                    let fn = BROKEN_WM_Z_ORDER ? todo : ok;
+                    fn(window.SocialChatBar.hasChats, "first window has a chat");
+                    window.SocialChatBar.chatbar.removeAll();
+
+                    privateWindow.close();
+                    secondWindow.close();
+                    next();
+                  });
+                });
+              });
+            });
+            window.focus();
           });
         });
       })
     });
   },
   testMultipleProviderChat: function(next) {
     // while pref'd off, we need to set the worker mode to multiple providers
     setWorkerMode(true, function() {
--- a/toolkit/components/social/MozSocialAPI.jsm
+++ b/toolkit/components/social/MozSocialAPI.jsm
@@ -270,22 +270,33 @@ function isWindowGoodForChats(win) {
 }
 
 function findChromeWindowForChats(preferredWindow) {
   if (preferredWindow && isWindowGoodForChats(preferredWindow))
     return preferredWindow;
   // no good - we just use the "most recent" browser window which can host
   // chats (we used to try and "group" all chats in the same browser window,
   // but that didn't work out so well - see bug 835111
+
+  // Try first the most recent window as getMostRecentWindow works
+  // even on platforms where getZOrderDOMWindowEnumerator is broken
+  // (ie. Linux).  This will handle most cases, but won't work if the
+  // foreground window is a popup.
+
+  let mostRecent = Services.wm.getMostRecentWindow("navigator:browser");
+  if (isWindowGoodForChats(mostRecent))
+    return mostRecent;
+
   let topMost, enumerator;
-  // *sigh* - getZOrderDOMWindowEnumerator is broken everywhere other than
-  // Windows.  We use BROKEN_WM_Z_ORDER as that is what the c++ code uses
+  // *sigh* - getZOrderDOMWindowEnumerator is broken except on Mac and
+  // Windows.  We use BROKEN_WM_Z_ORDER as that is what some other code uses
   // and a few bugs recommend searching mxr for this symbol to identify the
   // workarounds - we want this code to be hit in such searches.
-  const BROKEN_WM_Z_ORDER = Services.appinfo.OS != "WINNT";
+  let os = Services.appinfo.OS;
+  const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin";
   if (BROKEN_WM_Z_ORDER) {
     // this is oldest to newest and no way to change the order.
     enumerator = Services.wm.getEnumerator("navigator:browser");
   } else {
     // here we explicitly ask for bottom-to-top so we can use the same logic
     // where BROKEN_WM_Z_ORDER is true.
     enumerator = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", false);
   }