зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1090633 - fix some focus related oranges with chats. r=mixedpuppy
From 27e7f9f198304d44a7a70b2f61518f1ff943651e Mon Sep 17 00:00:00 2001 --- .../base/content/test/chat/browser_chatwindow.js | 82 +++++++--------------- browser/base/content/test/chat/browser_focus.js | 8 ++- 2 files changed, 31 insertions(+), 59 deletions(-)
This commit is contained in:
Родитель
ea5e332f77
Коммит
76c354ce26
|
@ -6,30 +6,6 @@ Components.utils.import("resource://gre/modules/Promise.jsm", this);
|
||||||
|
|
||||||
let chatbar = document.getElementById("pinnedchats");
|
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() {
|
add_chat_task(function* testOpenCloseChat() {
|
||||||
let chatbox = yield promiseOpenChat("http://example.com");
|
let chatbox = yield promiseOpenChat("http://example.com");
|
||||||
Assert.strictEqual(chatbox, chatbar.selectedChat);
|
Assert.strictEqual(chatbox, chatbar.selectedChat);
|
||||||
|
@ -115,7 +91,7 @@ add_chat_task(function* testSecondTopLevelWindow() {
|
||||||
secondWindow.close();
|
secondWindow.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test that chats are created in the correct window.
|
// Test that findChromeWindowForChats() returns the expected window.
|
||||||
add_chat_task(function* testChatWindowChooser() {
|
add_chat_task(function* testChatWindowChooser() {
|
||||||
let chat = yield promiseOpenChat("http://example.com");
|
let chat = yield promiseOpenChat("http://example.com");
|
||||||
Assert.equal(numChatsInWindow(window), 1, "first window has the chat");
|
Assert.equal(numChatsInWindow(window), 1, "first window has the chat");
|
||||||
|
@ -124,42 +100,34 @@ add_chat_task(function* testChatWindowChooser() {
|
||||||
let secondWindow = OpenBrowserWindow();
|
let secondWindow = OpenBrowserWindow();
|
||||||
yield promiseOneEvent(secondWindow, "load");
|
yield promiseOneEvent(secondWindow, "load");
|
||||||
Assert.equal(secondWindow, Chat.findChromeWindowForChats(null), "Second window is the preferred chat window");
|
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
|
// focus the first window, and check it will be selected for future chats.
|
||||||
yield waitForCondition(function () !chat.parentNode, "chat has been detached");
|
// Bug 1090633 - there are lots of issues around focus, especially when the
|
||||||
Assert.equal(numChatsInWindow(window), 0, "first window now has no chats");
|
// browser itself doesn't have focus. We can end up with
|
||||||
// now open another chat - it should still open in the second.
|
// Services.wm.getMostRecentWindow("navigator:browser") returning a different
|
||||||
yield promiseOpenChat("http://example.com#3");
|
// window than, say, Services.focus.activeWindow. But the focus manager isn't
|
||||||
Assert.equal(numChatsInWindow(window), 0, "first window still has no chats");
|
// the point of this test.
|
||||||
Assert.equal(numChatsInWindow(secondWindow), 2, "second window has both chats");
|
// So we simply keep focusing the first window until it is reported as the
|
||||||
|
// most recent.
|
||||||
// focus the first window, and open yet another chat - it
|
do {
|
||||||
// should open in the first window.
|
dump("trying to force window to become the most recent.\n");
|
||||||
|
secondWindow.focus();
|
||||||
window.focus();
|
window.focus();
|
||||||
yield promiseWaitForFocus();
|
yield promiseWaitForFocus();
|
||||||
chat = yield promiseOpenChat("http://example.com#4");
|
} while (Services.wm.getMostRecentWindow("navigator:browser") != window)
|
||||||
Assert.equal(numChatsInWindow(window), 1, "first window got new chat");
|
|
||||||
chat.close();
|
Assert.equal(window, Chat.findChromeWindowForChats(null), "First window now the preferred chat window");
|
||||||
Assert.equal(numChatsInWindow(window), 0, "first window has no chats");
|
|
||||||
|
|
||||||
let privateWindow = OpenBrowserWindow({private: true});
|
let privateWindow = OpenBrowserWindow({private: true});
|
||||||
yield promiseOneEvent(privateWindow, "load")
|
yield promiseOneEvent(privateWindow, "load")
|
||||||
|
|
||||||
// open a last chat - the focused window can't accept
|
// The focused window can't accept chats (it's a private window), so the
|
||||||
// chats (it's a private window), so the chat should open
|
// chat should open in the window that was selected before. This will be
|
||||||
// in the window that was selected before. This is known
|
// either window or secondWindow (linux may choose a different one) but the
|
||||||
// to be broken on Linux.
|
// point is that the window is *not* the private one.
|
||||||
chat = yield promiseOpenChat("http://example.com#5");
|
Assert.ok(Chat.findChromeWindowForChats(null) == window ||
|
||||||
let os = Services.appinfo.OS;
|
Chat.findChromeWindowForChats(null) == secondWindow,
|
||||||
const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin";
|
"Private window isn't selected for new chats.");
|
||||||
let fn = BROKEN_WM_Z_ORDER ? todo : ok;
|
|
||||||
fn(numChatsInWindow(window) == 1, "first window got the chat");
|
|
||||||
chat.close();
|
|
||||||
privateWindow.close();
|
privateWindow.close();
|
||||||
secondWindow.close();
|
secondWindow.close();
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,12 +10,16 @@ const CHAT_URL = "https://example.com/browser/browser/base/content/test/chat/cha
|
||||||
// Is the currently opened tab focused?
|
// Is the currently opened tab focused?
|
||||||
function isTabFocused() {
|
function isTabFocused() {
|
||||||
let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
|
let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
|
||||||
return Services.focus.focusedWindow == tabb.contentWindow;
|
// focus sucks in tests - our window may have lost focus.
|
||||||
|
let elt = Services.focus.getFocusedElementForWindow(window, false, {});
|
||||||
|
return elt == tabb;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the specified chat focused?
|
// Is the specified chat focused?
|
||||||
function isChatFocused(chat) {
|
function isChatFocused(chat) {
|
||||||
return chat.chatbar._isChatFocused(chat);
|
// focus sucks in tests - our window may have lost focus.
|
||||||
|
let elt = Services.focus.getFocusedElementForWindow(window, false, {});
|
||||||
|
return elt == chat.content;
|
||||||
}
|
}
|
||||||
|
|
||||||
let chatbar = document.getElementById("pinnedchats");
|
let chatbar = document.getElementById("pinnedchats");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче