1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/social/browser_social_chatwindow.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,574 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; 1.9 + 1.10 +let manifests = [ 1.11 + { 1.12 + name: "provider@example.com", 1.13 + origin: "https://example.com", 1.14 + sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?example.com", 1.15 + workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", 1.16 + iconURL: "chrome://branding/content/icon48.png" 1.17 + }, 1.18 + { 1.19 + name: "provider@test1", 1.20 + origin: "https://test1.example.com", 1.21 + sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?test1", 1.22 + workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", 1.23 + iconURL: "chrome://branding/content/icon48.png" 1.24 + }, 1.25 + { 1.26 + name: "provider@test2", 1.27 + origin: "https://test2.example.com", 1.28 + sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?test2", 1.29 + workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js", 1.30 + iconURL: "chrome://branding/content/icon48.png" 1.31 + } 1.32 +]; 1.33 + 1.34 +let chatId = 0; 1.35 +function openChat(provider, callback) { 1.36 + let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; 1.37 + let port = provider.getWorkerPort(); 1.38 + port.onmessage = function(e) { 1.39 + if (e.data.topic == "got-chatbox-message") { 1.40 + port.close(); 1.41 + callback(); 1.42 + } 1.43 + } 1.44 + let url = chatUrl + "?" + (chatId++); 1.45 + port.postMessage({topic: "test-init"}); 1.46 + port.postMessage({topic: "test-worker-chat", data: url}); 1.47 + gURLsNotRemembered.push(url); 1.48 +} 1.49 + 1.50 +function test() { 1.51 + requestLongerTimeout(2); // only debug builds seem to need more time... 1.52 + waitForExplicitFinish(); 1.53 + 1.54 + let oldwidth = window.outerWidth; // we futz with these, so we restore them 1.55 + let oldleft = window.screenX; 1.56 + window.moveTo(0, window.screenY) 1.57 + let postSubTest = function(cb) { 1.58 + let chats = document.getElementById("pinnedchats"); 1.59 + ok(chats.children.length == 0, "no chatty children left behind"); 1.60 + cb(); 1.61 + }; 1.62 + runSocialTestWithProvider(manifests, function (finishcb) { 1.63 + ok(Social.enabled, "Social is enabled"); 1.64 + ok(Social.providers[0].getWorkerPort(), "provider 0 has port"); 1.65 + ok(Social.providers[1].getWorkerPort(), "provider 1 has port"); 1.66 + ok(Social.providers[2].getWorkerPort(), "provider 2 has port"); 1.67 + SocialSidebar.show(); 1.68 + runSocialTests(tests, undefined, postSubTest, function() { 1.69 + window.moveTo(oldleft, window.screenY) 1.70 + window.resizeTo(oldwidth, window.outerHeight); 1.71 + finishcb(); 1.72 + }); 1.73 + }); 1.74 +} 1.75 + 1.76 +var tests = { 1.77 + testOpenCloseChat: function(next) { 1.78 + let chats = document.getElementById("pinnedchats"); 1.79 + let port = SocialSidebar.provider.getWorkerPort(); 1.80 + ok(port, "provider has a port"); 1.81 + port.onmessage = function (e) { 1.82 + let topic = e.data.topic; 1.83 + switch (topic) { 1.84 + case "got-sidebar-message": 1.85 + port.postMessage({topic: "test-chatbox-open"}); 1.86 + break; 1.87 + case "got-chatbox-visibility": 1.88 + if (e.data.result == "hidden") { 1.89 + ok(true, "chatbox got minimized"); 1.90 + chats.selectedChat.toggle(); 1.91 + } else if (e.data.result == "shown") { 1.92 + ok(true, "chatbox got shown"); 1.93 + // close it now 1.94 + let content = chats.selectedChat.content; 1.95 + content.addEventListener("unload", function chatUnload() { 1.96 + content.removeEventListener("unload", chatUnload, true); 1.97 + ok(true, "got chatbox unload on close"); 1.98 + port.close(); 1.99 + next(); 1.100 + }, true); 1.101 + chats.selectedChat.close(); 1.102 + } 1.103 + break; 1.104 + case "got-chatbox-message": 1.105 + ok(true, "got chatbox message"); 1.106 + ok(e.data.result == "ok", "got chatbox windowRef result: "+e.data.result); 1.107 + chats.selectedChat.toggle(); 1.108 + break; 1.109 + } 1.110 + } 1.111 + port.postMessage({topic: "test-init", data: { id: 1 }}); 1.112 + }, 1.113 + testOpenMinimized: function(next) { 1.114 + // In this case the sidebar opens a chat (without specifying minimized). 1.115 + // We then minimize it and have the sidebar reopen the chat (again without 1.116 + // minimized). On that second call the chat should open and no longer 1.117 + // be minimized. 1.118 + let chats = document.getElementById("pinnedchats"); 1.119 + let port = SocialSidebar.provider.getWorkerPort(); 1.120 + let seen_opened = false; 1.121 + port.onmessage = function (e) { 1.122 + let topic = e.data.topic; 1.123 + switch (topic) { 1.124 + case "test-init-done": 1.125 + port.postMessage({topic: "test-chatbox-open"}); 1.126 + break; 1.127 + case "chatbox-opened": 1.128 + is(e.data.result, "ok", "the sidebar says it got a chatbox"); 1.129 + if (!seen_opened) { 1.130 + // first time we got the opened message, so minimize the chat then 1.131 + // re-request the same chat to be opened - we should get the 1.132 + // message again and the chat should be restored. 1.133 + ok(!chats.selectedChat.minimized, "chat not initially minimized") 1.134 + chats.selectedChat.minimized = true 1.135 + seen_opened = true; 1.136 + port.postMessage({topic: "test-chatbox-open"}); 1.137 + } else { 1.138 + // This is the second time we've seen this message - there should 1.139 + // be exactly 1 chat open and it should no longer be minimized. 1.140 + let chats = document.getElementById("pinnedchats"); 1.141 + ok(!chats.selectedChat.minimized, "chat no longer minimized") 1.142 + chats.selectedChat.close(); 1.143 + is(chats.selectedChat, null, "should only have been one chat open"); 1.144 + port.close(); 1.145 + next(); 1.146 + } 1.147 + } 1.148 + } 1.149 + port.postMessage({topic: "test-init", data: { id: 1 }}); 1.150 + }, 1.151 + testManyChats: function(next) { 1.152 + // open enough chats to overflow the window, then check 1.153 + // if the menupopup is visible 1.154 + let port = SocialSidebar.provider.getWorkerPort(); 1.155 + let chats = document.getElementById("pinnedchats"); 1.156 + ok(port, "provider has a port"); 1.157 + ok(chats.menupopup.parentNode.collapsed, "popup nub collapsed at start"); 1.158 + port.postMessage({topic: "test-init"}); 1.159 + // we should *never* find a test box that needs more than this to cause 1.160 + // an overflow! 1.161 + let maxToOpen = 20; 1.162 + let numOpened = 0; 1.163 + let maybeOpenAnother = function() { 1.164 + if (numOpened++ >= maxToOpen) { 1.165 + ok(false, "We didn't find a collapsed chat after " + maxToOpen + "chats!"); 1.166 + closeAllChats(); 1.167 + next(); 1.168 + } 1.169 + port.postMessage({topic: "test-chatbox-open", data: { id: numOpened }}); 1.170 + } 1.171 + port.onmessage = function (e) { 1.172 + let topic = e.data.topic; 1.173 + switch (topic) { 1.174 + case "got-chatbox-message": 1.175 + if (!chats.menupopup.parentNode.collapsed) { 1.176 + maybeOpenAnother(); 1.177 + break; 1.178 + } 1.179 + ok(true, "popup nub became visible"); 1.180 + // close our chats now 1.181 + while (chats.selectedChat) { 1.182 + chats.selectedChat.close(); 1.183 + } 1.184 + ok(!chats.selectedChat, "chats are all closed"); 1.185 + port.close(); 1.186 + next(); 1.187 + break; 1.188 + } 1.189 + } 1.190 + maybeOpenAnother(); 1.191 + }, 1.192 + testWorkerChatWindow: function(next) { 1.193 + const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; 1.194 + let chats = document.getElementById("pinnedchats"); 1.195 + let port = SocialSidebar.provider.getWorkerPort(); 1.196 + ok(port, "provider has a port"); 1.197 + port.postMessage({topic: "test-init"}); 1.198 + port.onmessage = function (e) { 1.199 + let topic = e.data.topic; 1.200 + switch (topic) { 1.201 + case "got-chatbox-message": 1.202 + ok(true, "got a chat window opened"); 1.203 + ok(chats.selectedChat, "chatbox from worker opened"); 1.204 + while (chats.selectedChat) { 1.205 + chats.selectedChat.close(); 1.206 + } 1.207 + ok(!chats.selectedChat, "chats are all closed"); 1.208 + gURLsNotRemembered.push(chatUrl); 1.209 + port.close(); 1.210 + next(); 1.211 + break; 1.212 + } 1.213 + } 1.214 + ok(!chats.selectedChat, "chats are all closed"); 1.215 + port.postMessage({topic: "test-worker-chat", data: chatUrl}); 1.216 + }, 1.217 + testCloseSelf: function(next) { 1.218 + let chats = document.getElementById("pinnedchats"); 1.219 + let port = SocialSidebar.provider.getWorkerPort(); 1.220 + ok(port, "provider has a port"); 1.221 + port.onmessage = function (e) { 1.222 + let topic = e.data.topic; 1.223 + switch (topic) { 1.224 + case "test-init-done": 1.225 + port.postMessage({topic: "test-chatbox-open"}); 1.226 + break; 1.227 + case "got-chatbox-visibility": 1.228 + is(e.data.result, "shown", "chatbox shown"); 1.229 + port.close(); // don't want any more visibility messages. 1.230 + let chat = chats.selectedChat; 1.231 + ok(chat.parentNode, "chat has a parent node before it is closed"); 1.232 + // ask it to close itself. 1.233 + let doc = chat.contentDocument; 1.234 + let evt = doc.createEvent("CustomEvent"); 1.235 + evt.initCustomEvent("socialTest-CloseSelf", true, true, {}); 1.236 + doc.documentElement.dispatchEvent(evt); 1.237 + ok(!chat.parentNode, "chat is now closed"); 1.238 + port.close(); 1.239 + next(); 1.240 + break; 1.241 + } 1.242 + } 1.243 + port.postMessage({topic: "test-init", data: { id: 1 }}); 1.244 + }, 1.245 + testSameChatCallbacks: function(next) { 1.246 + let chats = document.getElementById("pinnedchats"); 1.247 + let port = SocialSidebar.provider.getWorkerPort(); 1.248 + let seen_opened = false; 1.249 + port.onmessage = function (e) { 1.250 + let topic = e.data.topic; 1.251 + switch (topic) { 1.252 + case "test-init-done": 1.253 + port.postMessage({topic: "test-chatbox-open"}); 1.254 + break; 1.255 + case "chatbox-opened": 1.256 + is(e.data.result, "ok", "the sidebar says it got a chatbox"); 1.257 + if (seen_opened) { 1.258 + // This is the second time we've seen this message - there should 1.259 + // be exactly 1 chat open. 1.260 + let chats = document.getElementById("pinnedchats"); 1.261 + chats.selectedChat.close(); 1.262 + is(chats.selectedChat, null, "should only have been one chat open"); 1.263 + port.close(); 1.264 + next(); 1.265 + } else { 1.266 + // first time we got the opened message, so re-request the same 1.267 + // chat to be opened - we should get the message again. 1.268 + seen_opened = true; 1.269 + port.postMessage({topic: "test-chatbox-open"}); 1.270 + } 1.271 + } 1.272 + } 1.273 + port.postMessage({topic: "test-init", data: { id: 1 }}); 1.274 + }, 1.275 + 1.276 + // check removeAll does the right thing 1.277 + testRemoveAll: function(next, mode) { 1.278 + let port = SocialSidebar.provider.getWorkerPort(); 1.279 + port.postMessage({topic: "test-init"}); 1.280 + get3ChatsForCollapsing(mode || "normal", function() { 1.281 + let chatbar = window.SocialChatBar.chatbar; 1.282 + chatbar.removeAll(); 1.283 + // should be no evidence of any chats left. 1.284 + is(chatbar.childNodes.length, 0, "should be no chats left"); 1.285 + checkPopup(); 1.286 + is(chatbar.selectedChat, null, "nothing should be selected"); 1.287 + is(chatbar.chatboxForURL.size, 0, "chatboxForURL map should be empty"); 1.288 + port.close(); 1.289 + next(); 1.290 + }); 1.291 + }, 1.292 + 1.293 + testRemoveAllMinimized: function(next) { 1.294 + this.testRemoveAll(next, "minimized"); 1.295 + }, 1.296 + 1.297 + // Check what happens when you close the only visible chat. 1.298 + testCloseOnlyVisible: function(next) { 1.299 + let chatbar = window.SocialChatBar.chatbar; 1.300 + let chatWidth = undefined; 1.301 + let num = 0; 1.302 + is(chatbar.childNodes.length, 0, "chatbar starting empty"); 1.303 + is(chatbar.menupopup.childNodes.length, 0, "popup starting empty"); 1.304 + 1.305 + makeChat("normal", "first chat", function() { 1.306 + // got the first one. 1.307 + checkPopup(); 1.308 + ok(chatbar.menupopup.parentNode.collapsed, "menu selection isn't visible"); 1.309 + // we kinda cheat here and get the width of the first chat, assuming 1.310 + // that all future chats will have the same width when open. 1.311 + chatWidth = chatbar.calcTotalWidthOf(chatbar.selectedChat); 1.312 + let desired = chatWidth * 1.5; 1.313 + resizeWindowToChatAreaWidth(desired, function(sizedOk) { 1.314 + ok(sizedOk, "can't do any tests without this width"); 1.315 + checkPopup(); 1.316 + makeChat("normal", "second chat", function() { 1.317 + is(chatbar.childNodes.length, 2, "now have 2 chats"); 1.318 + let first = chatbar.childNodes[0]; 1.319 + let second = chatbar.childNodes[1]; 1.320 + is(chatbar.selectedChat, first, "first chat is selected"); 1.321 + ok(second.collapsed, "second chat is currently collapsed"); 1.322 + // closing the first chat will leave enough room for the second 1.323 + // chat to appear, and thus become selected. 1.324 + chatbar.selectedChat.close(); 1.325 + is(chatbar.selectedChat, second, "second chat is selected"); 1.326 + closeAllChats(); 1.327 + next(); 1.328 + }); 1.329 + }); 1.330 + }); 1.331 + }, 1.332 + 1.333 + testShowWhenCollapsed: function(next) { 1.334 + let port = SocialSidebar.provider.getWorkerPort(); 1.335 + port.postMessage({topic: "test-init"}); 1.336 + get3ChatsForCollapsing("normal", function(first, second, third) { 1.337 + let chatbar = window.SocialChatBar.chatbar; 1.338 + chatbar.showChat(first); 1.339 + ok(!first.collapsed, "first should no longer be collapsed"); 1.340 + ok(second.collapsed || third.collapsed, false, "one of the others should be collapsed"); 1.341 + closeAllChats(); 1.342 + port.close(); 1.343 + next(); 1.344 + }); 1.345 + }, 1.346 + 1.347 + testActivity: function(next) { 1.348 + let port = SocialSidebar.provider.getWorkerPort(); 1.349 + port.postMessage({topic: "test-init"}); 1.350 + get3ChatsForCollapsing("normal", function(first, second, third) { 1.351 + let chatbar = window.SocialChatBar.chatbar; 1.352 + is(chatbar.selectedChat, third, "third chat should be selected"); 1.353 + ok(!chatbar.selectedChat.hasAttribute("activity"), "third chat should have no activity"); 1.354 + // send an activity message to the second. 1.355 + ok(!second.hasAttribute("activity"), "second chat should have no activity"); 1.356 + let chat2 = second.content; 1.357 + let evt = chat2.contentDocument.createEvent("CustomEvent"); 1.358 + evt.initCustomEvent("socialChatActivity", true, true, {}); 1.359 + chat2.contentDocument.documentElement.dispatchEvent(evt); 1.360 + // second should have activity. 1.361 + ok(second.hasAttribute("activity"), "second chat should now have activity"); 1.362 + // select the second - it should lose "activity" 1.363 + chatbar.selectedChat = second; 1.364 + ok(!second.hasAttribute("activity"), "second chat should no longer have activity"); 1.365 + // Now try the first - it is collapsed, so the 'nub' also gets activity attr. 1.366 + ok(!first.hasAttribute("activity"), "first chat should have no activity"); 1.367 + let chat1 = first.content; 1.368 + let evt = chat1.contentDocument.createEvent("CustomEvent"); 1.369 + evt.initCustomEvent("socialChatActivity", true, true, {}); 1.370 + chat1.contentDocument.documentElement.dispatchEvent(evt); 1.371 + ok(first.hasAttribute("activity"), "first chat should now have activity"); 1.372 + ok(chatbar.nub.hasAttribute("activity"), "nub should also have activity"); 1.373 + // first is collapsed, so use openChat to get it. 1.374 + chatbar.openChat(SocialSidebar.provider, first.getAttribute("src")); 1.375 + ok(!first.hasAttribute("activity"), "first chat should no longer have activity"); 1.376 + // The nub should lose the activity flag here too 1.377 + todo(!chatbar.nub.hasAttribute("activity"), "Bug 806266 - nub should no longer have activity"); 1.378 + // TODO: tests for bug 806266 should arrange to have 2 chats collapsed 1.379 + // then open them checking the nub is updated correctly. 1.380 + // Now we will go and change the embedded browser in the second chat and 1.381 + // ensure the activity magic still works (ie, check that the unload for 1.382 + // the browser didn't cause our event handlers to be removed.) 1.383 + ok(!second.hasAttribute("activity"), "second chat should have no activity"); 1.384 + let subiframe = chat2.contentDocument.getElementById("iframe"); 1.385 + subiframe.contentWindow.addEventListener("unload", function subunload() { 1.386 + subiframe.contentWindow.removeEventListener("unload", subunload); 1.387 + // ensure all other unload listeners have fired. 1.388 + executeSoon(function() { 1.389 + let evt = chat2.contentDocument.createEvent("CustomEvent"); 1.390 + evt.initCustomEvent("socialChatActivity", true, true, {}); 1.391 + chat2.contentDocument.documentElement.dispatchEvent(evt); 1.392 + ok(second.hasAttribute("activity"), "second chat still has activity after unloading sub-iframe"); 1.393 + closeAllChats(); 1.394 + port.close(); 1.395 + next(); 1.396 + }) 1.397 + }) 1.398 + subiframe.setAttribute("src", "data:text/plain:new location for iframe"); 1.399 + }); 1.400 + }, 1.401 + 1.402 + testOnlyOneCallback: function(next) { 1.403 + let chats = document.getElementById("pinnedchats"); 1.404 + let port = SocialSidebar.provider.getWorkerPort(); 1.405 + let numOpened = 0; 1.406 + port.onmessage = function (e) { 1.407 + let topic = e.data.topic; 1.408 + switch (topic) { 1.409 + case "test-init-done": 1.410 + port.postMessage({topic: "test-chatbox-open"}); 1.411 + break; 1.412 + case "chatbox-opened": 1.413 + numOpened += 1; 1.414 + port.postMessage({topic: "ping"}); 1.415 + break; 1.416 + case "pong": 1.417 + executeSoon(function() { 1.418 + is(numOpened, 1, "only got one open message"); 1.419 + chats.removeAll(); 1.420 + port.close(); 1.421 + next(); 1.422 + }); 1.423 + } 1.424 + } 1.425 + port.postMessage({topic: "test-init", data: { id: 1 }}); 1.426 + }, 1.427 + 1.428 + testSecondTopLevelWindow: function(next) { 1.429 + // Bug 817782 - check chats work in new top-level windows. 1.430 + const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; 1.431 + let port = SocialSidebar.provider.getWorkerPort(); 1.432 + let secondWindow; 1.433 + port.onmessage = function(e) { 1.434 + if (e.data.topic == "test-init-done") { 1.435 + secondWindow = OpenBrowserWindow(); 1.436 + secondWindow.addEventListener("load", function loadListener() { 1.437 + secondWindow.removeEventListener("load", loadListener); 1.438 + port.postMessage({topic: "test-worker-chat", data: chatUrl}); 1.439 + }); 1.440 + } else if (e.data.topic == "got-chatbox-message") { 1.441 + // the chat was created - let's make sure it was created in the second window. 1.442 + is(secondWindow.SocialChatBar.chatbar.childElementCount, 1); 1.443 + secondWindow.close(); 1.444 + next(); 1.445 + } 1.446 + } 1.447 + port.postMessage({topic: "test-init"}); 1.448 + }, 1.449 + 1.450 + testChatWindowChooser: function(next) { 1.451 + // Tests that when a worker creates a chat, it is opened in the correct 1.452 + // window. 1.453 + // open a chat (it will open in the main window) 1.454 + ok(!window.SocialChatBar.hasChats, "first window should start with no chats"); 1.455 + openChat(SocialSidebar.provider, function() { 1.456 + ok(window.SocialChatBar.hasChats, "first window has the chat"); 1.457 + // create a second window - this will be the "most recent" and will 1.458 + // therefore be the window that hosts the new chat (see bug 835111) 1.459 + let secondWindow = OpenBrowserWindow(); 1.460 + secondWindow.addEventListener("load", function loadListener() { 1.461 + secondWindow.removeEventListener("load", loadListener); 1.462 + ok(!secondWindow.SocialChatBar.hasChats, "second window has no chats"); 1.463 + openChat(SocialSidebar.provider, function() { 1.464 + ok(secondWindow.SocialChatBar.hasChats, "second window now has chats"); 1.465 + is(window.SocialChatBar.chatbar.childElementCount, 1, "first window still has 1 chat"); 1.466 + window.SocialChatBar.chatbar.removeAll(); 1.467 + // now open another chat - it should still open in the second. 1.468 + openChat(SocialSidebar.provider, function() { 1.469 + ok(!window.SocialChatBar.hasChats, "first window has no chats"); 1.470 + ok(secondWindow.SocialChatBar.hasChats, "second window has a chat"); 1.471 + 1.472 + // focus the first window, and open yet another chat - it 1.473 + // should open in the first window. 1.474 + waitForFocus(function() { 1.475 + openChat(SocialSidebar.provider, function() { 1.476 + ok(window.SocialChatBar.hasChats, "first window has chats"); 1.477 + window.SocialChatBar.chatbar.removeAll(); 1.478 + ok(!window.SocialChatBar.hasChats, "first window has no chats"); 1.479 + 1.480 + let privateWindow = OpenBrowserWindow({private: true}); 1.481 + privateWindow.addEventListener("load", function loadListener() { 1.482 + privateWindow.removeEventListener("load", loadListener); 1.483 + 1.484 + // open a last chat - the focused window can't accept 1.485 + // chats (it's a private window), so the chat should open 1.486 + // in the window that was selected before. This is known 1.487 + // to be broken on Linux. 1.488 + openChat(SocialSidebar.provider, function() { 1.489 + let os = Services.appinfo.OS; 1.490 + const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin"; 1.491 + let fn = BROKEN_WM_Z_ORDER ? todo : ok; 1.492 + fn(window.SocialChatBar.hasChats, "first window has a chat"); 1.493 + window.SocialChatBar.chatbar.removeAll(); 1.494 + 1.495 + privateWindow.close(); 1.496 + secondWindow.close(); 1.497 + next(); 1.498 + }); 1.499 + }); 1.500 + }); 1.501 + }); 1.502 + window.focus(); 1.503 + }); 1.504 + }); 1.505 + }) 1.506 + }); 1.507 + }, 1.508 + testMultipleProviderChat: function(next) { 1.509 + // test incomming chats from all providers 1.510 + openChat(Social.providers[0], function() { 1.511 + openChat(Social.providers[1], function() { 1.512 + openChat(Social.providers[2], function() { 1.513 + let chats = document.getElementById("pinnedchats"); 1.514 + waitForCondition(function() chats.children.length == Social.providers.length, 1.515 + function() { 1.516 + ok(true, "one chat window per provider opened"); 1.517 + // test logout of a single provider 1.518 + let provider = Social.providers[2]; 1.519 + let port = provider.getWorkerPort(); 1.520 + port.postMessage({topic: "test-logout"}); 1.521 + waitForCondition(function() chats.children.length == Social.providers.length - 1, 1.522 + function() { 1.523 + chats.removeAll(); 1.524 + waitForCondition(function() chats.children.length == 0, 1.525 + function() { 1.526 + ok(!chats.selectedChat, "multiprovider chats are all closed"); 1.527 + port.close(); 1.528 + next(); 1.529 + }, 1.530 + "chat windows didn't close"); 1.531 + }, 1.532 + "chat window didn't close"); 1.533 + }, "chat windows did not open"); 1.534 + }); 1.535 + }); 1.536 + }); 1.537 + }, 1.538 + 1.539 + // XXX - note this must be the last test until we restore the login state 1.540 + // between tests... 1.541 + testCloseOnLogout: function(next) { 1.542 + const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; 1.543 + let port = SocialSidebar.provider.getWorkerPort(); 1.544 + ok(port, "provider has a port"); 1.545 + let opened = false; 1.546 + port.onmessage = function (e) { 1.547 + let topic = e.data.topic; 1.548 + switch (topic) { 1.549 + case "test-init-done": 1.550 + info("open first chat window"); 1.551 + port.postMessage({topic: "test-worker-chat", data: chatUrl}); 1.552 + break; 1.553 + case "got-chatbox-message": 1.554 + ok(true, "got a chat window opened"); 1.555 + if (opened) { 1.556 + port.postMessage({topic: "test-logout"}); 1.557 + waitForCondition(function() document.getElementById("pinnedchats").firstChild == null, 1.558 + function() { 1.559 + port.close(); 1.560 + next(); 1.561 + }, 1.562 + "chat windows didn't close"); 1.563 + } else { 1.564 + // open a second chat window 1.565 + opened = true; 1.566 + port.postMessage({topic: "test-worker-chat", data: chatUrl+"?id=1"}); 1.567 + } 1.568 + break; 1.569 + } 1.570 + } 1.571 + // make sure a user profile is set for this provider as chat windows are 1.572 + // only closed on *change* of the profile data rather than merely setting 1.573 + // profile data. 1.574 + port.postMessage({topic: "test-set-profile"}); 1.575 + port.postMessage({topic: "test-init"}); 1.576 + } 1.577 +}