Bug 762413 - Fix regression where the user couldn't edit outside of the plaintext signature node under certain circumstances. r=bienvenu.
authorMike Conley <mconley@mozilla.com>
Mon, 11 Jun 2012 13:49:31 -0400
changeset 10411 7447698d6473435b31c7f6185a856b8b65706ad2
parent 10410 71786ff7840c135ecfea43e9d2fe73009f00cb97
child 10412 b7d246591716682452465248862a98aba9eb47dc
push id7875
push usermconley@mozilla.com
push dateMon, 11 Jun 2012 17:50:01 +0000
treeherdercomm-central@7447698d6473 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs762413
Bug 762413 - Fix regression where the user couldn't edit outside of the plaintext signature node under certain circumstances. r=bienvenu.
mail/test/mozmill/composition/test-signature-init.js
mail/test/mozmill/composition/test-signature-updating.js
mailnews/compose/src/nsMsgCompose.cpp
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/test-signature-init.js
@@ -0,0 +1,52 @@
+/* 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 that the compose window initializes with the signature correctly
+ * under various circumstances.
+ */
+
+const MODULE_NAME = 'test-signature-init';
+const RELATIVE_ROOT = '../shared-modules';
+const MODULE_REQUIRES = ['compose-helpers',
+                         'folder-display-helpers'];
+
+const kHtmlPref = 'mail.identity.default.compose_html';
+const kReplyOnTopPref = 'mail.identity.default.reply_on_top';
+const kReplyOnTop = 1;
+const kSigBottomPref = 'mail.identity.default.sig_bottom';
+
+Cu.import('resource://gre/modules/Services.jsm');
+
+function setupModule(module) {
+  collector.getModule('folder-display-helpers').installInto(module);
+  collector.getModule('compose-helpers').installInto(module);
+}
+
+/**
+ * Regression test for bug 762413 - tests that when we're set to reply above,
+ * with the signature below the reply, we initialize the compose window such
+ * that there is a <br> node above the signature. This allows the user to
+ * insert text before the signature.
+ */
+function test_on_reply_above_signature_below_reply() {
+  let origHtml = Services.prefs.getBoolPref(kHtmlPref);
+  let origReplyOnTop = Services.prefs.getIntPref(kReplyOnTopPref);
+  let origSigBottom = Services.prefs.getBoolPref(kSigBottomPref);
+
+  Services.prefs.setBoolPref(kHtmlPref, false);
+  Services.prefs.setIntPref(kReplyOnTopPref, kReplyOnTop);
+  Services.prefs.setBoolPref(kSigBottomPref, false);
+
+  let cw = open_compose_new_mail();
+  let mailBody = get_compose_body(cw);
+
+  let node = mailBody.firstChild;
+  assert_equals(node.localName, 'br',
+                'Expected a BR node to start the compose body.');
+
+  Services.prefs.setBoolPref(kHtmlPref, origHtml);
+  Services.prefs.setIntPref(kReplyOnTopPref, origReplyOnTop);
+  Services.prefs.setBoolPref(kSigBottomPref, origSigBottom);
+}
--- a/mail/test/mozmill/composition/test-signature-updating.js
+++ b/mail/test/mozmill/composition/test-signature-updating.js
@@ -58,20 +58,26 @@ function setupComposeWin(toAddr, subj, b
 function plaintextComposeWindowSwitchSignatures(suppressSigSep) {
   prefBranch.setBoolPref("mail.identity.id1.compose_html", false);
   cwc = composeHelper.open_compose_new_mail();
   prefBranch.setBoolPref("mail.identity.id1.suppress_signature_separator",
                          suppressSigSep);
   prefBranch.setBoolPref("mail.identity.id2.suppress_signature_separator",
                          suppressSigSep);
 
+  let contentFrame = cwc.e("content-frame");
+  let mailBody = contentFrame.contentDocument.body;
+
+  // The first node in the body should be a BR node, which allows the user
+  // to insert text before / outside of the signature.
+  assert_equals(mailBody.firstChild.localName, "br");
+
   setupComposeWin("", "Plaintext compose window", "Body, first line.");
 
-  let contentFrame = cwc.e("content-frame");
-  let node = contentFrame.contentDocument.body.lastChild;
+  let node = mailBody.lastChild;
 
   // The last node is a BR - this allows users to put text after the
   // signature without it being styled like the signature.
   assert_equals(node.localName, "br");
   node = node.previousSibling;
 
   // Now we should have the DIV node that contains the signature, with
   // the class moz-signature.
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -729,16 +729,17 @@ nsMsgCompose::ConvertAndLoadComposeWindo
       }
       else
         m_editor->EndOfDocument();
     }
     else if (htmlEditor)
     {
       if (sigOnTop && !aSignature.IsEmpty())
       {
+        textEditor->InsertLineBreak();
         InsertDivWrappedTextAtSelection(aSignature,
                                         NS_LITERAL_STRING("moz-signature"));
         m_editor->EndOfDocument();
       }
 
       if (!aBuf.IsEmpty())
       {
         if (mailEditor)