mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1002914 (part 2) - remove SocialChatBar, add chat specific tests and refactor social tests. r=mixedpuppy
This commit is contained in:
parent
80da9e20fd
commit
eef4227d00
@ -4,7 +4,6 @@
|
||||
|
||||
// the "exported" symbols
|
||||
let SocialUI,
|
||||
SocialChatBar,
|
||||
SocialFlyout,
|
||||
SocialMarks,
|
||||
SocialShare,
|
||||
@ -296,19 +295,6 @@ SocialUI = {
|
||||
}
|
||||
}
|
||||
|
||||
SocialChatBar = {
|
||||
get chatbar() {
|
||||
return document.getElementById("pinnedchats");
|
||||
},
|
||||
openChat: function(aProvider, aURL, aCallback, aMode) {
|
||||
// Until we refactor the tests we can't remove this.
|
||||
// Reach into the social API.
|
||||
let openChatWindow = Cu.import("resource://gre/modules/MozSocialAPI.jsm", {}).openChatWindow;
|
||||
openChatWindow(window, aProvider, aURL, aCallback, aMode);
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
SocialFlyout = {
|
||||
get panel() {
|
||||
return document.getElementById("social-flyout-panel");
|
||||
|
@ -515,22 +515,6 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- XXX - we should remove this - it is currently used only by tests.
|
||||
No-one has any business removing all chats. Chat.jsm exposes a
|
||||
method to close all chats from a specific origin which is all that
|
||||
should be necessary.
|
||||
-->
|
||||
<method name="removeAll">
|
||||
<body><![CDATA[
|
||||
this.selectedChat = null;
|
||||
while (this.firstElementChild) {
|
||||
this._remove(this.firstElementChild);
|
||||
}
|
||||
// and the nub/popup must also die.
|
||||
this.nub.collapsed = true;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="openChat">
|
||||
<parameter name="aOrigin"/>
|
||||
<parameter name="aTitle"/>
|
||||
|
8
browser/base/content/test/chat/browser.ini
Normal file
8
browser/base/content/test/chat/browser.ini
Normal file
@ -0,0 +1,8 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
head.js
|
||||
chat.html
|
||||
|
||||
[browser_chatwindow.js]
|
||||
[browser_focus.js]
|
||||
[browser_tearoff.js]
|
135
browser/base/content/test/chat/browser_chatwindow.js
Normal file
135
browser/base/content/test/chat/browser_chatwindow.js
Normal file
@ -0,0 +1,135 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
let chatbar = document.getElementById("pinnedchats");
|
||||
|
||||
add_chat_task(function* testOpenCloseChat() {
|
||||
let chatbox = yield promiseOpenChat("http://example.com");
|
||||
Assert.strictEqual(chatbox, chatbar.selectedChat);
|
||||
// we requested a "normal" chat, so shouldn't be minimized
|
||||
Assert.ok(!chatbox.minimized, "chat is not minimized");
|
||||
Assert.equal(chatbar.childNodes.length, 1, "should be 1 chat open");
|
||||
|
||||
|
||||
// now request the same URL again - we should get the same chat.
|
||||
let chatbox2 = yield promiseOpenChat("http://example.com");
|
||||
Assert.strictEqual(chatbox2, chatbox, "got the same chat");
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
|
||||
chatbox.toggle();
|
||||
is(chatbox.minimized, true, "chat is now minimized");
|
||||
// was no other chat to select, so selected becomes null.
|
||||
is(chatbar.selectedChat, null);
|
||||
|
||||
// We check the content gets an unload event as we close it.
|
||||
let promiseClosed = promiseOneEvent(chatbox.content, "unload", true);
|
||||
chatbox.close();
|
||||
yield promiseClosed;
|
||||
});
|
||||
|
||||
// In this case we open a chat minimized, then request the same chat again
|
||||
// without specifying minimized. On that second call the chat should open,
|
||||
// selected, and no longer minimized.
|
||||
add_chat_task(function* testMinimized() {
|
||||
let chatbox = yield promiseOpenChat("http://example.com", "minimized");
|
||||
Assert.strictEqual(chatbox, chatbar.selectedChat);
|
||||
Assert.ok(chatbox.minimized, "chat is minimized");
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
yield promiseOpenChat("http://example.com");
|
||||
Assert.ok(!chatbox.minimized, false, "chat is no longer minimized");
|
||||
});
|
||||
|
||||
// open enough chats to overflow the window, then check
|
||||
// if the menupopup is visible
|
||||
add_chat_task(function* testManyChats() {
|
||||
Assert.ok(chatbar.menupopup.parentNode.collapsed, "popup nub collapsed at start");
|
||||
// we should *never* find a test box that needs more than this to cause
|
||||
// an overflow!
|
||||
let maxToOpen = 20;
|
||||
let numOpened = 0;
|
||||
for (let i = 0; i < maxToOpen; i++) {
|
||||
yield promiseOpenChat("http://example.com#" + i);
|
||||
if (!chatbar.menupopup.parentNode.collapsed) {
|
||||
info("the menu popup appeared");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Assert.ok(false, "We didn't find a collapsed chat after " + maxToOpen + "chats!");
|
||||
});
|
||||
|
||||
// Check that closeAll works as expected.
|
||||
add_chat_task(function* testOpenTwiceCallbacks() {
|
||||
yield promiseOpenChat("http://example.com#1");
|
||||
yield promiseOpenChat("http://example.com#2");
|
||||
yield promiseOpenChat("http://test2.example.com");
|
||||
Assert.equal(numChatsInWindow(window), 3, "should be 3 chats open");
|
||||
Chat.closeAll("http://example.com");
|
||||
Assert.equal(numChatsInWindow(window), 1, "should have closed 2 chats");
|
||||
Chat.closeAll("http://test2.example.com");
|
||||
Assert.equal(numChatsInWindow(window), 0, "should have closed last chat");
|
||||
});
|
||||
|
||||
// Check that when we open the same chat twice, the callbacks are called back
|
||||
// twice.
|
||||
add_chat_task(function* testOpenTwiceCallbacks() {
|
||||
yield promiseOpenChatCallback("http://example.com");
|
||||
yield promiseOpenChatCallback("http://example.com");
|
||||
});
|
||||
|
||||
// Bug 817782 - check chats work in new top-level windows.
|
||||
add_chat_task(function* testSecondTopLevelWindow() {
|
||||
const chatUrl = "http://example.com";
|
||||
let secondWindow = OpenBrowserWindow();
|
||||
yield promiseOneEvent(secondWindow, "load");
|
||||
yield promiseOpenChat(chatUrl);
|
||||
// the chat was created - let's make sure it was created in the second window.
|
||||
Assert.equal(numChatsInWindow(window), 0, "main window has no chats");
|
||||
Assert.equal(numChatsInWindow(secondWindow), 1, "second window has 1 chat");
|
||||
secondWindow.close();
|
||||
});
|
||||
|
||||
// Test that chats are created in the correct window.
|
||||
add_chat_task(function* testChatWindowChooser() {
|
||||
let chat = yield promiseOpenChat("http://example.com");
|
||||
Assert.equal(numChatsInWindow(window), 1, "first window has the chat");
|
||||
// create a second window - this will be the "most recent" and will
|
||||
// therefore be the window that hosts the new chat (see bug 835111)
|
||||
let secondWindow = OpenBrowserWindow();
|
||||
yield promiseOneEvent(secondWindow, "load");
|
||||
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();
|
||||
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");
|
||||
Assert.equal(numChatsInWindow(window), 0, "first window still has no chats");
|
||||
Assert.equal(numChatsInWindow(secondWindow), 2, "second window has both chats");
|
||||
|
||||
// focus the first window, and open yet another chat - it
|
||||
// should open in the first window.
|
||||
window.focus();
|
||||
yield promiseWaitForFocus();
|
||||
chat = yield promiseOpenChat("http://example.com#4");
|
||||
Assert.equal(numChatsInWindow(window), 1, "first window got new chat");
|
||||
chat.close();
|
||||
Assert.equal(numChatsInWindow(window), 0, "first window has no chats");
|
||||
|
||||
let privateWindow = OpenBrowserWindow({private: true});
|
||||
yield promiseOneEvent(privateWindow, "load")
|
||||
|
||||
// open a last chat - the focused window can't accept
|
||||
// chats (it's a private window), so the chat should open
|
||||
// in the window that was selected before. This is known
|
||||
// to be broken on Linux.
|
||||
chat = yield promiseOpenChat("http://example.com#5");
|
||||
let os = Services.appinfo.OS;
|
||||
const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin";
|
||||
let fn = BROKEN_WM_Z_ORDER ? todo : ok;
|
||||
fn(numChatsInWindow(window) == 1, "first window got the chat");
|
||||
chat.close();
|
||||
privateWindow.close();
|
||||
secondWindow.close();
|
||||
});
|
226
browser/base/content/test/chat/browser_focus.js
Normal file
226
browser/base/content/test/chat/browser_focus.js
Normal file
@ -0,0 +1,226 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Tests the focus functionality.
|
||||
|
||||
const CHAT_URL = "https://example.com/browser/browser/base/content/test/chat/chat.html";
|
||||
|
||||
// Is the currently opened tab focused?
|
||||
function isTabFocused() {
|
||||
let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
|
||||
return Services.focus.focusedWindow == tabb.contentWindow;
|
||||
}
|
||||
|
||||
// Is the specified chat focused?
|
||||
function isChatFocused(chat) {
|
||||
return chat.chatbar._isChatFocused(chat);
|
||||
}
|
||||
|
||||
let chatbar = document.getElementById("pinnedchats");
|
||||
|
||||
function* setUp() {
|
||||
// Note that (probably) due to bug 604289, if a tab is focused but the
|
||||
// focused element is null, our chat windows can "steal" focus. This is
|
||||
// avoided if we explicitly focus an element in the tab.
|
||||
// So we load a page with an <input> field and focus that before testing.
|
||||
let html = '<input id="theinput"><button id="chat-opener"></button>';
|
||||
let url = "data:text/html;charset=utf-8," + encodeURI(html);
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true});
|
||||
yield promiseOneEvent(tab.linkedBrowser, "load", true);
|
||||
tab.linkedBrowser.contentDocument.getElementById("theinput").focus();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
}
|
||||
|
||||
// Test default focus - not user input.
|
||||
add_chat_task(function* testDefaultFocus() {
|
||||
yield setUp();
|
||||
let chat = yield promiseOpenChat("http://example.com");
|
||||
// we used the default focus behaviour, which means that because this was
|
||||
// not the direct result of user action the chat should not be focused.
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
Assert.ok(isTabFocused(), "the tab should remain focused.");
|
||||
Assert.ok(!isChatFocused(chat), "the chat should not be focused.");
|
||||
});
|
||||
|
||||
// Test default focus via user input.
|
||||
add_chat_task(function* testDefaultFocus() {
|
||||
yield setUp();
|
||||
let tab = gBrowser.selectedTab;
|
||||
let deferred = Promise.defer();
|
||||
let button = tab.linkedBrowser.contentDocument.getElementById("chat-opener");
|
||||
button.addEventListener("click", function onclick() {
|
||||
button.removeEventListener("click", onclick);
|
||||
promiseOpenChat("http://example.com").then(
|
||||
chat => deferred.resolve(chat)
|
||||
);
|
||||
})
|
||||
// Note we must use synthesizeMouseAtCenter() rather than calling
|
||||
// .click() directly as this causes nsIDOMWindowUtils.isHandlingUserInput
|
||||
// to be true.
|
||||
EventUtils.synthesizeMouseAtCenter(button, {}, button.ownerDocument.defaultView);
|
||||
let chat = yield deferred.promise;
|
||||
|
||||
// we use the default focus behaviour but the chat was opened via user input,
|
||||
// so the chat should be focused.
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
Assert.ok(!isTabFocused(), "the tab should have lost focus.");
|
||||
Assert.ok(isChatFocused(chat), "the chat should have got focus.");
|
||||
});
|
||||
|
||||
// We explicitly ask for the chat to be focused.
|
||||
add_chat_task(function* testExplicitFocus() {
|
||||
yield setUp();
|
||||
let chat = yield promiseOpenChat("http://example.com", undefined, true);
|
||||
// we use the default focus behaviour, which means that because this was
|
||||
// not the direct result of user action the chat should not be focused.
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
Assert.ok(!isTabFocused(), "the tab should have lost focus.");
|
||||
Assert.ok(isChatFocused(chat), "the chat should have got focus.");
|
||||
});
|
||||
|
||||
// Open a minimized chat via default focus behaviour - it will open and not
|
||||
// have focus. Then open the same chat without 'minimized' - it will be
|
||||
// restored but should still not have grabbed focus.
|
||||
add_chat_task(function* testNoFocusOnAutoRestore() {
|
||||
yield setUp();
|
||||
let chat = yield promiseOpenChat("http://example.com", "minimized");
|
||||
Assert.ok(chat.minimized, "chat is minimized");
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
Assert.ok(isTabFocused(), "the tab should remain focused.");
|
||||
Assert.ok(!isChatFocused(chat), "the chat should not be focused.");
|
||||
yield promiseOpenChat("http://example.com");
|
||||
Assert.ok(!chat.minimized, "chat should be restored");
|
||||
Assert.ok(isTabFocused(), "the tab should remain focused.");
|
||||
Assert.ok(!isChatFocused(chat), "the chat should not be focused.");
|
||||
});
|
||||
|
||||
// Here we open a chat, which will not be focused. Then we minimize it and
|
||||
// restore it via a titlebar clock - it should get focus at that point.
|
||||
add_chat_task(function* testFocusOnExplicitRestore() {
|
||||
yield setUp();
|
||||
let chat = yield promiseOpenChat("http://example.com");
|
||||
Assert.ok(!chat.minimized, "chat should have been opened restored");
|
||||
Assert.ok(isTabFocused(), "the tab should remain focused.");
|
||||
Assert.ok(!isChatFocused(chat), "the chat should not be focused.");
|
||||
chat.minimized = true;
|
||||
Assert.ok(isTabFocused(), "tab should still be focused");
|
||||
Assert.ok(!isChatFocused(chat), "the chat should not be focused.");
|
||||
|
||||
let promise = promiseOneEvent(chat.contentWindow, "focus");
|
||||
// pretend we clicked on the titlebar
|
||||
chat.onTitlebarClick({button: 0});
|
||||
yield promise; // wait for focus event.
|
||||
Assert.ok(!chat.minimized, "chat should have been restored");
|
||||
Assert.ok(isChatFocused(chat), "chat should be focused");
|
||||
Assert.strictEqual(chat, chatbar.selectedChat, "chat is marked selected");
|
||||
});
|
||||
|
||||
// Open 2 chats and give 1 focus. Minimize the focused one - the second
|
||||
// should get focus.
|
||||
add_chat_task(function* testMinimizeFocused() {
|
||||
yield setUp();
|
||||
let chat1 = yield promiseOpenChat("http://example.com#1");
|
||||
let chat2 = yield promiseOpenChat("http://example.com#2");
|
||||
Assert.equal(numChatsInWindow(window), 2, "2 chats open");
|
||||
Assert.strictEqual(chatbar.selectedChat, chat2, "chat2 is selected");
|
||||
let promise = promiseOneEvent(chat1.contentWindow, "focus");
|
||||
chatbar.selectedChat = chat1;
|
||||
chatbar.focus();
|
||||
yield promise; // wait for chat1 to get focus.
|
||||
Assert.strictEqual(chat1, chatbar.selectedChat, "chat1 is marked selected");
|
||||
Assert.notStrictEqual(chat2, chatbar.selectedChat, "chat2 is not marked selected");
|
||||
promise = promiseOneEvent(chat2.contentWindow, "focus");
|
||||
chat1.minimized = true;
|
||||
yield promise; // wait for chat2 to get focus.
|
||||
Assert.notStrictEqual(chat1, chatbar.selectedChat, "chat1 is not marked selected");
|
||||
Assert.strictEqual(chat2, chatbar.selectedChat, "chat2 is marked selected");
|
||||
});
|
||||
|
||||
// Open 2 chats, select and focus the second. Pressing the TAB key should
|
||||
// cause focus to move between all elements in our chat window before moving
|
||||
// to the next chat window.
|
||||
add_chat_task(function* testTab() {
|
||||
yield setUp();
|
||||
|
||||
function sendTabAndWaitForFocus(chat, eltid) {
|
||||
let doc = chat.contentDocument;
|
||||
EventUtils.sendKey("tab");
|
||||
// ideally we would use the 'focus' event here, but that doesn't work
|
||||
// as expected for the iframe - the iframe itself never gets the focus
|
||||
// event (apparently the sub-document etc does.)
|
||||
// So just poll for the correct element getting focus...
|
||||
let deferred = Promise.defer();
|
||||
let tries = 0;
|
||||
let interval = setInterval(function() {
|
||||
if (tries >= 30) {
|
||||
clearInterval(interval);
|
||||
deferred.reject("never got focus");
|
||||
return;
|
||||
}
|
||||
tries ++;
|
||||
let elt = eltid ? doc.getElementById(eltid) : doc.documentElement;
|
||||
if (doc.activeElement == elt) {
|
||||
clearInterval(interval);
|
||||
deferred.resolve();
|
||||
}
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
let chat1 = yield promiseOpenChat(CHAT_URL + "#1");
|
||||
let chat2 = yield promiseOpenChat(CHAT_URL + "#2");
|
||||
chatbar.selectedChat = chat2;
|
||||
let promise = promiseOneEvent(chat2.contentWindow, "focus");
|
||||
chatbar.focus();
|
||||
yield promise;
|
||||
|
||||
// Our chats have 3 focusable elements, so it takes 4 TABs to move
|
||||
// to the new chat.
|
||||
yield sendTabAndWaitForFocus(chat2, "input1");
|
||||
Assert.equal(chat2.contentDocument.activeElement.getAttribute("id"), "input1",
|
||||
"first input field has focus");
|
||||
Assert.ok(isChatFocused(chat2), "new chat still focused after first tab");
|
||||
|
||||
yield sendTabAndWaitForFocus(chat2, "input2");
|
||||
Assert.ok(isChatFocused(chat2), "new chat still focused after tab");
|
||||
Assert.equal(chat2.contentDocument.activeElement.getAttribute("id"), "input2",
|
||||
"second input field has focus");
|
||||
|
||||
yield sendTabAndWaitForFocus(chat2, "iframe");
|
||||
Assert.ok(isChatFocused(chat2), "new chat still focused after tab");
|
||||
Assert.equal(chat2.contentDocument.activeElement.getAttribute("id"), "iframe",
|
||||
"iframe has focus");
|
||||
|
||||
// this tab now should move to the next chat, but focus the
|
||||
// document element itself (hence the null eltid)
|
||||
yield sendTabAndWaitForFocus(chat1, null);
|
||||
Assert.ok(isChatFocused(chat1), "first chat is focused");
|
||||
});
|
||||
|
||||
// Open a chat and focus an element other than the first. Move focus to some
|
||||
// other item (the tab itself in this case), then focus the chatbar - the
|
||||
// same element that was previously focused should still have focus.
|
||||
add_chat_task(function* testFocusedElement() {
|
||||
yield setUp();
|
||||
|
||||
// open a chat with focus requested.
|
||||
let chat = yield promiseOpenChat(CHAT_URL, undefined, true);
|
||||
|
||||
chat.contentDocument.getElementById("input2").focus();
|
||||
|
||||
// set focus to the tab.
|
||||
let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
|
||||
let promise = promiseOneEvent(tabb.contentWindow, "focus");
|
||||
Services.focus.moveFocus(tabb.contentWindow, null, Services.focus.MOVEFOCUS_ROOT, 0);
|
||||
yield promise;
|
||||
|
||||
promise = promiseOneEvent(chat.contentWindow, "focus");
|
||||
chatbar.focus();
|
||||
yield promise;
|
||||
|
||||
Assert.equal(chat.contentDocument.activeElement.getAttribute("id"), "input2",
|
||||
"correct input field still has focus");
|
||||
});
|
128
browser/base/content/test/chat/browser_tearoff.js
Normal file
128
browser/base/content/test/chat/browser_tearoff.js
Normal file
@ -0,0 +1,128 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
let chatbar = document.getElementById("pinnedchats");
|
||||
|
||||
function promiseNewWindowLoaded() {
|
||||
let deferred = Promise.defer();
|
||||
Services.wm.addListener({
|
||||
onWindowTitleChange: function() {},
|
||||
onCloseWindow: function(xulwindow) {},
|
||||
onOpenWindow: function(xulwindow) {
|
||||
var domwindow = xulwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
||||
Services.wm.removeListener(this);
|
||||
// wait for load to ensure the window is ready for us to test
|
||||
domwindow.addEventListener("load", function _load(event) {
|
||||
let doc = domwindow.document;
|
||||
if (event.target != doc)
|
||||
return;
|
||||
domwindow.removeEventListener("load", _load);
|
||||
deferred.resolve(domwindow);
|
||||
});
|
||||
},
|
||||
});
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
add_chat_task(function* testTearoffChat() {
|
||||
let chatbox = yield promiseOpenChat("http://example.com");
|
||||
Assert.equal(numChatsInWindow(window), 1, "should be 1 chat open");
|
||||
|
||||
let chatDoc = chatbox.contentDocument;
|
||||
let chatTitle = chatDoc.title;
|
||||
|
||||
Assert.equal(chatbox.getAttribute("label"), chatTitle,
|
||||
"the new chatbox should show the title of the chat window");
|
||||
|
||||
// mutate the chat document a bit before we tear it off.
|
||||
let div = chatDoc.createElement("div");
|
||||
div.setAttribute("id", "testdiv");
|
||||
div.setAttribute("test", "1");
|
||||
chatDoc.body.appendChild(div);
|
||||
|
||||
// chatbox is open, lets detach. The new chat window will be caught in
|
||||
// the window watcher below
|
||||
let promise = promiseNewWindowLoaded();
|
||||
|
||||
let swap = document.getAnonymousElementByAttribute(chatbox, "anonid", "swap");
|
||||
swap.click();
|
||||
|
||||
// and wait for the new window.
|
||||
let domwindow = yield promise;
|
||||
|
||||
Assert.equal(domwindow.document.documentElement.getAttribute("windowtype"), "Social:Chat", "Social:Chat window opened");
|
||||
Assert.equal(numChatsInWindow(window), 0, "should be no chats in the chat bar");
|
||||
|
||||
// get the chatbox from the new window.
|
||||
chatbox = domwindow.document.getElementById("chatter")
|
||||
Assert.equal(chatbox.getAttribute("label"), chatTitle, "window should have same title as chat");
|
||||
|
||||
div = chatbox.contentDocument.getElementById("testdiv");
|
||||
Assert.equal(div.getAttribute("test"), "1", "docshell should have been swapped");
|
||||
div.setAttribute("test", "2");
|
||||
|
||||
// swap the window back to the chatbar
|
||||
promise = promiseOneEvent(domwindow, "unload");
|
||||
swap = domwindow.document.getAnonymousElementByAttribute(chatbox, "anonid", "swap");
|
||||
swap.click();
|
||||
|
||||
yield promise;
|
||||
|
||||
Assert.equal(numChatsInWindow(window), 1, "chat should be docked back in the window");
|
||||
chatbox = chatbar.selectedChat;
|
||||
Assert.equal(chatbox.getAttribute("label"), chatTitle,
|
||||
"the new chatbox should show the title of the chat window again");
|
||||
|
||||
div = chatbox.contentDocument.getElementById("testdiv");
|
||||
Assert.equal(div.getAttribute("test"), "2", "docshell should have been swapped");
|
||||
});
|
||||
|
||||
// Similar test but with 2 chats.
|
||||
add_chat_task(function* testReattachTwice() {
|
||||
let chatbox1 = yield promiseOpenChat("http://example.com#1");
|
||||
let chatbox2 = yield promiseOpenChat("http://example.com#2");
|
||||
Assert.equal(numChatsInWindow(window), 2, "both chats should be docked in the window");
|
||||
|
||||
info("chatboxes are open, detach from window");
|
||||
let promise = promiseNewWindowLoaded();
|
||||
document.getAnonymousElementByAttribute(chatbox1, "anonid", "swap").click();
|
||||
let domwindow1 = yield promise;
|
||||
chatbox1 = domwindow1.document.getElementById("chatter");
|
||||
Assert.equal(numChatsInWindow(window), 1, "only second chat should be docked in the window");
|
||||
|
||||
promise = promiseNewWindowLoaded();
|
||||
document.getAnonymousElementByAttribute(chatbox2, "anonid", "swap").click();
|
||||
let domwindow2 = yield promise;
|
||||
chatbox2 = domwindow2.document.getElementById("chatter");
|
||||
Assert.equal(numChatsInWindow(window), 0, "should be no docked chats");
|
||||
|
||||
promise = promiseOneEvent(domwindow2, "unload");
|
||||
domwindow2.document.getAnonymousElementByAttribute(chatbox2, "anonid", "swap").click();
|
||||
yield promise;
|
||||
Assert.equal(numChatsInWindow(window), 1, "one chat should be docked back in the window");
|
||||
|
||||
promise = promiseOneEvent(domwindow1, "unload");
|
||||
domwindow1.document.getAnonymousElementByAttribute(chatbox1, "anonid", "swap").click();
|
||||
yield promise;
|
||||
Assert.equal(numChatsInWindow(window), 2, "both chats should be docked back in the window");
|
||||
});
|
||||
|
||||
// Check that Chat.closeAll() also closes detached windows.
|
||||
add_chat_task(function* testCloseAll() {
|
||||
let chatbox1 = yield promiseOpenChat("http://example.com#1");
|
||||
let chatbox2 = yield promiseOpenChat("http://example.com#2");
|
||||
|
||||
let promise = promiseNewWindowLoaded();
|
||||
document.getAnonymousElementByAttribute(chatbox1, "anonid", "swap").click();
|
||||
let domwindow = yield promise;
|
||||
chatbox1 = domwindow.document.getElementById("chatter");
|
||||
|
||||
let promiseWindowUnload = promiseOneEvent(domwindow, "unload");
|
||||
|
||||
Assert.equal(numChatsInWindow(window), 1, "second chat should still be docked");
|
||||
Chat.closeAll("http://example.com");
|
||||
yield promiseWindowUnload;
|
||||
Assert.equal(numChatsInWindow(window), 0, "should be no chats left");
|
||||
});
|
14
browser/base/content/test/chat/chat.html
Normal file
14
browser/base/content/test/chat/chat.html
Normal file
@ -0,0 +1,14 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>test chat window</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>This is a test chat window.</p>
|
||||
<!-- a couple of input fields to help with focus testing -->
|
||||
<input id="input1"/>
|
||||
<input id="input2"/>
|
||||
<!-- an iframe here so this one page generates multiple load events -->
|
||||
<iframe id="iframe" src="data:text/plain:this is an iframe"></iframe>
|
||||
</body>
|
||||
</html>
|
74
browser/base/content/test/chat/head.js
Normal file
74
browser/base/content/test/chat/head.js
Normal file
@ -0,0 +1,74 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// Utility functions for Chat tests.
|
||||
|
||||
let Chat = Cu.import("resource:///modules/Chat.jsm", {}).Chat;
|
||||
|
||||
function promiseOpenChat(url, mode, focus) {
|
||||
let uri = Services.io.newURI(url, null, null);
|
||||
let origin = uri.prePath;
|
||||
let title = origin;
|
||||
let chatbox = Chat.open(null, origin, title, url, mode, focus);
|
||||
return chatbox.promiseChatLoaded;
|
||||
}
|
||||
|
||||
// Opens a chat, returns a promise resolved when the chat callback fired.
|
||||
function promiseOpenChatCallback(url, mode) {
|
||||
let uri = Services.io.newURI(url, null, null);
|
||||
let origin = uri.prePath;
|
||||
let title = origin;
|
||||
let deferred = Promise.defer();
|
||||
let callback = deferred.resolve;
|
||||
Chat.open(null, origin, title, url, mode, undefined, callback);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Opens a chat, returns the chat window's promise which fires when the chat
|
||||
// starts loading.
|
||||
function promiseOneEvent(target, eventName, capture) {
|
||||
let deferred = Promise.defer();
|
||||
target.addEventListener(eventName, function handler(event) {
|
||||
target.removeEventListener(eventName, handler, capture);
|
||||
deferred.resolve();
|
||||
}, capture);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Return the number of chats in a browser window.
|
||||
function numChatsInWindow(win) {
|
||||
let chatbar = win.document.getElementById("pinnedchats");
|
||||
return chatbar.childElementCount;
|
||||
}
|
||||
|
||||
function promiseWaitForFocus() {
|
||||
let deferred = Promise.defer();
|
||||
waitForFocus(deferred.resolve);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// A simple way to clean up after each test.
|
||||
function add_chat_task(genFunction) {
|
||||
add_task(function* () {
|
||||
info("Starting chat test " + genFunction.name);
|
||||
try {
|
||||
yield genFunction();
|
||||
} finally {
|
||||
info("Finished chat test " + genFunction.name + " - cleaning up.");
|
||||
// close all docked chats.
|
||||
while (chatbar.childNodes.length) {
|
||||
chatbar.childNodes[0].close();
|
||||
}
|
||||
// and non-docked chats.
|
||||
let winEnum = Services.wm.getEnumerator("Social:Chat");
|
||||
while (winEnum.hasMoreElements()) {
|
||||
let win = winEnum.getNext();
|
||||
if (win.closed) {
|
||||
continue;
|
||||
}
|
||||
win.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
@ -26,7 +26,6 @@ support-files =
|
||||
|
||||
[browser_addons.js]
|
||||
[browser_blocklist.js]
|
||||
[browser_chat_tearoff.js]
|
||||
[browser_defaults.js]
|
||||
[browser_share.js]
|
||||
[browser_social_activation.js]
|
||||
|
@ -1,308 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function test() {
|
||||
requestLongerTimeout(2); // only debug builds seem to need more time...
|
||||
waitForExplicitFinish();
|
||||
|
||||
let manifest = { // normal provider
|
||||
name: "provider 1",
|
||||
origin: "https://example.com",
|
||||
sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
|
||||
workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
|
||||
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
|
||||
};
|
||||
|
||||
let postSubTest = function(cb) {
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
ok(chats.children.length == 0, "no chatty children left behind");
|
||||
cb();
|
||||
};
|
||||
runSocialTestWithProvider(manifest, function (finishcb) {
|
||||
SocialSidebar.show();
|
||||
ok(SocialSidebar.provider, "sidebar provider exists");
|
||||
runSocialTests(tests, undefined, postSubTest, function() {
|
||||
finishcb();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var tests = {
|
||||
testTearoffChat: function(next) {
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
let chatTitle;
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
ok(port, "provider has a port");
|
||||
port.onmessage = function (e) {
|
||||
let topic = e.data.topic;
|
||||
switch (topic) {
|
||||
case "got-sidebar-message":
|
||||
port.postMessage({topic: "test-chatbox-open"});
|
||||
break;
|
||||
case "got-chatbox-visibility":
|
||||
// chatbox is open, lets detach. The new chat window will be caught in
|
||||
// the window watcher below
|
||||
let doc = chats.selectedChat.contentDocument;
|
||||
// This message is (sometimes!) received a second time
|
||||
// before we start our tests from the onCloseWindow
|
||||
// callback.
|
||||
if (doc.location == "about:blank")
|
||||
return;
|
||||
chatTitle = doc.title;
|
||||
ok(chats.selectedChat.getAttribute("label") == chatTitle,
|
||||
"the new chatbox should show the title of the chat window");
|
||||
let div = doc.createElement("div");
|
||||
div.setAttribute("id", "testdiv");
|
||||
div.setAttribute("test", "1");
|
||||
doc.body.appendChild(div);
|
||||
let swap = document.getAnonymousElementByAttribute(chats.selectedChat, "anonid", "swap");
|
||||
swap.click();
|
||||
port.close();
|
||||
break;
|
||||
case "got-chatbox-message":
|
||||
ok(true, "got chatbox message");
|
||||
ok(e.data.result == "ok", "got chatbox windowRef result: "+e.data.result);
|
||||
chats.selectedChat.toggle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Services.wm.addListener({
|
||||
onWindowTitleChange: function() {},
|
||||
onCloseWindow: function(xulwindow) {},
|
||||
onOpenWindow: function(xulwindow) {
|
||||
var domwindow = xulwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
||||
Services.wm.removeListener(this);
|
||||
// wait for load to ensure the window is ready for us to test
|
||||
domwindow.addEventListener("load", function _load(event) {
|
||||
let doc = domwindow.document;
|
||||
if (event.target != doc)
|
||||
return;
|
||||
|
||||
domwindow.removeEventListener("load", _load, false);
|
||||
|
||||
domwindow.addEventListener("unload", function _close(event) {
|
||||
if (event.target != doc)
|
||||
return;
|
||||
domwindow.removeEventListener("unload", _close, false);
|
||||
info("window has been closed");
|
||||
waitForCondition(function() {
|
||||
return chats.selectedChat && chats.selectedChat.contentDocument &&
|
||||
chats.selectedChat.contentDocument.readyState == "complete";
|
||||
},function () {
|
||||
ok(chats.selectedChat, "should have a chatbox in our window again");
|
||||
ok(chats.selectedChat.getAttribute("label") == chatTitle,
|
||||
"the new chatbox should show the title of the chat window again");
|
||||
let testdiv = chats.selectedChat.contentDocument.getElementById("testdiv");
|
||||
is(testdiv.getAttribute("test"), "2", "docshell should have been swapped");
|
||||
chats.selectedChat.close();
|
||||
waitForCondition(function() {
|
||||
return chats.children.length == 0;
|
||||
},function () {
|
||||
next();
|
||||
});
|
||||
});
|
||||
}, false);
|
||||
|
||||
is(doc.documentElement.getAttribute("windowtype"), "Social:Chat", "Social:Chat window opened");
|
||||
// window is loaded, but the docswap does not happen until after load,
|
||||
// and we have no event to wait on, so we'll wait for document state
|
||||
// to be ready
|
||||
let chatbox = doc.getElementById("chatter");
|
||||
waitForCondition(function() {
|
||||
return chats.selectedChat == null &&
|
||||
chatbox.contentDocument &&
|
||||
chatbox.contentDocument.readyState == "complete";
|
||||
},function() {
|
||||
ok(chatbox.getAttribute("label") == chatTitle,
|
||||
"detached window should show the title of the chat window");
|
||||
let testdiv = chatbox.contentDocument.getElementById("testdiv");
|
||||
is(testdiv.getAttribute("test"), "1", "docshell should have been swapped");
|
||||
testdiv.setAttribute("test", "2");
|
||||
// swap the window back to the chatbar
|
||||
let swap = doc.getAnonymousElementByAttribute(chatbox, "anonid", "swap");
|
||||
swap.click();
|
||||
}, domwindow);
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
port.postMessage({topic: "test-init", data: { id: 1 }});
|
||||
},
|
||||
|
||||
testCloseOnLogout: function(next) {
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
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-visibility":
|
||||
// chatbox is open, lets detach. The new chat window will be caught in
|
||||
// the window watcher below
|
||||
let doc = chats.selectedChat.contentDocument;
|
||||
// This message is (sometimes!) received a second time
|
||||
// before we start our tests from the onCloseWindow
|
||||
// callback.
|
||||
if (doc.location == "about:blank")
|
||||
return;
|
||||
info("chatbox is open, detach from window");
|
||||
let swap = document.getAnonymousElementByAttribute(chats.selectedChat, "anonid", "swap");
|
||||
swap.click();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Services.wm.addListener({
|
||||
onWindowTitleChange: function() {},
|
||||
onCloseWindow: function(xulwindow) {},
|
||||
onOpenWindow: function(xulwindow) {
|
||||
let domwindow = xulwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
||||
Services.wm.removeListener(this);
|
||||
// wait for load to ensure the window is ready for us to test, make sure
|
||||
// we're not getting called for about:blank
|
||||
domwindow.addEventListener("load", function _load(event) {
|
||||
let doc = domwindow.document;
|
||||
if (event.target != doc)
|
||||
return;
|
||||
domwindow.removeEventListener("load", _load, false);
|
||||
|
||||
domwindow.addEventListener("unload", function _close(event) {
|
||||
if (event.target != doc)
|
||||
return;
|
||||
domwindow.removeEventListener("unload", _close, false);
|
||||
ok(true, "window has been closed");
|
||||
next();
|
||||
}, false);
|
||||
|
||||
is(doc.documentElement.getAttribute("windowtype"), "Social:Chat", "Social:Chat window opened");
|
||||
// window is loaded, but the docswap does not happen until after load,
|
||||
// and we have no event to wait on, so we'll wait for document state
|
||||
// to be ready
|
||||
let chatbox = doc.getElementById("chatter");
|
||||
waitForCondition(function() {
|
||||
return chats.children.length == 0 &&
|
||||
chatbox.contentDocument &&
|
||||
chatbox.contentDocument.readyState == "complete";
|
||||
},function() {
|
||||
// logout, we should get unload next
|
||||
port.postMessage({topic: "test-logout"});
|
||||
port.close();
|
||||
}, domwindow);
|
||||
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
port.postMessage({topic: "test-worker-chat", data: chatUrl});
|
||||
},
|
||||
|
||||
testReattachTwice: function(next) {
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
let chatBoxCount = 0, reattachCount = 0;
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
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-visibility":
|
||||
// chatbox is open, lets detach. The new chat window will be caught in
|
||||
// the window watcher below
|
||||
let doc = chats.selectedChat.contentDocument;
|
||||
// This message is (sometimes!) received a second time
|
||||
// before we start our tests from the onCloseWindow
|
||||
// callback.
|
||||
if (doc.location == "about:blank")
|
||||
return;
|
||||
if (++chatBoxCount != 2) {
|
||||
// open the second chat window
|
||||
port.postMessage({topic: "test-worker-chat", data: chatUrl + "?id=2"});
|
||||
return;
|
||||
}
|
||||
info("chatbox is open, detach from window");
|
||||
let chat1 = chats.firstChild;
|
||||
let chat2 = chat1.nextSibling;
|
||||
document.getAnonymousElementByAttribute(chat1, "anonid", "swap").click();
|
||||
document.getAnonymousElementByAttribute(chat2, "anonid", "swap").click();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
let firstChatWindowDoc;
|
||||
Services.wm.addListener({
|
||||
onWindowTitleChange: function() {},
|
||||
onCloseWindow: function(xulwindow) {},
|
||||
onOpenWindow: function(xulwindow) {
|
||||
let listener = this;
|
||||
let domwindow = xulwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindow);
|
||||
// wait for load to ensure the window is ready for us to test, make sure
|
||||
// we're not getting called for about:blank
|
||||
domwindow.addEventListener("load", function _load(event) {
|
||||
let doc = domwindow.document;
|
||||
if (event.target != doc)
|
||||
return;
|
||||
domwindow.removeEventListener("load", _load, false);
|
||||
|
||||
domwindow.addEventListener("unload", function _close(event) {
|
||||
if (event.target != doc)
|
||||
return;
|
||||
domwindow.removeEventListener("unload", _close, false);
|
||||
ok(true, "window has been closed");
|
||||
waitForCondition(function() {
|
||||
return chats.selectedChat && chats.selectedChat.contentDocument &&
|
||||
chats.selectedChat.contentDocument.readyState == "complete";
|
||||
}, function () {
|
||||
++reattachCount;
|
||||
if (reattachCount == 1) {
|
||||
info("reattaching second chat window");
|
||||
let chatbox = firstChatWindowDoc.getElementById("chatter");
|
||||
firstChatWindowDoc.getAnonymousElementByAttribute(chatbox, "anonid", "swap").click();
|
||||
firstChatWindowDoc = null;
|
||||
}
|
||||
else if (reattachCount == 2) {
|
||||
is(chats.children.length, 2, "both chat windows should be reattached");
|
||||
chats.removeAll();
|
||||
waitForCondition(() => chats.children.length == 0, function () {
|
||||
info("no chat window left");
|
||||
is(chats.chatboxForURL.size, 0, "chatboxForURL map should be empty");
|
||||
next();
|
||||
});
|
||||
}
|
||||
}, "waited too long for the window to reattach");
|
||||
}, false);
|
||||
|
||||
is(doc.documentElement.getAttribute("windowtype"), "Social:Chat", "Social:Chat window opened");
|
||||
if (!firstChatWindowDoc) {
|
||||
firstChatWindowDoc = doc;
|
||||
return;
|
||||
}
|
||||
Services.wm.removeListener(listener);
|
||||
|
||||
// window is loaded, but the docswap does not happen until after load,
|
||||
// and we have no event to wait on, so we'll wait for document state
|
||||
// to be ready
|
||||
let chatbox = doc.getElementById("chatter");
|
||||
waitForCondition(function() {
|
||||
return chats.children.length == 0 &&
|
||||
chatbox.contentDocument &&
|
||||
chatbox.contentDocument.readyState == "complete";
|
||||
},function() {
|
||||
info("reattaching chat window");
|
||||
doc.getAnonymousElementByAttribute(chatbox, "anonid", "swap").click();
|
||||
}, "waited too long for the chat window to be detached");
|
||||
|
||||
}, false);
|
||||
}
|
||||
});
|
||||
|
||||
port.postMessage({topic: "test-worker-chat", data: chatUrl + "?id=1"});
|
||||
}
|
||||
};
|
@ -45,8 +45,7 @@ function openChat(provider, callback) {
|
||||
}
|
||||
|
||||
function windowHasChats(win) {
|
||||
let chatbar = win.document.getElementById("pinnedchats");
|
||||
return !!chatbar.firstElementChild;
|
||||
return !!getChatBar().firstElementChild;
|
||||
}
|
||||
|
||||
function test() {
|
||||
@ -112,85 +111,6 @@ 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 = SocialSidebar.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 }});
|
||||
},
|
||||
testManyChats: function(next) {
|
||||
// open enough chats to overflow the window, then check
|
||||
// if the menupopup is visible
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
ok(port, "provider has a port");
|
||||
ok(chats.menupopup.parentNode.collapsed, "popup nub collapsed at start");
|
||||
port.postMessage({topic: "test-init"});
|
||||
// we should *never* find a test box that needs more than this to cause
|
||||
// an overflow!
|
||||
let maxToOpen = 20;
|
||||
let numOpened = 0;
|
||||
let maybeOpenAnother = function() {
|
||||
if (numOpened++ >= maxToOpen) {
|
||||
ok(false, "We didn't find a collapsed chat after " + maxToOpen + "chats!");
|
||||
closeAllChats();
|
||||
next();
|
||||
}
|
||||
port.postMessage({topic: "test-chatbox-open", data: { id: numOpened }});
|
||||
}
|
||||
port.onmessage = function (e) {
|
||||
let topic = e.data.topic;
|
||||
switch (topic) {
|
||||
case "got-chatbox-message":
|
||||
if (!chats.menupopup.parentNode.collapsed) {
|
||||
maybeOpenAnother();
|
||||
break;
|
||||
}
|
||||
ok(true, "popup nub became visible");
|
||||
// close our chats now
|
||||
while (chats.selectedChat) {
|
||||
chats.selectedChat.close();
|
||||
}
|
||||
ok(!chats.selectedChat, "chats are all closed");
|
||||
port.close();
|
||||
next();
|
||||
break;
|
||||
}
|
||||
}
|
||||
maybeOpenAnother();
|
||||
},
|
||||
testWorkerChatWindow: function(next) {
|
||||
const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
@ -244,61 +164,10 @@ var tests = {
|
||||
}
|
||||
port.postMessage({topic: "test-init", data: { id: 1 }});
|
||||
},
|
||||
testSameChatCallbacks: function(next) {
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
let port = SocialSidebar.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) {
|
||||
// This is the second time we've seen this message - there should
|
||||
// be exactly 1 chat open.
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
chats.selectedChat.close();
|
||||
is(chats.selectedChat, null, "should only have been one chat open");
|
||||
port.close();
|
||||
next();
|
||||
} else {
|
||||
// first time we got the opened message, so re-request the same
|
||||
// chat to be opened - we should get the message again.
|
||||
seen_opened = true;
|
||||
port.postMessage({topic: "test-chatbox-open"});
|
||||
}
|
||||
}
|
||||
}
|
||||
port.postMessage({topic: "test-init", data: { id: 1 }});
|
||||
},
|
||||
|
||||
// check removeAll does the right thing
|
||||
testRemoveAll: function(next, mode) {
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
port.postMessage({topic: "test-init"});
|
||||
get3ChatsForCollapsing(mode || "normal", function() {
|
||||
let chatbar = window.SocialChatBar.chatbar;
|
||||
chatbar.removeAll();
|
||||
// should be no evidence of any chats left.
|
||||
is(chatbar.childNodes.length, 0, "should be no chats left");
|
||||
checkPopup();
|
||||
is(chatbar.selectedChat, null, "nothing should be selected");
|
||||
is(chatbar.chatboxForURL.size, 0, "chatboxForURL map should be empty");
|
||||
port.close();
|
||||
next();
|
||||
});
|
||||
},
|
||||
|
||||
testRemoveAllMinimized: function(next) {
|
||||
this.testRemoveAll(next, "minimized");
|
||||
},
|
||||
|
||||
// Check what happens when you close the only visible chat.
|
||||
testCloseOnlyVisible: function(next) {
|
||||
let chatbar = window.SocialChatBar.chatbar;
|
||||
let chatbar = getChatBar();
|
||||
let chatWidth = undefined;
|
||||
let num = 0;
|
||||
is(chatbar.childNodes.length, 0, "chatbar starting empty");
|
||||
@ -336,7 +205,7 @@ var tests = {
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
port.postMessage({topic: "test-init"});
|
||||
get3ChatsForCollapsing("normal", function(first, second, third) {
|
||||
let chatbar = window.SocialChatBar.chatbar;
|
||||
let chatbar = getChatBar();
|
||||
chatbar.showChat(first);
|
||||
ok(!first.collapsed, "first should no longer be collapsed");
|
||||
ok(second.collapsed || third.collapsed, false, "one of the others should be collapsed");
|
||||
@ -363,7 +232,7 @@ var tests = {
|
||||
case "pong":
|
||||
executeSoon(function() {
|
||||
is(numOpened, 1, "only got one open message");
|
||||
chats.removeAll();
|
||||
chats.selectedChat.close();
|
||||
port.close();
|
||||
next();
|
||||
});
|
||||
@ -372,86 +241,6 @@ var tests = {
|
||||
port.postMessage({topic: "test-init", data: { id: 1 }});
|
||||
},
|
||||
|
||||
testSecondTopLevelWindow: function(next) {
|
||||
// Bug 817782 - check chats work in new top-level windows.
|
||||
const chatUrl = SocialSidebar.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let port = SocialSidebar.provider.getWorkerPort();
|
||||
let secondWindow;
|
||||
port.onmessage = function(e) {
|
||||
if (e.data.topic == "test-init-done") {
|
||||
secondWindow = OpenBrowserWindow();
|
||||
secondWindow.addEventListener("load", function loadListener() {
|
||||
secondWindow.removeEventListener("load", loadListener);
|
||||
port.postMessage({topic: "test-worker-chat", data: chatUrl});
|
||||
});
|
||||
} else if (e.data.topic == "got-chatbox-message") {
|
||||
// the chat was created - let's make sure it was created in the second window.
|
||||
is(secondWindow.SocialChatBar.chatbar.childElementCount, 1);
|
||||
secondWindow.close();
|
||||
next();
|
||||
}
|
||||
}
|
||||
port.postMessage({topic: "test-init"});
|
||||
},
|
||||
|
||||
testChatWindowChooser: function(next) {
|
||||
// Tests that when a worker creates a chat, it is opened in the correct
|
||||
// window.
|
||||
// open a chat (it will open in the main window)
|
||||
ok(!windowHasChats(window), "first window should start with no chats");
|
||||
openChat(SocialSidebar.provider, function() {
|
||||
ok(windowHasChats(window), "first window has the chat");
|
||||
// create a second window - this will be the "most recent" and will
|
||||
// therefore be the window that hosts the new chat (see bug 835111)
|
||||
let secondWindow = OpenBrowserWindow();
|
||||
secondWindow.addEventListener("load", function loadListener() {
|
||||
secondWindow.removeEventListener("load", loadListener);
|
||||
ok(!windowHasChats(secondWindow), "second window has no chats");
|
||||
openChat(SocialSidebar.provider, function() {
|
||||
ok(windowHasChats(secondWindow), "second window now has chats");
|
||||
is(window.SocialChatBar.chatbar.childElementCount, 1, "first window still has 1 chat");
|
||||
window.SocialChatBar.chatbar.removeAll();
|
||||
// now open another chat - it should still open in the second.
|
||||
openChat(SocialSidebar.provider, function() {
|
||||
ok(!windowHasChats(window), "first window has no chats");
|
||||
ok(windowHasChats(secondWindow), "second window has a chat");
|
||||
|
||||
// focus the first window, and open yet another chat - it
|
||||
// should open in the first window.
|
||||
waitForFocus(function() {
|
||||
openChat(SocialSidebar.provider, function() {
|
||||
ok(windowHasChats(window), "first window has chats");
|
||||
window.SocialChatBar.chatbar.removeAll();
|
||||
ok(!windowHasChats(window), "first window has no chats");
|
||||
|
||||
let privateWindow = OpenBrowserWindow({private: true});
|
||||
privateWindow.addEventListener("load", function loadListener() {
|
||||
privateWindow.removeEventListener("load", loadListener);
|
||||
|
||||
// open a last chat - the focused window can't accept
|
||||
// chats (it's a private window), so the chat should open
|
||||
// in the window that was selected before. This is known
|
||||
// to be broken on Linux.
|
||||
openChat(SocialSidebar.provider, function() {
|
||||
let os = Services.appinfo.OS;
|
||||
const BROKEN_WM_Z_ORDER = os != "WINNT" && os != "Darwin";
|
||||
let fn = BROKEN_WM_Z_ORDER ? todo : ok;
|
||||
fn(windowHasChats(window), "first window has a chat");
|
||||
window.SocialChatBar.chatbar.removeAll();
|
||||
|
||||
privateWindow.close();
|
||||
secondWindow.close();
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
window.focus();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
},
|
||||
testMultipleProviderChat: function(next) {
|
||||
// test incomming chats from all providers
|
||||
openChat(Social.providers[0], function() {
|
||||
@ -467,7 +256,7 @@ var tests = {
|
||||
port.postMessage({topic: "test-logout"});
|
||||
waitForCondition(function() chats.children.length == Social.providers.length - 1,
|
||||
function() {
|
||||
chats.removeAll();
|
||||
closeAllChats();
|
||||
waitForCondition(function() chats.children.length == 0,
|
||||
function() {
|
||||
ok(!chats.selectedChat, "multiprovider chats are all closed");
|
||||
|
@ -9,7 +9,7 @@ function isTabFocused() {
|
||||
}
|
||||
|
||||
function isChatFocused(chat) {
|
||||
return SocialChatBar.chatbar._isChatFocused(chat);
|
||||
return getChatBar()._isChatFocused(chat);
|
||||
}
|
||||
|
||||
function openChatViaUser() {
|
||||
@ -32,7 +32,7 @@ function openChatViaSidebarMessage(port, data, callback) {
|
||||
function openChatViaWorkerMessage(port, data, callback) {
|
||||
// sadly there is no message coming back to tell us when the chat has
|
||||
// been opened, so we wait until one appears.
|
||||
let chatbar = SocialChatBar.chatbar;
|
||||
let chatbar = getChatBar();
|
||||
let numExpected = chatbar.childElementCount + 1;
|
||||
port.postMessage({topic: "test-worker-chat", data: data});
|
||||
waitForCondition(function() chatbar.childElementCount == numExpected,
|
||||
@ -40,12 +40,13 @@ function openChatViaWorkerMessage(port, data, callback) {
|
||||
// so the child has been added, but we don't know if it
|
||||
// has been intialized - re-request it and the callback
|
||||
// means it's done. Minimized, same as the worker.
|
||||
SocialChatBar.openChat(SocialSidebar.provider,
|
||||
chatbar.openChat(SocialSidebar.provider.origin,
|
||||
SocialSidebar.provider.name,
|
||||
data,
|
||||
"minimized",
|
||||
function() {
|
||||
callback();
|
||||
},
|
||||
"minimized");
|
||||
});
|
||||
},
|
||||
"No new chat appeared");
|
||||
}
|
||||
@ -109,7 +110,7 @@ function test() {
|
||||
waitForCondition(function() isTabFocused(), cb, "tab should have focus");
|
||||
}
|
||||
let postSubTest = function(cb) {
|
||||
window.SocialChatBar.chatbar.removeAll();
|
||||
closeAllChats();
|
||||
cb();
|
||||
}
|
||||
// and run the tests.
|
||||
@ -132,21 +133,22 @@ var tests = {
|
||||
// Then we do it again - should still not be focused.
|
||||
// Then we perform a user-initiated request - it should get focus.
|
||||
testNoFocusWhenViaWorker: function(next) {
|
||||
let chatbar = getChatBar();
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaSidebarMessage(port, {stealFocus: 1}, function() {
|
||||
ok(true, "got chatbox message");
|
||||
is(SocialChatBar.chatbar.childElementCount, 1, "exactly 1 chat open");
|
||||
is(chatbar.childElementCount, 1, "exactly 1 chat open");
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
// re-request the same chat via a message.
|
||||
openChatViaSidebarMessage(port, {stealFocus: 1}, function() {
|
||||
is(SocialChatBar.chatbar.childElementCount, 1, "still exactly 1 chat open");
|
||||
is(chatbar.childElementCount, 1, "still exactly 1 chat open");
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
// re-request the same chat via user event.
|
||||
openChatViaUser();
|
||||
waitForCondition(function() isChatFocused(SocialChatBar.chatbar.selectedChat),
|
||||
waitForCondition(function() isChatFocused(chatbar.selectedChat),
|
||||
function() {
|
||||
is(SocialChatBar.chatbar.childElementCount, 1, "still exactly 1 chat open");
|
||||
is(SocialChatBar.chatbar.selectedChat, SocialChatBar.chatbar.firstElementChild, "chat should be selected");
|
||||
is(chatbar.childElementCount, 1, "still exactly 1 chat open");
|
||||
is(chatbar.selectedChat, chatbar.firstElementChild, "chat should be selected");
|
||||
next();
|
||||
}, "chat should be focused");
|
||||
});
|
||||
@ -158,204 +160,14 @@ var tests = {
|
||||
// click. This should cause the new chat to be opened and focused.
|
||||
testFocusWhenViaUser: function(next) {
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
let chatbar = getChatBar();
|
||||
openChatViaUser();
|
||||
ok(SocialChatBar.chatbar.firstElementChild, "chat opened");
|
||||
waitForCondition(function() isChatFocused(SocialChatBar.chatbar.selectedChat),
|
||||
ok(chatbar.firstElementChild, "chat opened");
|
||||
waitForCondition(function() isChatFocused(chatbar.selectedChat),
|
||||
function() {
|
||||
is(SocialChatBar.chatbar.selectedChat, SocialChatBar.chatbar.firstElementChild, "chat is selected");
|
||||
is(chatbar.selectedChat, chatbar.firstElementChild, "chat is selected");
|
||||
next();
|
||||
}, "chat should be focused");
|
||||
});
|
||||
},
|
||||
|
||||
// Open a chat via the worker - it will open and not have focus.
|
||||
// Then open the same chat via a sidebar message - it will be restored but
|
||||
// should still not have grabbed focus.
|
||||
testNoFocusOnAutoRestore: function(next) {
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html?id=1";
|
||||
let chatbar = SocialChatBar.chatbar;
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaWorkerMessage(port, chatUrl, function() {
|
||||
is(chatbar.childElementCount, 1, "exactly 1 chat open");
|
||||
// bug 865086 opening minimized still sets the window as selected
|
||||
todo(chatbar.selectedChat != chatbar.firstElementChild, "chat is not selected");
|
||||
ok(isTabFocused(), "tab should be focused");
|
||||
openChatViaSidebarMessage(port, {stealFocus: 1, id: 1}, function() {
|
||||
is(chatbar.childElementCount, 1, "still 1 chat open");
|
||||
ok(!chatbar.firstElementChild.minimized, "chat no longer minimized");
|
||||
// bug 865086 because we marked it selected on open, it still is
|
||||
todo(chatbar.selectedChat != chatbar.firstElementChild, "chat is not selected");
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// Here we open a chat, which will not be focused. Then we minimize it and
|
||||
// restore it via a titlebar clock - it should get focus at that point.
|
||||
testFocusOnExplicitRestore: function(next) {
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaSidebarMessage(port, {stealFocus: 1}, function() {
|
||||
ok(true, "got chatbox message");
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
let chatbox = SocialChatBar.chatbar.firstElementChild;
|
||||
ok(chatbox, "chat opened");
|
||||
chatbox.minimized = true;
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
// pretend we clicked on the titlebar
|
||||
chatbox.onTitlebarClick({button: 0});
|
||||
waitForCondition(function() isChatFocused(SocialChatBar.chatbar.selectedChat),
|
||||
function() {
|
||||
ok(!chatbox.minimized, "chat should have been restored");
|
||||
ok(isChatFocused(chatbox), "chat should be focused");
|
||||
is(chatbox, SocialChatBar.chatbar.selectedChat, "chat is marked selected");
|
||||
next();
|
||||
}, "chat should have focus");
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// Open 2 chats and give 1 focus. Minimize the focused one - the second
|
||||
// should get focus.
|
||||
testMinimizeFocused: function(next) {
|
||||
let chatbar = SocialChatBar.chatbar;
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaSidebarMessage(port, {stealFocus: 1, id: 1}, function() {
|
||||
let chat1 = chatbar.firstElementChild;
|
||||
openChatViaSidebarMessage(port, {stealFocus: 1, id: 2}, function() {
|
||||
is(chatbar.childElementCount, 2, "exactly 2 chats open");
|
||||
let chat2 = chat1.nextElementSibling || chat1.previousElementSibling;
|
||||
chatbar.selectedChat = chat1;
|
||||
chatbar.focus();
|
||||
waitForCondition(function() isChatFocused(chat1),
|
||||
function() {
|
||||
is(chat1, SocialChatBar.chatbar.selectedChat, "chat1 is marked selected");
|
||||
isnot(chat2, SocialChatBar.chatbar.selectedChat, "chat2 is not marked selected");
|
||||
chat1.minimized = true;
|
||||
waitForCondition(function() isChatFocused(chat2),
|
||||
function() {
|
||||
// minimizing the chat with focus should give it to another.
|
||||
isnot(chat1, SocialChatBar.chatbar.selectedChat, "chat1 is not marked selected");
|
||||
is(chat2, SocialChatBar.chatbar.selectedChat, "chat2 is marked selected");
|
||||
next();
|
||||
}, "chat2 should have focus");
|
||||
}, "chat1 should have focus");
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// Open 2 chats, select (but not focus) one, then re-request it be
|
||||
// opened via a message. Focus should not move.
|
||||
testReopenNonFocused: function(next) {
|
||||
let chatbar = SocialChatBar.chatbar;
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaSidebarMessage(port, {id: 1}, function() {
|
||||
let chat1 = chatbar.firstElementChild;
|
||||
openChatViaSidebarMessage(port, {id: 2}, function() {
|
||||
let chat2 = chat1.nextElementSibling || chat1.previousElementSibling;
|
||||
chatbar.selectedChat = chat2;
|
||||
// tab still has focus
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
// re-request the first.
|
||||
openChatViaSidebarMessage(port, {id: 1}, function() {
|
||||
is(chatbar.selectedChat, chat1, "chat1 now selected");
|
||||
ok(isTabFocused(), "tab should still be focused");
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// Open 2 chats, select and focus the second. Pressing the TAB key should
|
||||
// cause focus to move between all elements in our chat window before moving
|
||||
// to the next chat window.
|
||||
testTab: function(next) {
|
||||
function sendTabAndWaitForFocus(chat, eltid, callback) {
|
||||
// ideally we would use the 'focus' event here, but that doesn't work
|
||||
// as expected for the iframe - the iframe itself never gets the focus
|
||||
// event (apparently the sub-document etc does.)
|
||||
// So just poll for the correct element getting focus...
|
||||
let doc = chat.contentDocument;
|
||||
EventUtils.sendKey("tab");
|
||||
waitForCondition(function() {
|
||||
let elt = eltid ? doc.getElementById(eltid) : doc.documentElement;
|
||||
return doc.activeElement == elt;
|
||||
}, callback, "element " + eltid + " never got focus");
|
||||
}
|
||||
|
||||
let chatbar = SocialChatBar.chatbar;
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaSidebarMessage(port, {id: 1}, function() {
|
||||
let chat1 = chatbar.firstElementChild;
|
||||
openChatViaSidebarMessage(port, {id: 2}, function() {
|
||||
let chat2 = chat1.nextElementSibling || chat1.previousElementSibling;
|
||||
chatbar.selectedChat = chat2;
|
||||
chatbar.focus();
|
||||
waitForCondition(function() isChatFocused(chatbar.selectedChat),
|
||||
function() {
|
||||
// Our chats have 3 focusable elements, so it takes 4 TABs to move
|
||||
// to the new chat.
|
||||
sendTabAndWaitForFocus(chat2, "input1", function() {
|
||||
is(chat2.contentDocument.activeElement.getAttribute("id"), "input1",
|
||||
"first input field has focus");
|
||||
ok(isChatFocused(chat2), "new chat still focused after first tab");
|
||||
sendTabAndWaitForFocus(chat2, "input2", function() {
|
||||
ok(isChatFocused(chat2), "new chat still focused after tab");
|
||||
is(chat2.contentDocument.activeElement.getAttribute("id"), "input2",
|
||||
"second input field has focus");
|
||||
sendTabAndWaitForFocus(chat2, "iframe", function() {
|
||||
ok(isChatFocused(chat2), "new chat still focused after tab");
|
||||
is(chat2.contentDocument.activeElement.getAttribute("id"), "iframe",
|
||||
"iframe has focus");
|
||||
// this tab now should move to the next chat, but focus the
|
||||
// document element itself (hence the null eltid)
|
||||
sendTabAndWaitForFocus(chat1, null, function() {
|
||||
ok(isChatFocused(chat1), "first chat is focused");
|
||||
next();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, "chat should have focus");
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// Open a chat and focus an element other than the first. Move focus to some
|
||||
// other item (the tab itself in this case), then focus the chatbar - the
|
||||
// same element that was previously focused should still have focus.
|
||||
testFocusedElement: function(next) {
|
||||
let chatbar = SocialChatBar.chatbar;
|
||||
startTestAndWaitForSidebar(function(port) {
|
||||
openChatViaUser();
|
||||
let chat = chatbar.firstElementChild;
|
||||
// need to wait for the content to load before we can focus it.
|
||||
chat.addEventListener("DOMContentLoaded", function DOMContentLoaded() {
|
||||
chat.removeEventListener("DOMContentLoaded", DOMContentLoaded);
|
||||
chat.contentDocument.getElementById("input2").focus();
|
||||
waitForCondition(function() isChatFocused(chat),
|
||||
function() {
|
||||
is(chat.contentDocument.activeElement.getAttribute("id"), "input2",
|
||||
"correct input field has focus");
|
||||
// set focus to the tab.
|
||||
let tabb = gBrowser.getBrowserForTab(gBrowser.selectedTab);
|
||||
Services.focus.moveFocus(tabb.contentWindow, null, Services.focus.MOVEFOCUS_ROOT, 0);
|
||||
waitForCondition(function() isTabFocused(),
|
||||
function() {
|
||||
chatbar.focus();
|
||||
waitForCondition(function() isChatFocused(chat),
|
||||
function() {
|
||||
is(chat.contentDocument.activeElement.getAttribute("id"), "input2",
|
||||
"correct input field still has focus");
|
||||
next();
|
||||
}, "chat took focus");
|
||||
}, "tab has focus");
|
||||
}, "chat took focus");
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -9,6 +9,8 @@ function gc() {
|
||||
wu.garbageCollect();
|
||||
}
|
||||
|
||||
let openChatWindow = Cu.import("resource://gre/modules/MozSocialAPI.jsm", {}).openChatWindow;
|
||||
|
||||
// Support for going on and offline.
|
||||
// (via browser/base/content/test/browser_bookmark_titles.js)
|
||||
let origProxyType = Services.prefs.getIntPref('network.proxy.type');
|
||||
@ -42,9 +44,10 @@ function openPanel(url, panelCallback, loadCallback) {
|
||||
|
||||
function openChat(url, panelCallback, loadCallback) {
|
||||
// open a chat window
|
||||
SocialChatBar.openChat(SocialSidebar.provider, url, panelCallback);
|
||||
SocialChatBar.chatbar.firstChild.addEventListener("DOMContentLoaded", function panelLoad() {
|
||||
SocialChatBar.chatbar.firstChild.removeEventListener("DOMContentLoaded", panelLoad, true);
|
||||
let chatbar = getChatBar();
|
||||
openChatWindow(null, SocialSidebar.provider, url, panelCallback);
|
||||
chatbar.firstChild.addEventListener("DOMContentLoaded", function panelLoad() {
|
||||
chatbar.firstChild.removeEventListener("DOMContentLoaded", panelLoad, true);
|
||||
loadCallback();
|
||||
}, true);
|
||||
}
|
||||
@ -154,7 +157,7 @@ var tests = {
|
||||
|
||||
testChatWindow: function(next) {
|
||||
let panelCallbackCount = 0;
|
||||
// go offline and open a flyout.
|
||||
// go offline and open a chat.
|
||||
goOffline();
|
||||
openChat(
|
||||
"https://example.com/browser/browser/base/content/test/social/social_chat.html",
|
||||
@ -164,7 +167,7 @@ var tests = {
|
||||
function() { // the "load" callback.
|
||||
executeSoon(function() {
|
||||
todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads.");
|
||||
let chat = SocialChatBar.chatbar.selectedChat;
|
||||
let chat = getChatBar().selectedChat;
|
||||
waitForCondition(function() chat.contentDocument.location.href.indexOf("about:socialerror?")==0,
|
||||
function() {
|
||||
chat.close();
|
||||
@ -186,7 +189,7 @@ var tests = {
|
||||
null,
|
||||
function() { // the "load" callback.
|
||||
executeSoon(function() {
|
||||
let chat = SocialChatBar.chatbar.selectedChat;
|
||||
let chat = getChatBar().selectedChat;
|
||||
is(chat.contentDocument.location.href, url, "correct url loaded");
|
||||
// toggle to a detached window.
|
||||
chat.swapWindows().then(
|
||||
|
@ -399,7 +399,7 @@ function get3ChatsForCollapsing(mode, cb) {
|
||||
// To make our life easier we don't go via the worker and ports so we get
|
||||
// more control over creation *and* to make the code much simpler. We
|
||||
// assume the worker/port stuff is individually tested above.
|
||||
let chatbar = window.SocialChatBar.chatbar;
|
||||
let chatbar = getChatBar();
|
||||
let chatWidth = undefined;
|
||||
let num = 0;
|
||||
is(chatbar.childNodes.length, 0, "chatbar starting empty");
|
||||
@ -443,23 +443,21 @@ function makeChat(mode, uniqueid, cb) {
|
||||
info("making a chat window '" + uniqueid +"'");
|
||||
let provider = SocialSidebar.provider;
|
||||
const chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let isOpened = window.SocialChatBar.openChat(provider, chatUrl + "?id=" + uniqueid, function(chat) {
|
||||
// Note that we use promiseChatLoaded instead of the callback to ensure the
|
||||
// content has started loading.
|
||||
let chatbox = getChatBar().openChat(provider.origin, provider.name,
|
||||
chatUrl + "?id=" + uniqueid, mode);
|
||||
chatbox.promiseChatLoaded.then(
|
||||
() => {
|
||||
info("chat window has opened");
|
||||
// we can't callback immediately or we might close the chat during
|
||||
// this event which upsets the implementation - it is only 1/2 way through
|
||||
// handling the load event.
|
||||
chat.document.title = uniqueid;
|
||||
executeSoon(cb);
|
||||
}, mode);
|
||||
if (!isOpened) {
|
||||
ok(false, "unable to open chat window, no provider? more failures to come");
|
||||
executeSoon(cb);
|
||||
}
|
||||
chatbox.contentDocument.title = uniqueid;
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
function checkPopup() {
|
||||
// popup only showing if any collapsed popup children.
|
||||
let chatbar = window.SocialChatBar.chatbar;
|
||||
let chatbar = getChatBar();
|
||||
let numCollapsed = 0;
|
||||
for (let chat of chatbar.childNodes) {
|
||||
if (chat.collapsed) {
|
||||
@ -478,7 +476,7 @@ function checkPopup() {
|
||||
// Does a callback passing |true| if the window is now big enough or false
|
||||
// if we couldn't resize large enough to satisfy the test requirement.
|
||||
function resizeWindowToChatAreaWidth(desired, cb, count = 0) {
|
||||
let current = window.SocialChatBar.chatbar.getBoundingClientRect().width;
|
||||
let current = getChatBar().getBoundingClientRect().width;
|
||||
let delta = desired - current;
|
||||
info(count + ": resizing window so chat area is " + desired + " wide, currently it is "
|
||||
+ current + ". Screen avail is " + window.screen.availWidth
|
||||
@ -511,7 +509,7 @@ function resizeWindowToChatAreaWidth(desired, cb, count = 0) {
|
||||
}
|
||||
function resize_handler(event) {
|
||||
// we did resize - but did we get far enough to be able to continue?
|
||||
let newSize = window.SocialChatBar.chatbar.getBoundingClientRect().width;
|
||||
let newSize = getChatBar().getBoundingClientRect().width;
|
||||
let sizedOk = widthDeltaCloseEnough(newSize - desired);
|
||||
if (!sizedOk)
|
||||
return;
|
||||
@ -559,8 +557,13 @@ function resizeAndCheckWidths(first, second, third, checks, cb) {
|
||||
}, count);
|
||||
}
|
||||
|
||||
function getChatBar() {
|
||||
return document.getElementById("pinnedchats");
|
||||
}
|
||||
|
||||
function getPopupWidth() {
|
||||
let popup = window.SocialChatBar.chatbar.menupopup;
|
||||
let chatbar = getChatBar();
|
||||
let popup = chatbar.menupopup;
|
||||
ok(!popup.parentNode.collapsed, "asking for popup width when it is visible");
|
||||
let cs = document.defaultView.getComputedStyle(popup.parentNode);
|
||||
let margins = parseInt(cs.marginLeft) + parseInt(cs.marginRight);
|
||||
@ -568,6 +571,8 @@ function getPopupWidth() {
|
||||
}
|
||||
|
||||
function closeAllChats() {
|
||||
let chatbar = window.SocialChatBar.chatbar;
|
||||
chatbar.removeAll();
|
||||
let chatbar = getChatBar();
|
||||
while (chatbar.selectedChat) {
|
||||
chatbar.selectedChat.close();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ MOCHITEST_CHROME_MANIFESTS += [
|
||||
]
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += [
|
||||
'content/test/chat/browser.ini',
|
||||
'content/test/general/browser.ini',
|
||||
'content/test/newtab/browser.ini',
|
||||
'content/test/plugins/browser.ini',
|
||||
|
Loading…
Reference in New Issue
Block a user