bug 864505 fix appearance of selected chat titlebar, r=markh
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 06 May 2013 12:48:57 -0700
changeset 142016 d775de2d818f31e3d9c23f4b33aca2c1bd7ad971
parent 142015 23bb737193ed8d934dd77a1dcc23752f13b67e13
child 142017 50c905b6d44ed1a01b2aed4eacce4c7e5e48d10e
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs864505
milestone23.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 864505 fix appearance of selected chat titlebar, r=markh
browser/base/content/socialchat.xml
browser/base/content/test/social/browser_social_chatwindowfocus.js
--- a/browser/base/content/socialchat.xml
+++ b/browser/base/content/socialchat.xml
@@ -115,17 +115,17 @@
       <method name="toggle">
         <body><![CDATA[
           this.minimized = !this.minimized;
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
-      <handler event="focus">
+      <handler event="focus" phase="capturing">
         this.parentNode.selectedChat = this;
       </handler>
       <handler event="DOMTitleChanged"><![CDATA[
         this.setAttribute('label', this.iframe.contentDocument.title);
         this.parentNode.updateTitlebar(this);
       ]]></handler>
       <handler event="DOMLinkAdded"><![CDATA[
         // much of this logic is from DOMLinkHandler in browser.js
--- a/browser/base/content/test/social/browser_social_chatwindowfocus.js
+++ b/browser/base/content/test/social/browser_social_chatwindowfocus.js
@@ -60,22 +60,26 @@ function startTestAndWaitForSidebar(call
     if (!doneCallback)
       callback(port);
     doneCallback = true;
   }
   port.onmessage = function(e) {
     let topic = e.data.topic;
     switch (topic) {
       case "got-sidebar-message":
+        // if sidebar loaded too fast, we need a backup ping
+      case "got-isVisible-response":
         isSidebarLoaded = true;
         maybeCallback();
         break;
       case "test-init-done":
         if (isSidebarLoaded)
           maybeCallback();
+        else
+          port.postMessage({topic: "test-isVisible"});
         break;
     }
   }
   port.postMessage({topic: "test-init"});
 }
 
 let manifest = { // normal provider
   name: "provider 1",
@@ -97,17 +101,17 @@ function test() {
   tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
     tab.linkedBrowser.removeEventListener("load", tabLoad, true);
     // before every test we focus the input field.
     let preSubTest = function(cb) {
       // XXX - when bug 604289 is fixed it should be possible to just do:
       // tab.linkedBrowser.contentWindow.focus()
       // but instead we must do:
       tab.linkedBrowser.contentDocument.getElementById("theinput").focus();
-      cb();
+      waitForCondition(function() isTabFocused(), cb, "tab should have focus");
     }
     let postSubTest = function(cb) {
       window.SocialChatBar.chatbar.removeAll();
       cb();
     }
     // and run the tests.
     runSocialTestWithProvider(manifest, function (finishcb) {
       runSocialTests(tests, preSubTest, postSubTest, function () {
@@ -133,50 +137,59 @@ var tests = {
         is(SocialChatBar.chatbar.childElementCount, 1, "exactly 1 chat open");
         ok(isTabFocused(), "tab should still be focused");
         // re-request the same chat via a message.
         openChatViaSidebarMessage(port, {stealFocus: 1}, function() {
           is(SocialChatBar.chatbar.childElementCount, 1, "still exactly 1 chat open");
           ok(isTabFocused(), "tab should still be focused");
           // re-request the same chat via user event.
           openChatViaUser();
-          is(SocialChatBar.chatbar.childElementCount, 1, "still exactly 1 chat open");
-          // should now be focused
-          ok(isChatFocused(SocialChatBar.chatbar.firstElementChild), "chat should be focused");
-          next();
+          waitForCondition(function() isChatFocused(SocialChatBar.chatbar.selectedChat),
+                           function() {
+            is(SocialChatBar.chatbar.childElementCount, 1, "still exactly 1 chat open");
+            is(SocialChatBar.chatbar.selectedChat, SocialChatBar.chatbar.firstElementChild, "chat should be selected");
+            next();
+          }, "chat should be focused");
         });
       });
     });
   },
 
   // In this test we arrange for the sidebar to open the chat via a simulated
   // click.  This should cause the new chat to be opened and focused.
   testFocusWhenViaUser: function(next) {
     startTestAndWaitForSidebar(function(port) {
       openChatViaUser();
       ok(SocialChatBar.chatbar.firstElementChild, "chat opened");
-      ok(isChatFocused(SocialChatBar.chatbar.firstElementChild), "chat should be focused");
-      next();
+      waitForCondition(function() isChatFocused(SocialChatBar.chatbar.selectedChat),
+                       function() {
+        is(SocialChatBar.chatbar.selectedChat, SocialChatBar.chatbar.firstElementChild, "chat is selected");
+        next();
+      }, "chat should be focused");
     });
   },
 
   // Open a chat via the worker - it will open minimized and not have focus.
   // Then open the same chat via a sidebar message - it will be restored but
   // should still not have grabbed focus.
   testNoFocusOnAutoRestore: function(next) {
     const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html?id=1";
     let chatbar = SocialChatBar.chatbar;
     startTestAndWaitForSidebar(function(port) {
       openChatViaWorkerMessage(port, chatUrl, function() {
         is(chatbar.childElementCount, 1, "exactly 1 chat open");
         ok(chatbar.firstElementChild.minimized, "chat is minimized");
+        // bug 865086 opening minimized still sets the window as selected
+        todo(chatbar.selectedChat != chatbar.firstElementChild, "chat is not selected");
         ok(isTabFocused(), "tab should be focused");
         openChatViaSidebarMessage(port, {stealFocus: 1, id: 1}, function() {
           is(chatbar.childElementCount, 1, "still 1 chat open");
           ok(!chatbar.firstElementChild.minimized, "chat no longer minimized");
+          // bug 865086 because we marked it selected on open, it still is
+          todo(chatbar.selectedChat != chatbar.firstElementChild, "chat is not selected");
           ok(isTabFocused(), "tab should still be focused");
           next();
         });
       });
     });
   },
 
   // Here we open a chat, which will not be focused.  Then we minimize it and
@@ -187,40 +200,52 @@ var tests = {
         ok(true, "got chatbox message");
         ok(isTabFocused(), "tab should still be focused");
         let chatbox = SocialChatBar.chatbar.firstElementChild;
         ok(chatbox, "chat opened");
         chatbox.minimized = true;
         ok(isTabFocused(), "tab should still be focused");
         // pretend we clicked on the titlebar
         chatbox.onTitlebarClick({button: 0});
-        ok(!chatbox.minimized, "chat should have been restored");
-        ok(isChatFocused(chatbox), "chat should be focused");
-        next();
+        waitForCondition(function() isChatFocused(SocialChatBar.chatbar.selectedChat),
+                         function() {
+          ok(!chatbox.minimized, "chat should have been restored");
+          ok(isChatFocused(chatbox), "chat should be focused");
+          is(chatbox, SocialChatBar.chatbar.selectedChat, "chat is marked selected");
+          next();
+        }, "chat should have focus");
       });
     });
   },
 
   // Open 2 chats and give 1 focus.  Minimize the focused one - the second
   // should get focus.
   testMinimizeFocused: function(next) {
     let chatbar = SocialChatBar.chatbar;
     startTestAndWaitForSidebar(function(port) {
       openChatViaSidebarMessage(port, {stealFocus: 1, id: 1}, function() {
         let chat1 = chatbar.firstElementChild;
         openChatViaSidebarMessage(port, {stealFocus: 1, id: 2}, function() {
           is(chatbar.childElementCount, 2, "exactly 2 chats open");
           let chat2 = chat1.nextElementSibling || chat1.previousElementSibling;
           chatbar.selectedChat = chat1;
           chatbar.focus();
-          ok(isChatFocused(chat1), "first chat should be focused");
-          chat1.minimized = true;
-          // minimizing the chat with focus should give it to another.
-          ok(isChatFocused(chat2), "second chat should be focused");
-          next();
+          waitForCondition(function() isChatFocused(chat1),
+                           function() {
+            is(chat1, SocialChatBar.chatbar.selectedChat, "chat1 is marked selected");
+            isnot(chat2, SocialChatBar.chatbar.selectedChat, "chat2 is not marked selected");
+            chat1.minimized = true;
+            waitForCondition(function() isChatFocused(chat2),
+                             function() {
+              // minimizing the chat with focus should give it to another.
+              isnot(chat1, SocialChatBar.chatbar.selectedChat, "chat1 is not marked selected");
+              is(chat2, SocialChatBar.chatbar.selectedChat, "chat2 is marked selected");
+              next();
+            }, "chat2 should have focus");
+          }, "chat1 should have focus");
         });
       });
     });
   },
 
   // Open 2 chats, select (but not focus) one, then re-request it be
   // opened via a message.  Focus should not move.
   testReopenNonFocused: function(next) {
@@ -264,40 +289,42 @@ var tests = {
     let chatbar = SocialChatBar.chatbar;
     startTestAndWaitForSidebar(function(port) {
       openChatViaSidebarMessage(port, {id: 1}, function() {
         let chat1 = chatbar.firstElementChild;
         openChatViaSidebarMessage(port, {id: 2}, function() {
           let chat2 = chat1.nextElementSibling || chat1.previousElementSibling;
           chatbar.selectedChat = chat2;
           chatbar.focus();
-          ok(isChatFocused(chat2), "new chat is focused");
-          // Our chats have 3 focusable elements, so it takes 4 TABs to move
-          // to the new chat.
-          sendTabAndWaitForFocus(chat2, "input1", function() {
-            is(chat2.iframe.contentDocument.activeElement.getAttribute("id"), "input1",
-               "first input field has focus");
-            ok(isChatFocused(chat2), "new chat still focused after first tab");
-            sendTabAndWaitForFocus(chat2, "input2", function() {
-              ok(isChatFocused(chat2), "new chat still focused after tab");
-              is(chat2.iframe.contentDocument.activeElement.getAttribute("id"), "input2",
-                 "second input field has focus");
-              sendTabAndWaitForFocus(chat2, "iframe", function() {
+          waitForCondition(function() isChatFocused(chatbar.selectedChat),
+                           function() {
+            // Our chats have 3 focusable elements, so it takes 4 TABs to move
+            // to the new chat.
+            sendTabAndWaitForFocus(chat2, "input1", function() {
+              is(chat2.iframe.contentDocument.activeElement.getAttribute("id"), "input1",
+                 "first input field has focus");
+              ok(isChatFocused(chat2), "new chat still focused after first tab");
+              sendTabAndWaitForFocus(chat2, "input2", function() {
                 ok(isChatFocused(chat2), "new chat still focused after tab");
-                is(chat2.iframe.contentDocument.activeElement.getAttribute("id"), "iframe",
-                   "iframe has focus");
-                // this tab now should move to the next chat, but focus the
-                // document element itself (hence the null eltid)
-                sendTabAndWaitForFocus(chat1, null, function() {
-                  ok(isChatFocused(chat1), "first chat is focused");
-                  next();
+                is(chat2.iframe.contentDocument.activeElement.getAttribute("id"), "input2",
+                   "second input field has focus");
+                sendTabAndWaitForFocus(chat2, "iframe", function() {
+                  ok(isChatFocused(chat2), "new chat still focused after tab");
+                  is(chat2.iframe.contentDocument.activeElement.getAttribute("id"), "iframe",
+                     "iframe has focus");
+                  // this tab now should move to the next chat, but focus the
+                  // document element itself (hence the null eltid)
+                  sendTabAndWaitForFocus(chat1, null, function() {
+                    ok(isChatFocused(chat1), "first chat is focused");
+                    next();
+                  });
                 });
               });
             });
-          });
+          }, "chat should have focus");
         });
       });
     });
   },
 
   // Open a chat and focus an element other than the first. Move focus to some
   // other item (the tab itself in this case), then focus the chatbar - the
   // same element that was previously focused should still have focus.
@@ -305,23 +332,30 @@ var tests = {
     let chatbar = SocialChatBar.chatbar;
     startTestAndWaitForSidebar(function(port) {
       openChatViaUser();
       let chat = chatbar.firstElementChild;
       // need to wait for the content to load before we can focus it.
       chat.addEventListener("DOMContentLoaded", function DOMContentLoaded() {
         chat.removeEventListener("DOMContentLoaded", DOMContentLoaded);
         chat.iframe.contentDocument.getElementById("input2").focus();
-        is(chat.iframe.contentDocument.activeElement.getAttribute("id"), "input2",
-           "correct input field has focus");
-        // set focus to the tab.
-        let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
-        Services.focus.moveFocus(tabb.contentWindow, null, Services.focus.MOVEFOCUS_ROOT, 0);
-        ok(isTabFocused(), "tab took focus");
-        chatbar.focus();
-        ok(isChatFocused(chat), "chat took focus");
-        is(chat.iframe.contentDocument.activeElement.getAttribute("id"), "input2",
-           "correct input field still has focus");
-        next();
+        waitForCondition(function() isChatFocused(chat),
+                         function() {
+          is(chat.iframe.contentDocument.activeElement.getAttribute("id"), "input2",
+             "correct input field has focus");
+          // set focus to the tab.
+          let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
+          Services.focus.moveFocus(tabb.contentWindow, null, Services.focus.MOVEFOCUS_ROOT, 0);
+          waitForCondition(function() isTabFocused(),
+                           function() {
+            chatbar.focus();
+            waitForCondition(function() isChatFocused(chat),
+                             function() {
+              is(chat.iframe.contentDocument.activeElement.getAttribute("id"), "input2",
+                 "correct input field still has focus");
+              next();
+            }, "chat took focus");
+          }, "tab has focus");
+        }, "chat took focus");
       });
     });
   },
 };