Bug 1245798: re-enable browser_social_activation.js, browser_social_chatwindowfocus.js and browser_social_contextmenu.js. r=mixedpuppy
authorMike de Boer <mdeboer@mozilla.com>
Mon, 14 Mar 2016 13:14:00 +0100
changeset 288516 2bef59a4476a99e0796bde9502c1bf0744f97182
parent 288515 f0c0480732d36153e8839c7f17394d45f679f87d
child 288517 7277824fbd1dea85a59d0bade0a44ccfb5186703
push id30083
push userkwierso@gmail.com
push dateTue, 15 Mar 2016 00:32:08 +0000
treeherdermozilla-central@21077a8abccf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1245798
milestone48.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 1245798: re-enable browser_social_activation.js, browser_social_chatwindowfocus.js and browser_social_contextmenu.js. r=mixedpuppy
browser/base/content/test/social/browser.ini
browser/base/content/test/social/browser_social_chatwindow.js
browser/base/content/test/social/browser_social_chatwindowfocus.js
browser/base/content/test/social/head.js
browser/base/content/test/social/social_sidebar.html
toolkit/components/social/MozSocialAPI.jsm
--- a/browser/base/content/test/social/browser.ini
+++ b/browser/base/content/test/social/browser.ini
@@ -29,21 +29,18 @@ support-files =
 
 [browser_aboutHome_activation.js]
 [browser_addons.js]
 [browser_blocklist.js]
 [browser_share.js]
 skip-if = true # bug 1115131
 [browser_social_activation.js]
 [browser_social_chatwindow.js]
-skip-if = true # Bug 1245798 'document-element-inserted' is not fired for chat windows anymore, so no mozSocial
 [browser_social_chatwindow_resize.js]
-skip-if = true # Bug 1245798 'document-element-inserted' is not fired for chat windows anymore, so no mozSocial
 [browser_social_chatwindowfocus.js]
-skip-if = true # Bug 1245798 'document-element-inserted' is not fired for chat windows anymore, so no mozSocial
 [browser_social_contextmenu.js]
 skip-if = (os == 'linux' && e10s) # Bug 1072669 context menu relies on target element
 [browser_social_errorPage.js]
 [browser_social_flyout.js]
 [browser_social_isVisible.js]
 [browser_social_marks.js]
 [browser_social_marks_context.js]
 [browser_social_multiprovider.js]
