Bug 566825 Multiple signatures when switching between accounts (signature of previously selected account is not removed). Adapt to localName returning lower case. r=Standard8,sr=bienvenu
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/test-signature-updating.js
@@ -0,0 +1,180 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Steffen Wilberg <steffen.wilberg@web.de>
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/**
+ * Tests that the signature updates properly when switching identities.
+ */
+
+// make SOLO_TEST=composition/test-signature-updating.js mozmill-one
+
+// mail.identity.id1.htmlSigFormat = false
+// mail.identity.id1.htmlSigText = "Tinderbox is soo 90ies"
+
+// mail.identity.id2.htmlSigFormat = true
+// mail.identity.id2.htmlSigText = "Tinderboxpushlog is the new <b>hotness!</b>"
+
+const MODULE_NAME = "test-signature-updating";
+
+const RELATIVE_ROOT = "../shared-modules";
+const MODULE_REQUIRES = ["folder-display-helpers", "compose-helpers", "window-helpers"];
+var jumlib = {};
+Components.utils.import("resource://mozmill/modules/jum.js", jumlib);
+var elib = {};
+Components.utils.import("resource://mozmill/modules/elementslib.js", elib);
+
+var composeHelper = null;
+var cwc = null; // compose window controller
+var prefBranch = Cc["@mozilla.org/preferences-service;1"]
+ .getService(Ci.nsIPrefService).getBranch(null);
+
+var setupModule = function (module) {
+ let fdh = collector.getModule("folder-display-helpers");
+ fdh.installInto(module);
+ composeHelper = collector.getModule("compose-helpers");
+ composeHelper.installInto(module);
+ let wh = collector.getModule("window-helpers");
+ wh.installInto(module);
+};
+
+function setupComposeWin(toAddr, subj, body) {
+ cwc.type(cwc.a("addressingWidget", {class: "addressingWidgetCell", crazyDeck: 1}), toAddr);
+ cwc.type(cwc.eid("msgSubject"), subj)
+ cwc.type(cwc.eid("content-frame"), body);
+}
+
+/**
+ * Test that the plaintext compose window has a signature initially,
+ * and has the correct signature after switching to another identity.
+ */
+function testPlaintextComposeWindowSwitchSignatures() {
+ prefBranch.setBoolPref("mail.identity.id1.compose_html", false);
+ cwc = composeHelper.open_compose_new_mail();
+
+ setupComposeWin("", "Plaintext compose window", "Body, first line.");
+
+ let contentFrame = cwc.e("content-frame");
+ let node = contentFrame.contentDocument.body.lastChild;
+
+ // In plaintext compose, the signature is followed by two <br> elements.
+ assert_equals(node.localName, "br");
+ node = node.previousSibling;
+ assert_equals(node.localName, "br");
+ node = node.previousSibling;
+ assert_equals(node.nodeValue, "Tinderbox is soo 90ies");
+ node = node.previousSibling.previousSibling; // a <br> element, then the next text node
+ assert_equals(node.nodeValue, "-- ");
+
+ // Now switch identities!
+ let menuID = cwc.e("msgIdentity");
+ menuID.value = "id2";
+ menuID.click();
+
+ node = contentFrame.contentDocument.body.lastChild;
+
+ // In plaintext compose, the signature is followed by two <br> elements.
+ assert_equals(node.localName, "br");
+ node = node.previousSibling;
+ assert_equals(node.localName, "br");
+ node = node.previousSibling;
+ assert_equals(node.nodeValue, "Tinderboxpushlog is the new *hotness!*");
+ node = node.previousSibling.previousSibling; // a <br> element, then the next text node
+ assert_equals(node.nodeValue, "-- ");
+
+ // Now check that the original signature has been removed!
+ let bodyFirstChild = contentFrame.contentDocument.body.firstChild;
+ while (node != bodyFirstChild) {
+ node = node.previousSibling;
+ jumlib.assertNotEquals(node.nodeValue, "Tinderbox is soo 90ies");
+ jumlib.assertNotEquals(node.nodeValue, "-- ");
+ }
+ assert_equals(node.nodeValue, "Body, first line.");
+
+ composeHelper.close_compose_window(cwc);
+}
+
+/**
+ * Same test, but with an HTML compose window
+ */
+function testHTMLComposeWindowSwitchSignatures() {
+ prefBranch.setBoolPref("mail.identity.id1.compose_html", true);
+ cwc = composeHelper.open_compose_new_mail();
+
+ setupComposeWin("", "HTML compose window", "Body, first line.");
+
+ let contentFrame = cwc.e("content-frame");
+ let node = contentFrame.contentDocument.body.lastChild;
+
+ // In html compose, the signature is inside the last node, which has a
+ // class="moz-signature".
+ assert_equals(node.className, "moz-signature")
+ node = node.firstChild; // text node containing the signature divider
+ assert_equals(node.nodeValue, "-- \nTinderbox is soo 90ies");
+
+ // Now switch identities!
+ let menuID = cwc.e("msgIdentity");
+ menuID.value = "id2";
+ menuID.click();
+
+ node = contentFrame.contentDocument.body.lastChild;
+
+ // In html compose, the signature is inside the last node
+ // with class="moz-signature".
+ assert_equals(node.className, "moz-signature");
+ node = node.firstChild; // text node containing the signature divider
+ assert_equals(node.nodeValue, "-- ");
+ node = node.nextSibling;
+ assert_equals(node.localName, "br");
+ node = node.nextSibling;
+ assert_equals(node.nodeValue, "Tinderboxpushlog is the new ");
+ node = node.nextSibling;
+ assert_equals(node.localName, "b");
+ node = node.firstChild;
+ assert_equals(node.nodeValue, "hotness!");
+
+ // Now check that the original signature has been removed,
+ // and no blank lines got added!
+ node = contentFrame.contentDocument.body.firstChild;
+ assert_equals(node.nodeValue, "Body, first line.");
+ node = node.nextSibling;
+ assert_equals(node.localName, "br");
+ node = node.nextSibling;
+ // check that the signature is immediately after the message text.
+ assert_equals(node.className, "moz-signature");
+ // check that that the signature is the last node.
+ assert_equals(node, contentFrame.contentDocument.body.lastChild);
+
+ composeHelper.close_compose_window(cwc);
+}
--- a/mail/test/mozmill/mozmilltests.list
+++ b/mail/test/mozmill/mozmilltests.list
@@ -1,17 +1,18 @@
-folder-display
-junk-commands
-search-window
-cookies
+account
+composition/test-signature-updating.js
content-policy
content-tabs
-message-header
+cookies
+folder-display
+folder-pane
+folder-tree-modes
folder-widget
-folder-pane
+junk-commands
+message-header
message-window
-session-store
-pref-window
-folder-tree-modes
-quick-filter-bar
migration
migration-from-tb2
-account
+pref-window
+quick-filter-bar
+search-window
+session-store
--- a/mail/test/mozmill/runtest.py
+++ b/mail/test/mozmill/runtest.py
@@ -117,25 +117,33 @@ class ThunderTestProfile(mozrunner.Thund
# disable address books for undisclosed reasons
'ldap_2.servers.osx.position': 0,
'ldap_2.servers.oe.position': 0,
# disable the first use junk dialog
'mailnews.ui.junk.firstuse': False,
# other unknown voodoo
# -- dummied up local accounts to stop the account wizard
'mail.account.account1.server' : "server1",
- 'mail.account.account2.identities' : "id1",
+ 'mail.account.account2.identities' : "id1,id2",
'mail.account.account2.server' : "server2",
'mail.accountmanager.accounts' : "account1,account2",
'mail.accountmanager.defaultaccount' : "account2",
'mail.accountmanager.localfoldersserver' : "server1",
'mail.identity.id1.fullName' : "Tinderbox",
+ 'mail.identity.id1.htmlSigFormat' : False,
+ 'mail.identity.id1.htmlSigText' : "Tinderbox is soo 90ies",
'mail.identity.id1.smtpServer' : "smtp1",
'mail.identity.id1.useremail' : "tinderbox@invalid.com",
'mail.identity.id1.valid' : True,
+ 'mail.identity.id2.fullName' : "Tinderboxpushlog",
+ 'mail.identity.id2.htmlSigFormat' : True,
+ 'mail.identity.id2.htmlSigText' : "Tinderboxpushlog is the new <b>hotness!</b>",
+ 'mail.identity.id2.smtpServer' : "smtp1",
+ 'mail.identity.id2.useremail' : "tinderboxpushlog@invalid.com",
+ 'mail.identity.id2.valid' : True,
'mail.root.none-rel' : "[ProfD]Mail",
'mail.root.pop3-rel' : "[ProfD]Mail",
'mail.server.server1.directory-rel' : "[ProfD]Mail/Local Folders",
'mail.server.server1.hostname' : "Local Folders",
'mail.server.server1.name' : "Local Folders",
'mail.server.server1.type' : "none",
'mail.server.server1.userName' : "nobody",
'mail.server.server2.check_new_mail' : False,
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -4124,17 +4124,17 @@ nsMsgCompose::ProcessSignature(nsIMsgIde
if (identity && !attachFile)
identity->GetHtmlSigText(prefSigText);
// Now, if they didn't even want to use a signature, we should
// just return nicely.
//
if ((!useSigFile && prefSigText.IsEmpty()) || NS_FAILED(rv))
return NS_OK;
- static const char htmlBreak[] = "<BR>";
+ static const char htmlBreak[] = "<br>";
static const char dashes[] = "-- ";
static const char htmlsigopen[] = "<div class=\"moz-signature\">";
static const char htmlsigclose[] = "</div>"; /* XXX: Due to a bug in
4.x' HTML editor, it will not be able to
break this HTML sig, if quoted (for the user to
interleave a comment). */
static const char _preopen[] = "<pre class=\"moz-signature\" cols=%d>";
char* preopen;
@@ -5326,17 +5326,17 @@ nsMsgCompose::SetIdentity(nsIMsgIdentity
m_editor->EndTransaction();
return rv;
}
//Also, remove the <br> right before the signature.
if (tempNode)
{
tempNode->GetLocalName(tagLocalName);
- if (tagLocalName.EqualsLiteral("BR"))
+ if (tagLocalName.EqualsLiteral("br"))
m_editor->DeleteNode(tempNode);
}
m_editor->EndTransaction();
}
}
}
}
else
@@ -5347,39 +5347,39 @@ nsMsgCompose::SetIdentity(nsIMsgIdentity
do
{
node->GetNodeType(&nodeType);
node->GetLocalName(tagLocalName);
switch (searchState)
{
case 0:
- if (nodeType == nsIDOMNode::ELEMENT_NODE && tagLocalName.EqualsLiteral("BR"))
+ if (nodeType == nsIDOMNode::ELEMENT_NODE && tagLocalName.EqualsLiteral("br"))
searchState = 1;
break;
case 1:
searchState = 0;
if (nodeType == nsIDOMNode::TEXT_NODE)
{
nsString nodeValue;
node->GetNodeValue(nodeValue);
if (nodeValue.EqualsLiteral("-- "))
searchState = 2;
}
else
- if (nodeType == nsIDOMNode::ELEMENT_NODE && tagLocalName.EqualsLiteral("BR"))
+ if (nodeType == nsIDOMNode::ELEMENT_NODE && tagLocalName.EqualsLiteral("br"))
{
searchState = 1;
break;
}
break;
case 2:
- if (nodeType == nsIDOMNode::ELEMENT_NODE && tagLocalName.EqualsLiteral("BR"))
+ if (nodeType == nsIDOMNode::ELEMENT_NODE && tagLocalName.EqualsLiteral("br"))
searchState = 3;
else
searchState = 0;
break;
}
tempNode = node;
} while (searchState != 3 && NS_SUCCEEDED(tempNode->GetPreviousSibling(getter_AddRefs(node))) && node);