Bug 804591 - opening an existing chat window should restore it if minimized. r=jaws

This commit is contained in:
Mark Hammond 2012-11-14 15:27:34 +11:00
parent 50843d2e4c
commit ee50ee9e2d
2 changed files with 82 additions and 2 deletions

View File

@ -279,8 +279,9 @@
<method name="showChat">
<parameter name="aChatbox"/>
<parameter name="aMode"/>
<body><![CDATA[
if (aChatbox.minimized)
if ((aMode != "minimized") && aChatbox.minimized)
aChatbox.minimized = false;
if (this.selectedChat != aChatbox)
this.selectedChat = aChatbox;
@ -353,7 +354,7 @@
if (cb) {
cb = cb.get();
if (cb.parentNode) {
this.showChat(cb);
this.showChat(cb, aMode);
if (aCallback)
aCallback(cb.iframe.contentWindow);
return;

View File

@ -60,6 +60,85 @@ var tests = {
}
port.postMessage({topic: "test-init", data: { id: 1 }});
},
testOpenMinimized: function(next) {
// In this case the sidebar opens a chat (without specifying minimized).
// We then minimize it and have the sidebar reopen the chat (again without
// minimized). On that second call the chat should open and no longer
// be minimized.
let chats = document.getElementById("pinnedchats");
let port = Social.provider.getWorkerPort();
let seen_opened = false;
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "test-init-done":
port.postMessage({topic: "test-chatbox-open"});
break;
case "chatbox-opened":
is(e.data.result, "ok", "the sidebar says it got a chatbox");
if (!seen_opened) {
// first time we got the opened message, so minimize the chat then
// re-request the same chat to be opened - we should get the
// message again and the chat should be restored.
ok(!chats.selectedChat.minimized, "chat not initially minimized")
chats.selectedChat.minimized = true
seen_opened = true;
port.postMessage({topic: "test-chatbox-open"});
} else {
// This is the second time we've seen this message - there should
// be exactly 1 chat open and it should no longer be minimized.
let chats = document.getElementById("pinnedchats");
ok(!chats.selectedChat.minimized, "chat no longer minimized")
chats.selectedChat.close();
is(chats.selectedChat, null, "should only have been one chat open");
port.close();
next();
}
}
}
port.postMessage({topic: "test-init", data: { id: 1 }});
},
// In this case the *worker* opens a chat (so minimized is specified).
// The worker then makes the same call again - as that second call also
// specifies "minimized" the chat should *not* be restored.
testWorkerChatWindowMinimized: function(next) {
const chatUrl = "https://example.com/browser/browser/base/content/test/social_chat.html";
let port = Social.provider.getWorkerPort();
let seen_opened = false;
ok(port, "provider has a port");
port.postMessage({topic: "test-init"});
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-chatbox-message":
ok(true, "got a chat window opened");
let chats = document.getElementById("pinnedchats");
if (!seen_opened) {
// first time we got the opened message, so minimize the chat then
// re-request the same chat to be opened - we should get the
// message again and the chat should be restored.
ok(chats.selectedChat.minimized, "chatbox from worker opened as minimized");
seen_opened = true;
port.postMessage({topic: "test-worker-chat", data: chatUrl});
// Sadly there is no notification we can use to know the chat was
// re-opened :( So we ask the chat window to "ping" us - by then
// the second request should have made it.
chats.selectedChat.iframe.contentWindow.wrappedJSObject.pingWorker();
} else {
// This is the second time we've seen this message - there should
// be exactly 1 chat open and it should still be minimized.
let chats = document.getElementById("pinnedchats");
ok(chats.selectedChat.minimized, "chat still minimized")
chats.selectedChat.close();
is(chats.selectedChat, null, "should only have been one chat open");
port.close();
next();
}
break;
}
}
port.postMessage({topic: "test-worker-chat", data: chatUrl});
},
testManyChats: function(next) {
// open enough chats to overflow the window, then check
// if the menupopup is visible