michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; michael@0: michael@0: let manifests = [ michael@0: { michael@0: name: "provider@example.com", michael@0: origin: "https://example.com", michael@0: sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?example.com", michael@0: workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: iconURL: "chrome://branding/content/icon48.png" michael@0: }, michael@0: { michael@0: name: "provider@test1", michael@0: origin: "https://test1.example.com", michael@0: sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?test1", michael@0: workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: iconURL: "chrome://branding/content/icon48.png" michael@0: }, michael@0: { michael@0: name: "provider@test2", michael@0: origin: "https://test2.example.com", michael@0: sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?test2", michael@0: workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: iconURL: "chrome://branding/content/icon48.png" michael@0: } michael@0: ]; michael@0: michael@0: let chatId = 0; michael@0: function openChat(provider, callback) { michael@0: let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; michael@0: let port = provider.getWorkerPort(); michael@0: port.onmessage = function(e) { michael@0: if (e.data.topic == "got-chatbox-message") { michael@0: port.close(); michael@0: callback(); michael@0: } michael@0: } michael@0: let url = chatUrl + "?" + (chatId++); michael@0: port.postMessage({topic: "test-init"}); michael@0: port.postMessage({topic: "test-worker-chat", data: url}); michael@0: gURLsNotRemembered.push(url); michael@0: } michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); // only debug builds seem to need more time... michael@0: waitForExplicitFinish(); michael@0: michael@0: let oldwidth = window.outerWidth; // we futz with these, so we restore them michael@0: let oldleft = window.screenX; michael@0: window.moveTo(0, window.screenY) michael@0: let postSubTest = function(cb) { michael@0: let chats = document.getElementById("pinnedchats"); michael@0: ok(chats.children.length == 0, "no chatty children left behind"); michael@0: cb(); michael@0: }; michael@0: runSocialTestWithProvider(manifests, function (finishcb) { michael@0: ok(Social.enabled, "Social is enabled"); michael@0: ok(Social.providers[0].getWorkerPort(), "provider 0 has port"); michael@0: ok(Social.providers[1].getWorkerPort(), "provider 1 has port"); michael@0: ok(Social.providers[2].getWorkerPort(), "provider 2 has port"); michael@0: SocialSidebar.show(); michael@0: runSocialTests(tests, undefined, postSubTest, function() { michael@0: window.moveTo(oldleft, window.screenY) michael@0: window.resizeTo(oldwidth, window.outerHeight); michael@0: finishcb(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: var tests = { michael@0: testOpenCloseChat: function(next) { michael@0: let chats = document.getElementById("pinnedchats"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "got-sidebar-message": michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: break; michael@0: case "got-chatbox-visibility": michael@0: if (e.data.result == "hidden") { michael@0: ok(true, "chatbox got minimized"); michael@0: chats.selectedChat.toggle(); michael@0: } else if (e.data.result == "shown") { michael@0: ok(true, "chatbox got shown"); michael@0: // close it now michael@0: let content = chats.selectedChat.content; michael@0: content.addEventListener("unload", function chatUnload() { michael@0: content.removeEventListener("unload", chatUnload, true); michael@0: ok(true, "got chatbox unload on close"); michael@0: port.close(); michael@0: next(); michael@0: }, true); michael@0: chats.selectedChat.close(); michael@0: } michael@0: break; michael@0: case "got-chatbox-message": michael@0: ok(true, "got chatbox message"); michael@0: ok(e.data.result == "ok", "got chatbox windowRef result: "+e.data.result); michael@0: chats.selectedChat.toggle(); michael@0: break; michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init", data: { id: 1 }}); michael@0: }, michael@0: testOpenMinimized: function(next) { michael@0: // In this case the sidebar opens a chat (without specifying minimized). michael@0: // We then minimize it and have the sidebar reopen the chat (again without michael@0: // minimized). On that second call the chat should open and no longer michael@0: // be minimized. michael@0: let chats = document.getElementById("pinnedchats"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: let seen_opened = false; michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: break; michael@0: case "chatbox-opened": michael@0: is(e.data.result, "ok", "the sidebar says it got a chatbox"); michael@0: if (!seen_opened) { michael@0: // first time we got the opened message, so minimize the chat then michael@0: // re-request the same chat to be opened - we should get the michael@0: // message again and the chat should be restored. michael@0: ok(!chats.selectedChat.minimized, "chat not initially minimized") michael@0: chats.selectedChat.minimized = true michael@0: seen_opened = true; michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: } else { michael@0: // This is the second time we've seen this message - there should michael@0: // be exactly 1 chat open and it should no longer be minimized. michael@0: let chats = document.getElementById("pinnedchats"); michael@0: ok(!chats.selectedChat.minimized, "chat no longer minimized") michael@0: chats.selectedChat.close(); michael@0: is(chats.selectedChat, null, "should only have been one chat open"); michael@0: port.close(); michael@0: next(); michael@0: } michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init", data: { id: 1 }}); michael@0: }, michael@0: testManyChats: function(next) { michael@0: // open enough chats to overflow the window, then check michael@0: // if the menupopup is visible michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: let chats = document.getElementById("pinnedchats"); michael@0: ok(port, "provider has a port"); michael@0: ok(chats.menupopup.parentNode.collapsed, "popup nub collapsed at start"); michael@0: port.postMessage({topic: "test-init"}); michael@0: // we should *never* find a test box that needs more than this to cause michael@0: // an overflow! michael@0: let maxToOpen = 20; michael@0: let numOpened = 0; michael@0: let maybeOpenAnother = function() { michael@0: if (numOpened++ >= maxToOpen) { michael@0: ok(false, "We didn't find a collapsed chat after " + maxToOpen + "chats!"); michael@0: closeAllChats(); michael@0: next(); michael@0: } michael@0: port.postMessage({topic: "test-chatbox-open", data: { id: numOpened }}); michael@0: } michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "got-chatbox-message": michael@0: if (!chats.menupopup.parentNode.collapsed) { michael@0: maybeOpenAnother(); michael@0: break; michael@0: } michael@0: ok(true, "popup nub became visible"); michael@0: // close our chats now michael@0: while (chats.selectedChat) { michael@0: chats.selectedChat.close(); michael@0: } michael@0: ok(!chats.selectedChat, "chats are all closed"); michael@0: port.close(); michael@0: next(); michael@0: break; michael@0: } michael@0: } michael@0: maybeOpenAnother(); michael@0: }, michael@0: testWorkerChatWindow: function(next) { michael@0: const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; michael@0: let chats = document.getElementById("pinnedchats"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.postMessage({topic: "test-init"}); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "got-chatbox-message": michael@0: ok(true, "got a chat window opened"); michael@0: ok(chats.selectedChat, "chatbox from worker opened"); michael@0: while (chats.selectedChat) { michael@0: chats.selectedChat.close(); michael@0: } michael@0: ok(!chats.selectedChat, "chats are all closed"); michael@0: gURLsNotRemembered.push(chatUrl); michael@0: port.close(); michael@0: next(); michael@0: break; michael@0: } michael@0: } michael@0: ok(!chats.selectedChat, "chats are all closed"); michael@0: port.postMessage({topic: "test-worker-chat", data: chatUrl}); michael@0: }, michael@0: testCloseSelf: function(next) { michael@0: let chats = document.getElementById("pinnedchats"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: break; michael@0: case "got-chatbox-visibility": michael@0: is(e.data.result, "shown", "chatbox shown"); michael@0: port.close(); // don't want any more visibility messages. michael@0: let chat = chats.selectedChat; michael@0: ok(chat.parentNode, "chat has a parent node before it is closed"); michael@0: // ask it to close itself. michael@0: let doc = chat.contentDocument; michael@0: let evt = doc.createEvent("CustomEvent"); michael@0: evt.initCustomEvent("socialTest-CloseSelf", true, true, {}); michael@0: doc.documentElement.dispatchEvent(evt); michael@0: ok(!chat.parentNode, "chat is now closed"); michael@0: port.close(); michael@0: next(); michael@0: break; michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init", data: { id: 1 }}); michael@0: }, michael@0: testSameChatCallbacks: function(next) { michael@0: let chats = document.getElementById("pinnedchats"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: let seen_opened = false; michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: break; michael@0: case "chatbox-opened": michael@0: is(e.data.result, "ok", "the sidebar says it got a chatbox"); michael@0: if (seen_opened) { michael@0: // This is the second time we've seen this message - there should michael@0: // be exactly 1 chat open. michael@0: let chats = document.getElementById("pinnedchats"); michael@0: chats.selectedChat.close(); michael@0: is(chats.selectedChat, null, "should only have been one chat open"); michael@0: port.close(); michael@0: next(); michael@0: } else { michael@0: // first time we got the opened message, so re-request the same michael@0: // chat to be opened - we should get the message again. michael@0: seen_opened = true; michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: } michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init", data: { id: 1 }}); michael@0: }, michael@0: michael@0: // check removeAll does the right thing michael@0: testRemoveAll: function(next, mode) { michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: port.postMessage({topic: "test-init"}); michael@0: get3ChatsForCollapsing(mode || "normal", function() { michael@0: let chatbar = window.SocialChatBar.chatbar; michael@0: chatbar.removeAll(); michael@0: // should be no evidence of any chats left. michael@0: is(chatbar.childNodes.length, 0, "should be no chats left"); michael@0: checkPopup(); michael@0: is(chatbar.selectedChat, null, "nothing should be selected"); michael@0: is(chatbar.chatboxForURL.size, 0, "chatboxForURL map should be empty"); michael@0: port.close(); michael@0: next(); michael@0: }); michael@0: }, michael@0: michael@0: testRemoveAllMinimized: function(next) { michael@0: this.testRemoveAll(next, "minimized"); michael@0: }, michael@0: michael@0: // Check what happens when you close the only visible chat. michael@0: testCloseOnlyVisible: function(next) { michael@0: let chatbar = window.SocialChatBar.chatbar; michael@0: let chatWidth = undefined; michael@0: let num = 0; michael@0: is(chatbar.childNodes.length, 0, "chatbar starting empty"); michael@0: is(chatbar.menupopup.childNodes.length, 0, "popup starting empty"); michael@0: michael@0: makeChat("normal", "first chat", function() { michael@0: // got the first one. michael@0: checkPopup(); michael@0: ok(chatbar.menupopup.parentNode.collapsed, "menu selection isn't visible"); michael@0: // we kinda cheat here and get the width of the first chat, assuming michael@0: // that all future chats will have the same width when open. michael@0: chatWidth = chatbar.calcTotalWidthOf(chatbar.selectedChat); michael@0: let desired = chatWidth * 1.5; michael@0: resizeWindowToChatAreaWidth(desired, function(sizedOk) { michael@0: ok(sizedOk, "can't do any tests without this width"); michael@0: checkPopup(); michael@0: makeChat("normal", "second chat", function() { michael@0: is(chatbar.childNodes.length, 2, "now have 2 chats"); michael@0: let first = chatbar.childNodes[0]; michael@0: let second = chatbar.childNodes[1]; michael@0: is(chatbar.selectedChat, first, "first chat is selected"); michael@0: ok(second.collapsed, "second chat is currently collapsed"); michael@0: // closing the first chat will leave enough room for the second michael@0: // chat to appear, and thus become selected. michael@0: chatbar.selectedChat.close(); michael@0: is(chatbar.selectedChat, second, "second chat is selected"); michael@0: closeAllChats(); michael@0: next(); michael@0: }); michael@0: }); michael@0: }); michael@0: }, michael@0: michael@0: testShowWhenCollapsed: function(next) { michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: port.postMessage({topic: "test-init"}); michael@0: get3ChatsForCollapsing("normal", function(first, second, third) { michael@0: let chatbar = window.SocialChatBar.chatbar; michael@0: chatbar.showChat(first); michael@0: ok(!first.collapsed, "first should no longer be collapsed"); michael@0: ok(second.collapsed || third.collapsed, false, "one of the others should be collapsed"); michael@0: closeAllChats(); michael@0: port.close(); michael@0: next(); michael@0: }); michael@0: }, michael@0: michael@0: testActivity: function(next) { michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: port.postMessage({topic: "test-init"}); michael@0: get3ChatsForCollapsing("normal", function(first, second, third) { michael@0: let chatbar = window.SocialChatBar.chatbar; michael@0: is(chatbar.selectedChat, third, "third chat should be selected"); michael@0: ok(!chatbar.selectedChat.hasAttribute("activity"), "third chat should have no activity"); michael@0: // send an activity message to the second. michael@0: ok(!second.hasAttribute("activity"), "second chat should have no activity"); michael@0: let chat2 = second.content; michael@0: let evt = chat2.contentDocument.createEvent("CustomEvent"); michael@0: evt.initCustomEvent("socialChatActivity", true, true, {}); michael@0: chat2.contentDocument.documentElement.dispatchEvent(evt); michael@0: // second should have activity. michael@0: ok(second.hasAttribute("activity"), "second chat should now have activity"); michael@0: // select the second - it should lose "activity" michael@0: chatbar.selectedChat = second; michael@0: ok(!second.hasAttribute("activity"), "second chat should no longer have activity"); michael@0: // Now try the first - it is collapsed, so the 'nub' also gets activity attr. michael@0: ok(!first.hasAttribute("activity"), "first chat should have no activity"); michael@0: let chat1 = first.content; michael@0: let evt = chat1.contentDocument.createEvent("CustomEvent"); michael@0: evt.initCustomEvent("socialChatActivity", true, true, {}); michael@0: chat1.contentDocument.documentElement.dispatchEvent(evt); michael@0: ok(first.hasAttribute("activity"), "first chat should now have activity"); michael@0: ok(chatbar.nub.hasAttribute("activity"), "nub should also have activity"); michael@0: // first is collapsed, so use openChat to get it. michael@0: chatbar.openChat(SocialSidebar.provider, first.getAttribute("src")); michael@0: ok(!first.hasAttribute("activity"), "first chat should no longer have activity"); michael@0: // The nub should lose the activity flag here too michael@0: todo(!chatbar.nub.hasAttribute("activity"), "Bug 806266 - nub should no longer have activity"); michael@0: // TODO: tests for bug 806266 should arrange to have 2 chats collapsed michael@0: // then open them checking the nub is updated correctly. michael@0: // Now we will go and change the embedded browser in the second chat and michael@0: // ensure the activity magic still works (ie, check that the unload for michael@0: // the browser didn't cause our event handlers to be removed.) michael@0: ok(!second.hasAttribute("activity"), "second chat should have no activity"); michael@0: let subiframe = chat2.contentDocument.getElementById("iframe"); michael@0: subiframe.contentWindow.addEventListener("unload", function subunload() { michael@0: subiframe.contentWindow.removeEventListener("unload", subunload); michael@0: // ensure all other unload listeners have fired. michael@0: executeSoon(function() { michael@0: let evt = chat2.contentDocument.createEvent("CustomEvent"); michael@0: evt.initCustomEvent("socialChatActivity", true, true, {}); michael@0: chat2.contentDocument.documentElement.dispatchEvent(evt); michael@0: ok(second.hasAttribute("activity"), "second chat still has activity after unloading sub-iframe"); michael@0: closeAllChats(); michael@0: port.close(); michael@0: next(); michael@0: }) michael@0: }) michael@0: subiframe.setAttribute("src", "data:text/plain:new location for iframe"); michael@0: }); michael@0: }, michael@0: michael@0: testOnlyOneCallback: function(next) { michael@0: let chats = document.getElementById("pinnedchats"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: let numOpened = 0; michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-chatbox-open"}); michael@0: break; michael@0: case "chatbox-opened": michael@0: numOpened += 1; michael@0: port.postMessage({topic: "ping"}); michael@0: break; michael@0: case "pong": michael@0: executeSoon(function() { michael@0: is(numOpened, 1, "only got one open message"); michael@0: chats.removeAll(); michael@0: port.close(); michael@0: next(); michael@0: }); michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init", data: { id: 1 }}); michael@0: }, michael@0: michael@0: testSecondTopLevelWindow: function(next) { michael@0: // Bug 817782 - check chats work in new top-level windows. michael@0: const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: let secondWindow; michael@0: port.onmessage = function(e) { michael@0: if (e.data.topic == "test-init-done") { michael@0: secondWindow = OpenBrowserWindow(); michael@0: secondWindow.addEventListener("load", function loadListener() { michael@0: secondWindow.removeEventListener("load", loadListener); michael@0: port.postMessage({topic: "test-worker-chat", data: chatUrl}); michael@0: }); michael@0: } else if (e.data.topic == "got-chatbox-message") { michael@0: // the chat was created - let's make sure it was created in the second window. michael@0: is(secondWindow.SocialChatBar.chatbar.childElementCount, 1); michael@0: secondWindow.close(); michael@0: next(); michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init"}); michael@0: }, michael@0: michael@0: testChatWindowChooser: function(next) { michael@0: // Tests that when a worker creates a chat, it is opened in the correct michael@0: // window. michael@0: // open a chat (it will open in the main window) michael@0: ok(!window.SocialChatBar.hasChats, "first window should start with no chats"); michael@0: openChat(SocialSidebar.provider, function() { michael@0: ok(window.SocialChatBar.hasChats, "first window has the chat"); michael@0: // create a second window - this will be the "most recent" and will michael@0: // therefore be the window that hosts the new chat (see bug 835111) michael@0: let secondWindow = OpenBrowserWindow(); michael@0: secondWindow.addEventListener("load", function loadListener() { michael@0: secondWindow.removeEventListener("load", loadListener); michael@0: ok(!secondWindow.SocialChatBar.hasChats, "second window has no chats"); michael@0: openChat(SocialSidebar.provider, function() { michael@0: ok(secondWindow.SocialChatBar.hasChats, "second window now has chats"); michael@0: is(window.SocialChatBar.chatbar.childElementCount, 1, "first window still has 1 chat"); michael@0: window.SocialChatBar.chatbar.removeAll(); michael@0: // now open another chat - it should still open in the second. michael@0: openChat(SocialSidebar.provider, function() { michael@0: ok(!window.SocialChatBar.hasChats, "first window has no chats"); michael@0: ok(secondWindow.SocialChatBar.hasChats, "second window has a chat"); michael@0: michael@0: // focus the first window, and open yet another chat - it michael@0: // should open in the first window. michael@0: waitForFocus(function() { michael@0: openChat(SocialSidebar.provider, function() { michael@0: ok(window.SocialChatBar.hasChats, "first window has chats"); michael@0: window.SocialChatBar.chatbar.removeAll(); michael@0: ok(!window.SocialChatBar.hasChats, "first window has no chats"); michael@0: michael@0: let privateWindow = OpenBrowserWindow({private: true}); michael@0: privateWindow.addEventListener("load", function loadListener() { michael@0: privateWindow.removeEventListener("load", loadListener); michael@0: michael@0: // open a last chat - the focused window can't accept michael@0: // chats (it's a private window), so the chat should open michael@0: // in the window that was selected before. This is known michael@0: // to be broken on Linux. michael@0: openChat(SocialSidebar.provider, function() { michael@0: let os = Services.appinfo.OS; michael@0: const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin"; michael@0: let fn = BROKEN_WM_Z_ORDER ? todo : ok; michael@0: fn(window.SocialChatBar.hasChats, "first window has a chat"); michael@0: window.SocialChatBar.chatbar.removeAll(); michael@0: michael@0: privateWindow.close(); michael@0: secondWindow.close(); michael@0: next(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: window.focus(); michael@0: }); michael@0: }); michael@0: }) michael@0: }); michael@0: }, michael@0: testMultipleProviderChat: function(next) { michael@0: // test incomming chats from all providers michael@0: openChat(Social.providers[0], function() { michael@0: openChat(Social.providers[1], function() { michael@0: openChat(Social.providers[2], function() { michael@0: let chats = document.getElementById("pinnedchats"); michael@0: waitForCondition(function() chats.children.length == Social.providers.length, michael@0: function() { michael@0: ok(true, "one chat window per provider opened"); michael@0: // test logout of a single provider michael@0: let provider = Social.providers[2]; michael@0: let port = provider.getWorkerPort(); michael@0: port.postMessage({topic: "test-logout"}); michael@0: waitForCondition(function() chats.children.length == Social.providers.length - 1, michael@0: function() { michael@0: chats.removeAll(); michael@0: waitForCondition(function() chats.children.length == 0, michael@0: function() { michael@0: ok(!chats.selectedChat, "multiprovider chats are all closed"); michael@0: port.close(); michael@0: next(); michael@0: }, michael@0: "chat windows didn't close"); michael@0: }, michael@0: "chat window didn't close"); michael@0: }, "chat windows did not open"); michael@0: }); michael@0: }); michael@0: }); michael@0: }, michael@0: michael@0: // XXX - note this must be the last test until we restore the login state michael@0: // between tests... michael@0: testCloseOnLogout: function(next) { michael@0: const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: let opened = false; michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: info("open first chat window"); michael@0: port.postMessage({topic: "test-worker-chat", data: chatUrl}); michael@0: break; michael@0: case "got-chatbox-message": michael@0: ok(true, "got a chat window opened"); michael@0: if (opened) { michael@0: port.postMessage({topic: "test-logout"}); michael@0: waitForCondition(function() document.getElementById("pinnedchats").firstChild == null, michael@0: function() { michael@0: port.close(); michael@0: next(); michael@0: }, michael@0: "chat windows didn't close"); michael@0: } else { michael@0: // open a second chat window michael@0: opened = true; michael@0: port.postMessage({topic: "test-worker-chat", data: chatUrl+"?id=1"}); michael@0: } michael@0: break; michael@0: } michael@0: } michael@0: // make sure a user profile is set for this provider as chat windows are michael@0: // only closed on *change* of the profile data rather than merely setting michael@0: // profile data. michael@0: port.postMessage({topic: "test-set-profile"}); michael@0: port.postMessage({topic: "test-init"}); michael@0: } michael@0: }