From f33eaf3d40e8796ae744d3c6394aebf7e6e08d63 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Fri, 5 Oct 2012 14:13:11 +1000 Subject: [PATCH] Bug 796309 - callback must be invoked if same social chat url opened twice. r=mixedpuppy --- browser/base/content/socialchat.xml | 2 ++ .../content/test/browser_social_chatwindow.js | 29 +++++++++++++++++++ browser/base/content/test/social_worker.js | 5 +++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/browser/base/content/socialchat.xml b/browser/base/content/socialchat.xml index d580c2ebcaf2..828839defcd0 100644 --- a/browser/base/content/socialchat.xml +++ b/browser/base/content/socialchat.xml @@ -317,6 +317,8 @@ this.selectedChat = cb; if (cb.collapsed) this.showChat(cb); + if (aCallback) + aCallback(cb.iframe.contentWindow); return; } this.chatboxForURL.delete(aURL); diff --git a/browser/base/content/test/browser_social_chatwindow.js b/browser/base/content/test/browser_social_chatwindow.js index b56a2e188463..df493d66df51 100644 --- a/browser/base/content/test/browser_social_chatwindow.js +++ b/browser/base/content/test/browser_social_chatwindow.js @@ -143,6 +143,35 @@ var tests = { } port.postMessage({topic: "test-init", data: { id: 1 }}); }, + testSameChatCallbacks: function(next) { + let chats = document.getElementById("pinnedchats"); + let port = Social.provider.getWorkerPort(); + let seen_opened = false; + port.onmessage = function (e) { + let topic = e.data.topic; + switch (topic) { + case "test-init-done": + port.postMessage({topic: "test-chatbox-open"}); + break; + case "chatbox-opened": + is(e.data.result, "ok", "the sidebar says it got a chatbox"); + if (seen_opened) { + // This is the second time we've seen this message - there should + // be exactly 1 chat open. + let chats = document.getElementById("pinnedchats"); + chats.selectedChat.close(); + is(chats.selectedChat, null, "should only have been one chat open"); + next(); + } else { + // first time we got the opened message, so re-request the same + // chat to be opened - we should get the message again. + seen_opened = true; + port.postMessage({topic: "test-chatbox-open"}); + } + } + } + port.postMessage({topic: "test-init", data: { id: 1 }}); + }, testCloseOnLogout: function(next) { const chatUrl = "https://example.com/browser/browser/base/content/test/social_chat.html"; let port = Social.provider.getWorkerPort(); diff --git a/browser/base/content/test/social_worker.js b/browser/base/content/test/social_worker.js index be0524125a7a..9d1a4abed5fa 100644 --- a/browser/base/content/test/social_worker.js +++ b/browser/base/content/test/social_worker.js @@ -50,7 +50,10 @@ onconnect = function(e) { testPort.postMessage({topic:"got-social-panel-visibility", result: event.data.result }); break; case "test-chatbox-open": - sidebarPort.postMessage( event.data ); + sidebarPort.postMessage(event.data); + break; + case "chatbox-opened": + testPort.postMessage(event.data); break; case "chatbox-message": testPort.postMessage({topic:"got-chatbox-message", result: event.data.result});