--- a/browser/base/content/test/social/browser_social_chatwindow.js
+++ b/browser/base/content/test/social/browser_social_chatwindow.js
@@ -91,38 +91,39 @@ function test() {
 var tests = {
   testOpenCloseChat: function(next) {
     let chats = document.getElementById("pinnedchats");
     let port = getProviderPort(SocialSidebar.provider);
     port.onmessage = function (e) {
       let topic = e.data.topic;
       switch (topic) {
         case "got-sidebar-message":
-          port.postMessage({topic: "test-chatbox-open"});
+          openChatViaUser();
           break;
         case "got-chatbox-visibility":
+          let selectedChat = chats.selectedChat || chats.lastElementChild;
           if (e.data.result == "hidden") {
             ok(true, "chatbox got minimized");
-            chats.selectedChat.toggle();
+            selectedChat.toggle();
           } else if (e.data.result == "shown") {
             ok(true, "chatbox got shown");
             // close it now
-            let content = chats.selectedChat.content;
+            let content = selectedChat.content;
             content.addEventListener("unload", function chatUnload() {
               content.removeEventListener("unload", chatUnload, true);
               ok(true, "got chatbox unload on close");
               next();
             }, true);
-            chats.selectedChat.close();
+            selectedChat.close();
           }
           break;
         case "got-chatbox-message":
           ok(true, "got chatbox message");
           ok(e.data.result == "ok", "got chatbox windowRef result: "+e.data.result);
-          chats.selectedChat.toggle();
+          selectedChat.toggle();
           break;
       }
     }
     port.postMessage({topic: "test-init", data: { id: 1 }});
   },
   testWorkerChatWindow: function(next) {
     const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
     let chats = document.getElementById("pinnedchats");
@@ -148,30 +149,27 @@ var tests = {
   },
   testCloseSelf: function(next) {
     let chats = document.getElementById("pinnedchats");
     let port = getProviderPort(SocialSidebar.provider);
     port.onmessage = function (e) {
       let topic = e.data.topic;
       switch (topic) {
         case "test-init-done":
-          port.postMessage({topic: "test-chatbox-open"});
+          openChatViaUser();
           break;
         case "got-chatbox-visibility":
           is(e.data.result, "shown", "chatbox shown");
           port.close(); // don't want any more visibility messages.
           let chat = chats.selectedChat;
           ok(chat.parentNode, "chat has a parent node before it is closed");
           // ask it to close itself.
-          let doc = chat.contentDocument;
-          let evt = doc.createEvent("CustomEvent");
-          evt.initCustomEvent("socialTest-CloseSelf", true, true, {});
-          doc.documentElement.dispatchEvent(evt);
-          ok(!chat.parentNode, "chat is now closed");
-          next();
+          let mm = chat.content.messageManager;
+          mm.sendAsyncMessage("Social:CustomEvent", { name: "socialTest-CloseSelf" });
+          waitForCondition(() => !chat.parentNode, next, "chat should close");
           break;
       }
     }
     port.postMessage({topic: "test-init", data: { id: 1 }});
   },
 
   // Check what happens when you close the only visible chat.
   testCloseOnlyVisible: function(next) {
--- a/browser/base/content/test/social/browser_social_chatwindowfocus.js
+++ b/browser/base/content/test/social/browser_social_chatwindowfocus.js
@@ -1,31 +1,16 @@
 /* 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/. */
 
-// Is the currently opened tab focused?
-function isTabFocused() {
-  let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
-  return Services.focus.focusedWindow == tabb.contentWindow;
-}
-
 function isChatFocused(chat) {
   return getChatBar()._isChatFocused(chat);
 }
 
-function openChatViaUser() {
-  let sidebarDoc = document.getElementById("social-sidebar-browser").contentDocument;
-  let button = sidebarDoc.getElementById("chat-opener");
-  // Note we must use synthesizeMouseAtCenter() rather than calling
-  // .click() directly as this causes nsIDOMWindowUtils.isHandlingUserInput
-  // to be true.
-  EventUtils.synthesizeMouseAtCenter(button, {}, sidebarDoc.defaultView);
-}
-
 function openChatViaSidebarMessage(port, data, callback) {
   port.onmessage = function (e) {
     if (e.data.topic == "chatbox-opened")
       callback();
   }
   port.postMessage({topic: "test-chatbox-open", data: data});
 }
 
@@ -93,25 +78,28 @@ function test() {
   waitForExplicitFinish();
 
   // Note that (probably) due to bug 604289, if a tab is focused but the
   // focused element is null, our chat windows can "steal" focus.  This is
   // avoided if we explicitly focus an element in the tab.
   // So we load a page with an <input> field and focus that before testing.
   let url = "data:text/html;charset=utf-8," + encodeURI('<input id="theinput">');
   let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true});
-  tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
-    tab.linkedBrowser.removeEventListener("load", tabLoad, true);
+  let browser = tab.linkedBrowser;
+  browser.addEventListener("load", function tabLoad(event) {
+    browser.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();
-      waitForCondition(() => isTabFocused(), cb, "tab should have focus");
+      ContentTask.spawn(browser, null, function* () {
+        content.focus();
+        content.document.getElementById("theinput").focus();
+
+        yield ContentTaskUtils.waitForCondition(
+          () => Services.focus.focusedWindow == content, "tab should have focus");
+      }).then(cb);
     }
     let postSubTest = function(cb) {
       Task.spawn(closeAllChats).then(cb);
     }
     // and run the tests.
     runSocialTestWithProvider(manifest, function (finishcb) {
       SocialSidebar.show();
       runSocialTests(tests, preSubTest, postSubTest, function () {
@@ -131,41 +119,49 @@ var tests = {
   // Then we do it again - should still not be focused.
   // Then we perform a user-initiated request - it should get focus.
   testNoFocusWhenViaWorker: function(next) {
     let chatbar = getChatBar();
     startTestAndWaitForSidebar(function(port) {
       openChatViaSidebarMessage(port, {stealFocus: 1}, function() {
         ok(true, "got chatbox message");
         is(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(chatbar.childElementCount, 1, "still exactly 1 chat open");
-          ok(isTabFocused(), "tab should still be focused");
-          // re-request the same chat via user event.
-          openChatViaUser();
-          waitForCondition(() => isChatFocused(chatbar.selectedChat),
-                           function() {
+
+        let browser = gBrowser.selectedTab.linkedBrowser;
+        ContentTask.spawn(browser, null, function* () {
+          is(Services.focus.focusedWindow, content, "tab should still be focused");
+        }).then(() => {
+          // re-request the same chat via a message.
+          openChatViaSidebarMessage(port, {stealFocus: 1}, function() {
             is(chatbar.childElementCount, 1, "still exactly 1 chat open");
-            is(chatbar.selectedChat, chatbar.firstElementChild, "chat should be selected");
-            next();
-          }, "chat should be focused");
+
+            ContentTask.spawn(browser, null, function* () {
+              is(Services.focus.focusedWindow, content, "tab should still be focused");
+            }).then(() => {
+              // re-request the same chat via user event.
+              openChatViaUser();
+              waitForCondition(() => isChatFocused(chatbar.selectedChat), function() {
+                is(chatbar.childElementCount, 1, "still exactly 1 chat open");
+                is(chatbar.selectedChat, 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) {
       let chatbar = getChatBar();
       openChatViaUser();
       ok(chatbar.firstElementChild, "chat opened");
-      waitForCondition(() => isChatFocused(chatbar.selectedChat),
-                       function() {
+      waitForCondition(() => isChatFocused(chatbar.selectedChat), function() {
         is(chatbar.selectedChat, chatbar.firstElementChild, "chat is selected");
         next();
       }, "chat should be focused");
     });
   },
 };
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -653,16 +653,25 @@ function promiseCloseChat(chat) {
 
 function closeAllChats() {
   let chatbar = getChatBar();
   while (chatbar.selectedChat) {
     yield promiseCloseChat(chatbar.selectedChat);
   }
 }
 
+function openChatViaUser() {
+  let sidebarDoc = document.getElementById("social-sidebar-browser").contentDocument;
+  let button = sidebarDoc.getElementById("chat-opener");
+  // Note we must use synthesizeMouseAtCenter() rather than calling
+  // .click() directly as this causes nsIDOMWindowUtils.isHandlingUserInput
+  // to be true.
+  EventUtils.synthesizeMouseAtCenter(button, {}, sidebarDoc.defaultView);
+}
+
 
 // Support for going on and offline.
 // (via browser/base/content/test/browser_bookmark_titles.js)
 var origProxyType = Services.prefs.getIntPref('network.proxy.type');
 
 function toggleOfflineStatus(goOffline) {
   // Bug 968887 fix.  when going on/offline, wait for notification before continuing
   let deferred = Promise.defer();
--- a/browser/base/content/test/social/social_sidebar.html
+++ b/browser/base/content/test/social/social_sidebar.html
@@ -15,24 +15,19 @@
               navigator.mozSocial.closePanel();
               break;
             case "test-chatbox-open":
               var url = "social_chat.html";
               var data = e.data.data;
               if (data && data.id) {
                 url = url + "?id="+data.id;
               }
-              navigator.mozSocial.openChatWindow(url, function(chatwin) {
-                // Note that the following .focus() call should *not* arrange
-                // to steal focus - see browser_social_chatwindowfocus.js
-                if (data && data.stealFocus && chatwin) {
-                  chatwin.focus();
-                }
+              navigator.mozSocial.openChatWindow(url, function(success) {
                 port.postMessage({topic: "chatbox-opened",
-                                  result: chatwin ? "ok" : "failed"});
+                                  result: success ? "ok" : "failed"});
               });
               break;
             case "test-isVisible":
               port.postMessage({topic: "test-isVisible-response",
                                 result: navigator.mozSocial.isVisible});
               break;
           }
         }
--- a/toolkit/components/social/MozSocialAPI.jsm
+++ b/toolkit/components/social/MozSocialAPI.jsm
@@ -140,17 +140,25 @@ function attachToWindow(provider, target
       }
     },
     openChatWindow: {
       enumerable: true,
       configurable: true,
       writable: true,
       value: function(toURL, callback) {
         let url = targetWindow.document.documentURIObject.resolve(toURL);
-        openChatWindow(targetWindow, provider, url, callback);
+        let dwu = getChromeWindow(targetWindow)
+          .QueryInterface(Ci.nsIInterfaceRequestor)
+          .getInterface(Ci.nsIDOMWindowUtils);
+        openChatWindow(targetWindow, provider, url, chatWin => {
+          if (chatWin && dwu.isHandlingUserInput)
+            chatWin.focus();
+          if (callback)
+            callback(!!chatWin);
+        });
       }
     },
     openPanel: {
       enumerable: true,
       configurable: true,
       writable: true,
       value: function(toURL, offset, callback) {
         let chromeWindow = getChromeWindow(targetWindow);