browser/base/content/test/social/browser_social_chatwindow.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
michael@0 6
michael@0 7 let manifests = [
michael@0 8 {
michael@0 9 name: "provider@example.com",
michael@0 10 origin: "https://example.com",
michael@0 11 sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?example.com",
michael@0 12 workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
michael@0 13 iconURL: "chrome://branding/content/icon48.png"
michael@0 14 },
michael@0 15 {
michael@0 16 name: "provider@test1",
michael@0 17 origin: "https://test1.example.com",
michael@0 18 sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?test1",
michael@0 19 workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
michael@0 20 iconURL: "chrome://branding/content/icon48.png"
michael@0 21 },
michael@0 22 {
michael@0 23 name: "provider@test2",
michael@0 24 origin: "https://test2.example.com",
michael@0 25 sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?test2",
michael@0 26 workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js",
michael@0 27 iconURL: "chrome://branding/content/icon48.png"
michael@0 28 }
michael@0 29 ];
michael@0 30
michael@0 31 let chatId = 0;
michael@0 32 function openChat(provider, callback) {
michael@0 33 let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
michael@0 34 let port = provider.getWorkerPort();
michael@0 35 port.onmessage = function(e) {
michael@0 36 if (e.data.topic == "got-chatbox-message") {
michael@0 37 port.close();
michael@0 38 callback();
michael@0 39 }
michael@0 40 }
michael@0 41 let url = chatUrl + "?" + (chatId++);
michael@0 42 port.postMessage({topic: "test-init"});
michael@0 43 port.postMessage({topic: "test-worker-chat", data: url});
michael@0 44 gURLsNotRemembered.push(url);
michael@0 45 }
michael@0 46
michael@0 47 function test() {
michael@0 48 requestLongerTimeout(2); // only debug builds seem to need more time...
michael@0 49 waitForExplicitFinish();
michael@0 50
michael@0 51 let oldwidth = window.outerWidth; // we futz with these, so we restore them
michael@0 52 let oldleft = window.screenX;
michael@0 53 window.moveTo(0, window.screenY)
michael@0 54 let postSubTest = function(cb) {
michael@0 55 let chats = document.getElementById("pinnedchats");
michael@0 56 ok(chats.children.length == 0, "no chatty children left behind");
michael@0 57 cb();
michael@0 58 };
michael@0 59 runSocialTestWithProvider(manifests, function (finishcb) {
michael@0 60 ok(Social.enabled, "Social is enabled");
michael@0 61 ok(Social.providers[0].getWorkerPort(), "provider 0 has port");
michael@0 62 ok(Social.providers[1].getWorkerPort(), "provider 1 has port");
michael@0 63 ok(Social.providers[2].getWorkerPort(), "provider 2 has port");
michael@0 64 SocialSidebar.show();
michael@0 65 runSocialTests(tests, undefined, postSubTest, function() {
michael@0 66 window.moveTo(oldleft, window.screenY)
michael@0 67 window.resizeTo(oldwidth, window.outerHeight);
michael@0 68 finishcb();
michael@0 69 });
michael@0 70 });
michael@0 71 }
michael@0 72
michael@0 73 var tests = {
michael@0 74 testOpenCloseChat: function(next) {
michael@0 75 let chats = document.getElementById("pinnedchats");
michael@0 76 let port = SocialSidebar.provider.getWorkerPort();
michael@0 77 ok(port, "provider has a port");
michael@0 78 port.onmessage = function (e) {
michael@0 79 let topic = e.data.topic;
michael@0 80 switch (topic) {
michael@0 81 case "got-sidebar-message":
michael@0 82 port.postMessage({topic: "test-chatbox-open"});
michael@0 83 break;
michael@0 84 case "got-chatbox-visibility":
michael@0 85 if (e.data.result == "hidden") {
michael@0 86 ok(true, "chatbox got minimized");
michael@0 87 chats.selectedChat.toggle();
michael@0 88 } else if (e.data.result == "shown") {
michael@0 89 ok(true, "chatbox got shown");
michael@0 90 // close it now
michael@0 91 let content = chats.selectedChat.content;
michael@0 92 content.addEventListener("unload", function chatUnload() {
michael@0 93 content.removeEventListener("unload", chatUnload, true);
michael@0 94 ok(true, "got chatbox unload on close");
michael@0 95 port.close();
michael@0 96 next();
michael@0 97 }, true);
michael@0 98 chats.selectedChat.close();
michael@0 99 }
michael@0 100 break;
michael@0 101 case "got-chatbox-message":
michael@0 102 ok(true, "got chatbox message");
michael@0 103 ok(e.data.result == "ok", "got chatbox windowRef result: "+e.data.result);
michael@0 104 chats.selectedChat.toggle();
michael@0 105 break;
michael@0 106 }
michael@0 107 }
michael@0 108 port.postMessage({topic: "test-init", data: { id: 1 }});
michael@0 109 },
michael@0 110 testOpenMinimized: function(next) {
michael@0 111 // In this case the sidebar opens a chat (without specifying minimized).
michael@0 112 // We then minimize it and have the sidebar reopen the chat (again without
michael@0 113 // minimized). On that second call the chat should open and no longer
michael@0 114 // be minimized.
michael@0 115 let chats = document.getElementById("pinnedchats");
michael@0 116 let port = SocialSidebar.provider.getWorkerPort();
michael@0 117 let seen_opened = false;
michael@0 118 port.onmessage = function (e) {
michael@0 119 let topic = e.data.topic;
michael@0 120 switch (topic) {
michael@0 121 case "test-init-done":
michael@0 122 port.postMessage({topic: "test-chatbox-open"});
michael@0 123 break;
michael@0 124 case "chatbox-opened":
michael@0 125 is(e.data.result, "ok", "the sidebar says it got a chatbox");
michael@0 126 if (!seen_opened) {
michael@0 127 // first time we got the opened message, so minimize the chat then
michael@0 128 // re-request the same chat to be opened - we should get the
michael@0 129 // message again and the chat should be restored.
michael@0 130 ok(!chats.selectedChat.minimized, "chat not initially minimized")
michael@0 131 chats.selectedChat.minimized = true
michael@0 132 seen_opened = true;
michael@0 133 port.postMessage({topic: "test-chatbox-open"});
michael@0 134 } else {
michael@0 135 // This is the second time we've seen this message - there should
michael@0 136 // be exactly 1 chat open and it should no longer be minimized.
michael@0 137 let chats = document.getElementById("pinnedchats");
michael@0 138 ok(!chats.selectedChat.minimized, "chat no longer minimized")
michael@0 139 chats.selectedChat.close();
michael@0 140 is(chats.selectedChat, null, "should only have been one chat open");
michael@0 141 port.close();
michael@0 142 next();
michael@0 143 }
michael@0 144 }
michael@0 145 }
michael@0 146 port.postMessage({topic: "test-init", data: { id: 1 }});
michael@0 147 },
michael@0 148 testManyChats: function(next) {
michael@0 149 // open enough chats to overflow the window, then check
michael@0 150 // if the menupopup is visible
michael@0 151 let port = SocialSidebar.provider.getWorkerPort();
michael@0 152 let chats = document.getElementById("pinnedchats");
michael@0 153 ok(port, "provider has a port");
michael@0 154 ok(chats.menupopup.parentNode.collapsed, "popup nub collapsed at start");
michael@0 155 port.postMessage({topic: "test-init"});
michael@0 156 // we should *never* find a test box that needs more than this to cause
michael@0 157 // an overflow!
michael@0 158 let maxToOpen = 20;
michael@0 159 let numOpened = 0;
michael@0 160 let maybeOpenAnother = function() {
michael@0 161 if (numOpened++ >= maxToOpen) {
michael@0 162 ok(false, "We didn't find a collapsed chat after " + maxToOpen + "chats!");
michael@0 163 closeAllChats();
michael@0 164 next();
michael@0 165 }
michael@0 166 port.postMessage({topic: "test-chatbox-open", data: { id: numOpened }});
michael@0 167 }
michael@0 168 port.onmessage = function (e) {
michael@0 169 let topic = e.data.topic;
michael@0 170 switch (topic) {
michael@0 171 case "got-chatbox-message":
michael@0 172 if (!chats.menupopup.parentNode.collapsed) {
michael@0 173 maybeOpenAnother();
michael@0 174 break;
michael@0 175 }
michael@0 176 ok(true, "popup nub became visible");
michael@0 177 // close our chats now
michael@0 178 while (chats.selectedChat) {
michael@0 179 chats.selectedChat.close();
michael@0 180 }
michael@0 181 ok(!chats.selectedChat, "chats are all closed");
michael@0 182 port.close();
michael@0 183 next();
michael@0 184 break;
michael@0 185 }
michael@0 186 }
michael@0 187 maybeOpenAnother();
michael@0 188 },
michael@0 189 testWorkerChatWindow: function(next) {
michael@0 190 const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
michael@0 191 let chats = document.getElementById("pinnedchats");
michael@0 192 let port = SocialSidebar.provider.getWorkerPort();
michael@0 193 ok(port, "provider has a port");
michael@0 194 port.postMessage({topic: "test-init"});
michael@0 195 port.onmessage = function (e) {
michael@0 196 let topic = e.data.topic;
michael@0 197 switch (topic) {
michael@0 198 case "got-chatbox-message":
michael@0 199 ok(true, "got a chat window opened");
michael@0 200 ok(chats.selectedChat, "chatbox from worker opened");
michael@0 201 while (chats.selectedChat) {
michael@0 202 chats.selectedChat.close();
michael@0 203 }
michael@0 204 ok(!chats.selectedChat, "chats are all closed");
michael@0 205 gURLsNotRemembered.push(chatUrl);
michael@0 206 port.close();
michael@0 207 next();
michael@0 208 break;
michael@0 209 }
michael@0 210 }
michael@0 211 ok(!chats.selectedChat, "chats are all closed");
michael@0 212 port.postMessage({topic: "test-worker-chat", data: chatUrl});
michael@0 213 },
michael@0 214 testCloseSelf: function(next) {
michael@0 215 let chats = document.getElementById("pinnedchats");
michael@0 216 let port = SocialSidebar.provider.getWorkerPort();
michael@0 217 ok(port, "provider has a port");
michael@0 218 port.onmessage = function (e) {
michael@0 219 let topic = e.data.topic;
michael@0 220 switch (topic) {
michael@0 221 case "test-init-done":
michael@0 222 port.postMessage({topic: "test-chatbox-open"});
michael@0 223 break;
michael@0 224 case "got-chatbox-visibility":
michael@0 225 is(e.data.result, "shown", "chatbox shown");
michael@0 226 port.close(); // don't want any more visibility messages.
michael@0 227 let chat = chats.selectedChat;
michael@0 228 ok(chat.parentNode, "chat has a parent node before it is closed");
michael@0 229 // ask it to close itself.
michael@0 230 let doc = chat.contentDocument;
michael@0 231 let evt = doc.createEvent("CustomEvent");
michael@0 232 evt.initCustomEvent("socialTest-CloseSelf", true, true, {});
michael@0 233 doc.documentElement.dispatchEvent(evt);
michael@0 234 ok(!chat.parentNode, "chat is now closed");
michael@0 235 port.close();
michael@0 236 next();
michael@0 237 break;
michael@0 238 }
michael@0 239 }
michael@0 240 port.postMessage({topic: "test-init", data: { id: 1 }});
michael@0 241 },
michael@0 242 testSameChatCallbacks: function(next) {
michael@0 243 let chats = document.getElementById("pinnedchats");
michael@0 244 let port = SocialSidebar.provider.getWorkerPort();
michael@0 245 let seen_opened = false;
michael@0 246 port.onmessage = function (e) {
michael@0 247 let topic = e.data.topic;
michael@0 248 switch (topic) {
michael@0 249 case "test-init-done":
michael@0 250 port.postMessage({topic: "test-chatbox-open"});
michael@0 251 break;
michael@0 252 case "chatbox-opened":
michael@0 253 is(e.data.result, "ok", "the sidebar says it got a chatbox");
michael@0 254 if (seen_opened) {
michael@0 255 // This is the second time we've seen this message - there should
michael@0 256 // be exactly 1 chat open.
michael@0 257 let chats = document.getElementById("pinnedchats");
michael@0 258 chats.selectedChat.close();
michael@0 259 is(chats.selectedChat, null, "should only have been one chat open");
michael@0 260 port.close();
michael@0 261 next();
michael@0 262 } else {
michael@0 263 // first time we got the opened message, so re-request the same
michael@0 264 // chat to be opened - we should get the message again.
michael@0 265 seen_opened = true;
michael@0 266 port.postMessage({topic: "test-chatbox-open"});
michael@0 267 }
michael@0 268 }
michael@0 269 }
michael@0 270 port.postMessage({topic: "test-init", data: { id: 1 }});
michael@0 271 },
michael@0 272
michael@0 273 // check removeAll does the right thing
michael@0 274 testRemoveAll: function(next, mode) {
michael@0 275 let port = SocialSidebar.provider.getWorkerPort();
michael@0 276 port.postMessage({topic: "test-init"});
michael@0 277 get3ChatsForCollapsing(mode || "normal", function() {
michael@0 278 let chatbar = window.SocialChatBar.chatbar;
michael@0 279 chatbar.removeAll();
michael@0 280 // should be no evidence of any chats left.
michael@0 281 is(chatbar.childNodes.length, 0, "should be no chats left");
michael@0 282 checkPopup();
michael@0 283 is(chatbar.selectedChat, null, "nothing should be selected");
michael@0 284 is(chatbar.chatboxForURL.size, 0, "chatboxForURL map should be empty");
michael@0 285 port.close();
michael@0 286 next();
michael@0 287 });
michael@0 288 },
michael@0 289
michael@0 290 testRemoveAllMinimized: function(next) {
michael@0 291 this.testRemoveAll(next, "minimized");
michael@0 292 },
michael@0 293
michael@0 294 // Check what happens when you close the only visible chat.
michael@0 295 testCloseOnlyVisible: function(next) {
michael@0 296 let chatbar = window.SocialChatBar.chatbar;
michael@0 297 let chatWidth = undefined;
michael@0 298 let num = 0;
michael@0 299 is(chatbar.childNodes.length, 0, "chatbar starting empty");
michael@0 300 is(chatbar.menupopup.childNodes.length, 0, "popup starting empty");
michael@0 301
michael@0 302 makeChat("normal", "first chat", function() {
michael@0 303 // got the first one.
michael@0 304 checkPopup();
michael@0 305 ok(chatbar.menupopup.parentNode.collapsed, "menu selection isn't visible");
michael@0 306 // we kinda cheat here and get the width of the first chat, assuming
michael@0 307 // that all future chats will have the same width when open.
michael@0 308 chatWidth = chatbar.calcTotalWidthOf(chatbar.selectedChat);
michael@0 309 let desired = chatWidth * 1.5;
michael@0 310 resizeWindowToChatAreaWidth(desired, function(sizedOk) {
michael@0 311 ok(sizedOk, "can't do any tests without this width");
michael@0 312 checkPopup();
michael@0 313 makeChat("normal", "second chat", function() {
michael@0 314 is(chatbar.childNodes.length, 2, "now have 2 chats");
michael@0 315 let first = chatbar.childNodes[0];
michael@0 316 let second = chatbar.childNodes[1];
michael@0 317 is(chatbar.selectedChat, first, "first chat is selected");
michael@0 318 ok(second.collapsed, "second chat is currently collapsed");
michael@0 319 // closing the first chat will leave enough room for the second
michael@0 320 // chat to appear, and thus become selected.
michael@0 321 chatbar.selectedChat.close();
michael@0 322 is(chatbar.selectedChat, second, "second chat is selected");
michael@0 323 closeAllChats();
michael@0 324 next();
michael@0 325 });
michael@0 326 });
michael@0 327 });
michael@0 328 },
michael@0 329
michael@0 330 testShowWhenCollapsed: function(next) {
michael@0 331 let port = SocialSidebar.provider.getWorkerPort();
michael@0 332 port.postMessage({topic: "test-init"});
michael@0 333 get3ChatsForCollapsing("normal", function(first, second, third) {
michael@0 334 let chatbar = window.SocialChatBar.chatbar;
michael@0 335 chatbar.showChat(first);
michael@0 336 ok(!first.collapsed, "first should no longer be collapsed");
michael@0 337 ok(second.collapsed || third.collapsed, false, "one of the others should be collapsed");
michael@0 338 closeAllChats();
michael@0 339 port.close();
michael@0 340 next();
michael@0 341 });
michael@0 342 },
michael@0 343
michael@0 344 testActivity: function(next) {
michael@0 345 let port = SocialSidebar.provider.getWorkerPort();
michael@0 346 port.postMessage({topic: "test-init"});
michael@0 347 get3ChatsForCollapsing("normal", function(first, second, third) {
michael@0 348 let chatbar = window.SocialChatBar.chatbar;
michael@0 349 is(chatbar.selectedChat, third, "third chat should be selected");
michael@0 350 ok(!chatbar.selectedChat.hasAttribute("activity"), "third chat should have no activity");
michael@0 351 // send an activity message to the second.
michael@0 352 ok(!second.hasAttribute("activity"), "second chat should have no activity");
michael@0 353 let chat2 = second.content;
michael@0 354 let evt = chat2.contentDocument.createEvent("CustomEvent");
michael@0 355 evt.initCustomEvent("socialChatActivity", true, true, {});
michael@0 356 chat2.contentDocument.documentElement.dispatchEvent(evt);
michael@0 357 // second should have activity.
michael@0 358 ok(second.hasAttribute("activity"), "second chat should now have activity");
michael@0 359 // select the second - it should lose "activity"
michael@0 360 chatbar.selectedChat = second;
michael@0 361 ok(!second.hasAttribute("activity"), "second chat should no longer have activity");
michael@0 362 // Now try the first - it is collapsed, so the 'nub' also gets activity attr.
michael@0 363 ok(!first.hasAttribute("activity"), "first chat should have no activity");
michael@0 364 let chat1 = first.content;
michael@0 365 let evt = chat1.contentDocument.createEvent("CustomEvent");
michael@0 366 evt.initCustomEvent("socialChatActivity", true, true, {});
michael@0 367 chat1.contentDocument.documentElement.dispatchEvent(evt);
michael@0 368 ok(first.hasAttribute("activity"), "first chat should now have activity");
michael@0 369 ok(chatbar.nub.hasAttribute("activity"), "nub should also have activity");
michael@0 370 // first is collapsed, so use openChat to get it.
michael@0 371 chatbar.openChat(SocialSidebar.provider, first.getAttribute("src"));
michael@0 372 ok(!first.hasAttribute("activity"), "first chat should no longer have activity");
michael@0 373 // The nub should lose the activity flag here too
michael@0 374 todo(!chatbar.nub.hasAttribute("activity"), "Bug 806266 - nub should no longer have activity");
michael@0 375 // TODO: tests for bug 806266 should arrange to have 2 chats collapsed
michael@0 376 // then open them checking the nub is updated correctly.
michael@0 377 // Now we will go and change the embedded browser in the second chat and
michael@0 378 // ensure the activity magic still works (ie, check that the unload for
michael@0 379 // the browser didn't cause our event handlers to be removed.)
michael@0 380 ok(!second.hasAttribute("activity"), "second chat should have no activity");
michael@0 381 let subiframe = chat2.contentDocument.getElementById("iframe");
michael@0 382 subiframe.contentWindow.addEventListener("unload", function subunload() {
michael@0 383 subiframe.contentWindow.removeEventListener("unload", subunload);
michael@0 384 // ensure all other unload listeners have fired.
michael@0 385 executeSoon(function() {
michael@0 386 let evt = chat2.contentDocument.createEvent("CustomEvent");
michael@0 387 evt.initCustomEvent("socialChatActivity", true, true, {});
michael@0 388 chat2.contentDocument.documentElement.dispatchEvent(evt);
michael@0 389 ok(second.hasAttribute("activity"), "second chat still has activity after unloading sub-iframe");
michael@0 390 closeAllChats();
michael@0 391 port.close();
michael@0 392 next();
michael@0 393 })
michael@0 394 })
michael@0 395 subiframe.setAttribute("src", "data:text/plain:new location for iframe");
michael@0 396 });
michael@0 397 },
michael@0 398
michael@0 399 testOnlyOneCallback: function(next) {
michael@0 400 let chats = document.getElementById("pinnedchats");
michael@0 401 let port = SocialSidebar.provider.getWorkerPort();
michael@0 402 let numOpened = 0;
michael@0 403 port.onmessage = function (e) {
michael@0 404 let topic = e.data.topic;
michael@0 405 switch (topic) {
michael@0 406 case "test-init-done":
michael@0 407 port.postMessage({topic: "test-chatbox-open"});
michael@0 408 break;
michael@0 409 case "chatbox-opened":
michael@0 410 numOpened += 1;
michael@0 411 port.postMessage({topic: "ping"});
michael@0 412 break;
michael@0 413 case "pong":
michael@0 414 executeSoon(function() {
michael@0 415 is(numOpened, 1, "only got one open message");
michael@0 416 chats.removeAll();
michael@0 417 port.close();
michael@0 418 next();
michael@0 419 });
michael@0 420 }
michael@0 421 }
michael@0 422 port.postMessage({topic: "test-init", data: { id: 1 }});
michael@0 423 },
michael@0 424
michael@0 425 testSecondTopLevelWindow: function(next) {
michael@0 426 // Bug 817782 - check chats work in new top-level windows.
michael@0 427 const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
michael@0 428 let port = SocialSidebar.provider.getWorkerPort();
michael@0 429 let secondWindow;
michael@0 430 port.onmessage = function(e) {
michael@0 431 if (e.data.topic == "test-init-done") {
michael@0 432 secondWindow = OpenBrowserWindow();
michael@0 433 secondWindow.addEventListener("load", function loadListener() {
michael@0 434 secondWindow.removeEventListener("load", loadListener);
michael@0 435 port.postMessage({topic: "test-worker-chat", data: chatUrl});
michael@0 436 });
michael@0 437 } else if (e.data.topic == "got-chatbox-message") {
michael@0 438 // the chat was created - let's make sure it was created in the second window.
michael@0 439 is(secondWindow.SocialChatBar.chatbar.childElementCount, 1);
michael@0 440 secondWindow.close();
michael@0 441 next();
michael@0 442 }
michael@0 443 }
michael@0 444 port.postMessage({topic: "test-init"});
michael@0 445 },
michael@0 446
michael@0 447 testChatWindowChooser: function(next) {
michael@0 448 // Tests that when a worker creates a chat, it is opened in the correct
michael@0 449 // window.
michael@0 450 // open a chat (it will open in the main window)
michael@0 451 ok(!window.SocialChatBar.hasChats, "first window should start with no chats");
michael@0 452 openChat(SocialSidebar.provider, function() {
michael@0 453 ok(window.SocialChatBar.hasChats, "first window has the chat");
michael@0 454 // create a second window - this will be the "most recent" and will
michael@0 455 // therefore be the window that hosts the new chat (see bug 835111)
michael@0 456 let secondWindow = OpenBrowserWindow();
michael@0 457 secondWindow.addEventListener("load", function loadListener() {
michael@0 458 secondWindow.removeEventListener("load", loadListener);
michael@0 459 ok(!secondWindow.SocialChatBar.hasChats, "second window has no chats");
michael@0 460 openChat(SocialSidebar.provider, function() {
michael@0 461 ok(secondWindow.SocialChatBar.hasChats, "second window now has chats");
michael@0 462 is(window.SocialChatBar.chatbar.childElementCount, 1, "first window still has 1 chat");
michael@0 463 window.SocialChatBar.chatbar.removeAll();
michael@0 464 // now open another chat - it should still open in the second.
michael@0 465 openChat(SocialSidebar.provider, function() {
michael@0 466 ok(!window.SocialChatBar.hasChats, "first window has no chats");
michael@0 467 ok(secondWindow.SocialChatBar.hasChats, "second window has a chat");
michael@0 468
michael@0 469 // focus the first window, and open yet another chat - it
michael@0 470 // should open in the first window.
michael@0 471 waitForFocus(function() {
michael@0 472 openChat(SocialSidebar.provider, function() {
michael@0 473 ok(window.SocialChatBar.hasChats, "first window has chats");
michael@0 474 window.SocialChatBar.chatbar.removeAll();
michael@0 475 ok(!window.SocialChatBar.hasChats, "first window has no chats");
michael@0 476
michael@0 477 let privateWindow = OpenBrowserWindow({private: true});
michael@0 478 privateWindow.addEventListener("load", function loadListener() {
michael@0 479 privateWindow.removeEventListener("load", loadListener);
michael@0 480
michael@0 481 // open a last chat - the focused window can't accept
michael@0 482 // chats (it's a private window), so the chat should open
michael@0 483 // in the window that was selected before. This is known
michael@0 484 // to be broken on Linux.
michael@0 485 openChat(SocialSidebar.provider, function() {
michael@0 486 let os = Services.appinfo.OS;
michael@0 487 const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin";
michael@0 488 let fn = BROKEN_WM_Z_ORDER ? todo : ok;
michael@0 489 fn(window.SocialChatBar.hasChats, "first window has a chat");
michael@0 490 window.SocialChatBar.chatbar.removeAll();
michael@0 491
michael@0 492 privateWindow.close();
michael@0 493 secondWindow.close();
michael@0 494 next();
michael@0 495 });
michael@0 496 });
michael@0 497 });
michael@0 498 });
michael@0 499 window.focus();
michael@0 500 });
michael@0 501 });
michael@0 502 })
michael@0 503 });
michael@0 504 },
michael@0 505 testMultipleProviderChat: function(next) {
michael@0 506 // test incomming chats from all providers
michael@0 507 openChat(Social.providers[0], function() {
michael@0 508 openChat(Social.providers[1], function() {
michael@0 509 openChat(Social.providers[2], function() {
michael@0 510 let chats = document.getElementById("pinnedchats");
michael@0 511 waitForCondition(function() chats.children.length == Social.providers.length,
michael@0 512 function() {
michael@0 513 ok(true, "one chat window per provider opened");
michael@0 514 // test logout of a single provider
michael@0 515 let provider = Social.providers[2];
michael@0 516 let port = provider.getWorkerPort();
michael@0 517 port.postMessage({topic: "test-logout"});
michael@0 518 waitForCondition(function() chats.children.length == Social.providers.length - 1,
michael@0 519 function() {
michael@0 520 chats.removeAll();
michael@0 521 waitForCondition(function() chats.children.length == 0,
michael@0 522 function() {
michael@0 523 ok(!chats.selectedChat, "multiprovider chats are all closed");
michael@0 524 port.close();
michael@0 525 next();
michael@0 526 },
michael@0 527 "chat windows didn't close");
michael@0 528 },
michael@0 529 "chat window didn't close");
michael@0 530 }, "chat windows did not open");
michael@0 531 });
michael@0 532 });
michael@0 533 });
michael@0 534 },
michael@0 535
michael@0 536 // XXX - note this must be the last test until we restore the login state
michael@0 537 // between tests...
michael@0 538 testCloseOnLogout: function(next) {
michael@0 539 const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
michael@0 540 let port = SocialSidebar.provider.getWorkerPort();
michael@0 541 ok(port, "provider has a port");
michael@0 542 let opened = false;
michael@0 543 port.onmessage = function (e) {
michael@0 544 let topic = e.data.topic;
michael@0 545 switch (topic) {
michael@0 546 case "test-init-done":
michael@0 547 info("open first chat window");
michael@0 548 port.postMessage({topic: "test-worker-chat", data: chatUrl});
michael@0 549 break;
michael@0 550 case "got-chatbox-message":
michael@0 551 ok(true, "got a chat window opened");
michael@0 552 if (opened) {
michael@0 553 port.postMessage({topic: "test-logout"});
michael@0 554 waitForCondition(function() document.getElementById("pinnedchats").firstChild == null,
michael@0 555 function() {
michael@0 556 port.close();
michael@0 557 next();
michael@0 558 },
michael@0 559 "chat windows didn't close");
michael@0 560 } else {
michael@0 561 // open a second chat window
michael@0 562 opened = true;
michael@0 563 port.postMessage({topic: "test-worker-chat", data: chatUrl+"?id=1"});
michael@0 564 }
michael@0 565 break;
michael@0 566 }
michael@0 567 }
michael@0 568 // make sure a user profile is set for this provider as chat windows are
michael@0 569 // only closed on *change* of the profile data rather than merely setting
michael@0 570 // profile data.
michael@0 571 port.postMessage({topic: "test-set-profile"});
michael@0 572 port.postMessage({topic: "test-init"});
michael@0 573 }
michael@0 574 }

mercurial