summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/im
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/test/browser/im')
-rw-r--r--comm/mail/test/browser/im/browser.ini23
-rw-r--r--comm/mail/test/browser/im/browser_chatTabRestore.js102
-rw-r--r--comm/mail/test/browser/im/browser_toolbarButtons.js147
3 files changed, 272 insertions, 0 deletions
diff --git a/comm/mail/test/browser/im/browser.ini b/comm/mail/test/browser/im/browser.ini
new file mode 100644
index 0000000000..cba4d07872
--- /dev/null
+++ b/comm/mail/test/browser/im/browser.ini
@@ -0,0 +1,23 @@
+[DEFAULT]
+prefs =
+ mail.provider.suppress_dialog_on_startup=true
+ mail.shell.checkDefaultClient=false
+ mail.spotlight.firstRunDone=true
+ mail.winsearch.firstRunDone=true
+ mailnews.start_page.override_url=about:blank
+ mailnews.start_page.url=about:blank
+ messenger.account.account1.autoLogin=false
+ messenger.account.account1.firstConnectionState=1
+ messenger.account.account1.name=mozmilltest@irc.mozilla.invalid
+ messenger.account.account1.prpl=prpl-irc
+ mail.accountmanager.accounts=account1
+ mail.account.account1.server=server1
+ mail.server.server1.imAccount=account1
+ mail.server.server1.type=im
+ mail.server.server1.hostname=prpl-irc
+ mail.server.server1.userName=mozmilltest@irc.mozilla.invalid
+ datareporting.policy.dataSubmissionPolicyBypassNotification=true
+subsuite = thunderbird
+
+[browser_chatTabRestore.js]
+[browser_toolbarButtons.js]
diff --git a/comm/mail/test/browser/im/browser_chatTabRestore.js b/comm/mail/test/browser/im/browser_chatTabRestore.js
new file mode 100644
index 0000000000..e80ecc0461
--- /dev/null
+++ b/comm/mail/test/browser/im/browser_chatTabRestore.js
@@ -0,0 +1,102 @@
+/* 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/. */
+
+"use strict";
+
+var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.jsm");
+
+var { assert_tab_mode_name, mc } = ChromeUtils.import(
+ "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
+);
+
+/**
+ * Create a new chat tab, making that tab the current tab. We block until the
+ * message finishes loading. (Inspired by open_selected_message_in_new_tab)
+ */
+async function open_chat_tab() {
+ // Get the current tab count so we can make sure the tab actually opened.
+ let preCount =
+ mc.window.document.getElementById("tabmail").tabContainer.allTabs.length;
+
+ mc.window.document.getElementById("tabmail").openTab("chat", {});
+ await wait_for_chat_tab_to_open(mc);
+
+ if (
+ mc.window.document.getElementById("tabmail").tabContainer.allTabs.length !=
+ preCount + 1
+ ) {
+ throw new Error("The tab never actually got opened!");
+ }
+
+ let newTab = mc.window.document.getElementById("tabmail").tabInfo[preCount];
+ return newTab;
+}
+
+async function wait_for_chat_tab_to_open(aController) {
+ if (aController == null) {
+ aController = mc;
+ }
+
+ utils.waitFor(
+ function () {
+ let chatTabFound = false;
+ for (let tab of mc.window.document.getElementById("tabmail").tabInfo) {
+ if (tab.mode.type == "chat") {
+ chatTabFound = true;
+ break;
+ }
+ }
+ return chatTabFound;
+ },
+ "Timeout waiting for chat tab to open",
+ 1000,
+ 50
+ );
+
+ // The above may return immediately, meaning the event queue might not get a
+ // chance. Give it a chance now.
+ await new Promise(resolve => setTimeout(resolve));
+}
+
+/**
+ * This tests that the chat tab is restored properly after tabs are
+ * serialized. As for folder tabs, we can't test a restart (can we ?), so we
+ * just test the persist/restore cycle.
+ */
+add_task(async function test_chat_tab_restore() {
+ // Close everything but the first tab.
+ let closeTabs = function () {
+ while (mc.window.document.getElementById("tabmail").tabInfo.length > 1) {
+ mc.window.document.getElementById("tabmail").closeTab(1);
+ }
+ };
+
+ await open_chat_tab();
+ let state = mc.window.document.getElementById("tabmail").persistTabs();
+ closeTabs();
+ mc.window.document.getElementById("tabmail").restoreTabs(state);
+
+ if (
+ mc.window.document.getElementById("tabmail").tabContainer.allTabs.length < 2
+ ) {
+ throw new Error("The tab is not restored!");
+ }
+
+ let tabTypes = ["mail3PaneTab", "chat"];
+ for (let i in tabTypes) {
+ assert_tab_mode_name(
+ mc.window.document.getElementById("tabmail").tabInfo[i],
+ tabTypes[i]
+ );
+ }
+
+ closeTabs();
+
+ Assert.report(
+ false,
+ undefined,
+ undefined,
+ "Test ran to completion successfully"
+ );
+});
diff --git a/comm/mail/test/browser/im/browser_toolbarButtons.js b/comm/mail/test/browser/im/browser_toolbarButtons.js
new file mode 100644
index 0000000000..960443a85b
--- /dev/null
+++ b/comm/mail/test/browser/im/browser_toolbarButtons.js
@@ -0,0 +1,147 @@
+/* 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/. */
+
+"use strict";
+
+var { mc } = ChromeUtils.import(
+ "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
+);
+
+var { IMServices } = ChromeUtils.importESModule(
+ "resource:///modules/IMServices.sys.mjs"
+);
+
+/* This test checks that the toolbar buttons of the chat toolbar are
+ * correctly disabled/enabled, and that the placeholder displayed in
+ * the middle of the chat tab is correct.
+ */
+add_task(function test_toolbar_and_placeholder() {
+ Assert.notEqual(
+ mc.window.document.getElementById("tabmail").selectedTab.mode.type,
+ "chat",
+ "the chat tab shouldn't be selected at startup"
+ );
+ EventUtils.synthesizeMouseAtCenter(
+ mc.window.document.getElementById("chatButton"),
+ { clickCount: 1 },
+ mc.window
+ );
+ Assert.equal(
+ mc.window.document.getElementById("tabmail").selectedTab.mode.type,
+ "chat",
+ "the chat tab should be selected"
+ );
+
+ // Check that "No connected account" placeholder is correct.
+ Assert.ok(
+ !mc.window.document.getElementById("noConvScreen").hidden,
+ "'Your chat accounts are not connected.' placeholder"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("noConvInnerBox").hidden,
+ "the 'No conversation' placeholder is hidden"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("noAccountInnerBox").hidden,
+ "the 'No account' placeholder is hidden"
+ );
+ Assert.ok(
+ !mc.window.document.getElementById("noConnectedAccountInnerBox").hidden,
+ "the 'No connected account' placeholder is visible"
+ );
+ let chatHandler = mc.window.chatHandler;
+ Assert.equal(
+ chatHandler._placeHolderButtonId,
+ "openIMAccountManagerButton",
+ "the correct placeholder button is visible"
+ );
+ Assert.equal(
+ mc.window.document.activeElement.id,
+ chatHandler._placeHolderButtonId,
+ "the placeholder button is focused"
+ );
+
+ // check that add contact and join chat are disabled
+ Assert.ok(
+ mc.window.document.getElementById("button-add-buddy").disabled,
+ "the Add Buddy button is disabled"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("button-join-chat").disabled,
+ "the Join Chat button is disabled"
+ );
+
+ // The next tests require an account, get the unwrapped default IRC account.
+ let account = IMServices.accounts.getAccountByNumericId(1);
+ Assert.equal(
+ account.protocol.id,
+ "prpl-irc",
+ "the default IM account is an IRC account"
+ );
+ let ircAccount = account.prplAccount.wrappedJSObject;
+
+ // Pretend the account is connected and check how the UI reacts
+ ircAccount.reportConnected();
+
+ // check that add contact and join chat are no longer disabled
+ Assert.ok(
+ !mc.window.document.getElementById("button-add-buddy").disabled,
+ "the Add Buddy button is not disabled"
+ );
+ Assert.ok(
+ !mc.window.document.getElementById("button-join-chat").disabled,
+ "the Join Chat button is not disabled"
+ );
+
+ // Check that the "No conversations" placeholder is correct.
+ Assert.ok(
+ !mc.window.document.getElementById("noConvInnerBox").hidden,
+ "the 'No conversation' placeholder is visible"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("noAccountInnerBox").hidden,
+ "the 'No account' placeholder is hidden"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("noConnectedAccountInnerBox").hidden,
+ "the 'No connected account' placeholder is hidden"
+ );
+ Assert.ok(!chatHandler._placeHolderButtonId, "no placeholder button");
+
+ // Now check that the UI reacts to account disconnections too.
+ ircAccount.reportDisconnected();
+
+ // check that add contact and join chat are disabled again.
+ Assert.ok(
+ mc.window.document.getElementById("button-add-buddy").disabled,
+ "the Add Buddy button is disabled"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("button-join-chat").disabled,
+ "the Join Chat button is disabled"
+ );
+
+ // Check that the "No connected account" placeholder is back.
+ Assert.ok(
+ mc.window.document.getElementById("noConvInnerBox").hidden,
+ "the 'No conversation' placeholder is hidden"
+ );
+ Assert.ok(
+ mc.window.document.getElementById("noAccountInnerBox").hidden,
+ "the 'No account' placeholder is hidden"
+ );
+ Assert.ok(
+ !mc.window.document.getElementById("noConnectedAccountInnerBox").hidden,
+ "the 'No connected account' placeholder is visible"
+ );
+ Assert.equal(
+ chatHandler._placeHolderButtonId,
+ "openIMAccountManagerButton",
+ "the correct placeholder button is visible"
+ );
+
+ while (mc.window.document.getElementById("tabmail").tabInfo.length > 1) {
+ mc.window.document.getElementById("tabmail").closeTab(1);
+ }
+});