зеркало из https://github.com/mozilla/gecko-dev.git
bug 891221 add tests for chat from multiple providers, r=markh
This commit is contained in:
Родитель
71661cb777
Коммит
df67b2b74d
|
@ -2,17 +2,71 @@
|
|||
* 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 SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
|
||||
|
||||
let manifests = [
|
||||
{
|
||||
name: "provider@example.com",
|
||||
origin: "https://example.com",
|
||||
sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?example.com",
|
||||
workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
|
||||
iconURL: "chrome://branding/content/icon48.png"
|
||||
},
|
||||
{
|
||||
name: "provider@test1",
|
||||
origin: "https://test1.example.com",
|
||||
sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?test1",
|
||||
workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
|
||||
iconURL: "chrome://branding/content/icon48.png"
|
||||
},
|
||||
{
|
||||
name: "provider@test2",
|
||||
origin: "https://test2.example.com",
|
||||
sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?test2",
|
||||
workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js",
|
||||
iconURL: "chrome://branding/content/icon48.png"
|
||||
}
|
||||
];
|
||||
|
||||
let chatId = 0;
|
||||
function openChat(provider, callback) {
|
||||
let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let port = provider.getWorkerPort();
|
||||
port.onmessage = function(e) {
|
||||
if (e.data.topic == "got-chatbox-message") {
|
||||
port.close();
|
||||
callback();
|
||||
}
|
||||
}
|
||||
let url = chatUrl + "?" + (chatId++);
|
||||
port.postMessage({topic: "test-init"});
|
||||
port.postMessage({topic: "test-worker-chat", data: url});
|
||||
gURLsNotRemembered.push(url);
|
||||
}
|
||||
|
||||
function waitPrefChange(cb) {
|
||||
Services.prefs.addObserver("social.enabled", function prefObserver(subject, topic, data) {
|
||||
Services.prefs.removeObserver("social.enabled", prefObserver);
|
||||
executeSoon(cb);
|
||||
}, false);
|
||||
}
|
||||
|
||||
function setWorkerMode(multiple, cb) {
|
||||
waitPrefChange(function() {
|
||||
if (multiple)
|
||||
Services.prefs.setBoolPref("social.allowMultipleWorkers", true);
|
||||
else
|
||||
Services.prefs.clearUserPref("social.allowMultipleWorkers");
|
||||
waitPrefChange(cb);
|
||||
Social.enabled = true;
|
||||
});
|
||||
Social.enabled = false;
|
||||
}
|
||||
|
||||
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/moz.png"
|
||||
};
|
||||
let oldwidth = window.outerWidth; // we futz with these, so we restore them
|
||||
let oldleft = window.screenX;
|
||||
window.moveTo(0, window.screenY)
|
||||
|
@ -21,7 +75,7 @@ function test() {
|
|||
ok(chats.children.length == 0, "no chatty children left behind");
|
||||
cb();
|
||||
};
|
||||
runSocialTestWithProvider(manifest, function (finishcb) {
|
||||
runSocialTestWithProvider(manifests, function (finishcb) {
|
||||
runSocialTests(tests, undefined, postSubTest, function() {
|
||||
window.moveTo(oldleft, window.screenY)
|
||||
window.resizeTo(oldwidth, window.outerHeight);
|
||||
|
@ -147,7 +201,7 @@ var tests = {
|
|||
maybeOpenAnother();
|
||||
},
|
||||
testWorkerChatWindow: function(next) {
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
const chatUrl = Social.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
let port = Social.provider.getWorkerPort();
|
||||
ok(port, "provider has a port");
|
||||
|
@ -384,7 +438,7 @@ var tests = {
|
|||
|
||||
testSecondTopLevelWindow: function(next) {
|
||||
// Bug 817782 - check chats work in new top-level windows.
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
const chatUrl = Social.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let port = Social.provider.getWorkerPort();
|
||||
let secondWindow;
|
||||
port.onmessage = function(e) {
|
||||
|
@ -407,23 +461,9 @@ var tests = {
|
|||
testChatWindowChooser: function(next) {
|
||||
// Tests that when a worker creates a chat, it is opened in the correct
|
||||
// window.
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
let chatId = 1;
|
||||
let port = Social.provider.getWorkerPort();
|
||||
port.postMessage({topic: "test-init"});
|
||||
|
||||
function openChat(callback) {
|
||||
port.onmessage = function(e) {
|
||||
if (e.data.topic == "got-chatbox-message")
|
||||
callback();
|
||||
}
|
||||
let url = chatUrl + "?" + (chatId++);
|
||||
port.postMessage({topic: "test-worker-chat", data: url});
|
||||
}
|
||||
|
||||
// open a chat (it will open in the main window)
|
||||
ok(!window.SocialChatBar.hasChats, "first window should start with no chats");
|
||||
openChat(function() {
|
||||
openChat(Social.provider, function() {
|
||||
ok(window.SocialChatBar.hasChats, "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)
|
||||
|
@ -431,27 +471,55 @@ var tests = {
|
|||
secondWindow.addEventListener("load", function loadListener() {
|
||||
secondWindow.removeEventListener("load", loadListener);
|
||||
ok(!secondWindow.SocialChatBar.hasChats, "second window has no chats");
|
||||
openChat(function() {
|
||||
openChat(Social.provider, function() {
|
||||
ok(secondWindow.SocialChatBar.hasChats, "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(function() {
|
||||
openChat(Social.provider, function() {
|
||||
ok(!window.SocialChatBar.hasChats, "first window has no chats");
|
||||
ok(secondWindow.SocialChatBar.hasChats, "second window has a chat");
|
||||
secondWindow.close();
|
||||
port.close();
|
||||
next();
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
},
|
||||
testMultipleProviderChat: function(next) {
|
||||
// while pref'd off, we need to set the worker mode to multiple providers
|
||||
setWorkerMode(true, function() {
|
||||
// test incomming chats from all providers
|
||||
openChat(Social.providers[0], function() {
|
||||
openChat(Social.providers[1], function() {
|
||||
openChat(Social.providers[2], function() {
|
||||
let chats = document.getElementById("pinnedchats");
|
||||
waitForCondition(function() chats.children.length == Social.providers.length,
|
||||
function() {
|
||||
ok(true, "one chat window per provider opened");
|
||||
// test logout of a single provider
|
||||
let provider = Social.providers[0];
|
||||
let port = provider.getWorkerPort();
|
||||
port.postMessage({topic: "test-logout"});
|
||||
waitForCondition(function() chats.children.length == Social.providers.length - 1,
|
||||
function() {
|
||||
port.close();
|
||||
chats.removeAll();
|
||||
ok(!chats.selectedChat, "chats are all closed");
|
||||
setWorkerMode(false, next);
|
||||
},
|
||||
"chat window didn't close");
|
||||
}, "chat windows did not open");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// XXX - note this must be the last test until we restore the login state
|
||||
// between tests...
|
||||
testCloseOnLogout: function(next) {
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
const chatUrl = Social.provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
|
||||
let port = Social.provider.getWorkerPort();
|
||||
ok(port, "provider has a port");
|
||||
let opened = false;
|
||||
|
|
|
@ -417,8 +417,8 @@ function get3ChatsForCollapsing(mode, cb) {
|
|||
|
||||
function makeChat(mode, uniqueid, cb) {
|
||||
info("making a chat window '" + uniqueid +"'");
|
||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social/social_chat.html";
|
||||
let provider = Social.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) {
|
||||
info("chat window has opened");
|
||||
// we can't callback immediately or we might close the chat during
|
||||
|
|
Загрузка…
Ссылка в новой задаче