From 76a726f48e66329df9992826f368923ede606ba7 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Wed, 10 Dec 2014 14:53:43 -0800 Subject: [PATCH] Bug 1090633 fix intermittent failure, r=markh --- .../content/test/chat/browser_chatwindow.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/browser/base/content/test/chat/browser_chatwindow.js b/browser/base/content/test/chat/browser_chatwindow.js index 861b5b16e143..b0665050dc5f 100644 --- a/browser/base/content/test/chat/browser_chatwindow.js +++ b/browser/base/content/test/chat/browser_chatwindow.js @@ -6,6 +6,30 @@ Components.utils.import("resource://gre/modules/Promise.jsm", this); let chatbar = document.getElementById("pinnedchats"); +function waitForCondition(condition, errorMsg) { + let deferred = Promise.defer(); + var tries = 0; + var interval = setInterval(function() { + if (tries >= 30) { + ok(false, errorMsg); + moveOn(); + } + var conditionPassed; + try { + conditionPassed = condition(); + } catch (e) { + ok(false, e + "\n" + e.stack); + conditionPassed = false; + } + if (conditionPassed) { + moveOn(); + } + tries++; + }, 100); + var moveOn = function() { clearInterval(interval); deferred.resolve(); }; + return deferred.promise; +} + add_chat_task(function* testOpenCloseChat() { let chatbox = yield promiseOpenChat("http://example.com"); Assert.strictEqual(chatbox, chatbar.selectedChat); @@ -99,11 +123,15 @@ add_chat_task(function* testChatWindowChooser() { // therefore be the window that hosts the new chat (see bug 835111) let secondWindow = OpenBrowserWindow(); yield promiseOneEvent(secondWindow, "load"); + Assert.equal(secondWindow, Chat.findChromeWindowForChats(null), "Second window is the preferred chat window"); Assert.equal(numChatsInWindow(secondWindow), 0, "second window starts with no chats"); yield promiseOpenChat("http://example.com#2"); Assert.equal(numChatsInWindow(secondWindow), 1, "second window now has chats"); Assert.equal(numChatsInWindow(window), 1, "first window still has 1 chat"); chat.close(); + + // a bit heavy handed, but handy fixing bug 1090633 + yield waitForCondition(function () !chat.parentNode, "chat has been detached"); Assert.equal(numChatsInWindow(window), 0, "first window now has no chats"); // now open another chat - it should still open in the second. yield promiseOpenChat("http://example.com#3");