Bug 933101 - Properly enable Send button if recipients are drag'n'dropped into the address widget or filled in by switching identities. r=mkmelin
authoraceman <acelists@atlas.sk>
Tue, 19 Nov 2013 09:36:11 -0500
changeset 16911 0b04606f23dc9d11f1283b2f8cc88233fcb0a2b5
parent 16910 dda8c42d23a8ad0b4de949083b0faf11be92e5cf
child 16912 e75d5882e8b25df8b1be28414c6d43cb3e6f5ae7
push id1074
push userbugzilla@standard8.plus.com
push dateMon, 03 Feb 2014 22:47:23 +0000
treeherdercomm-beta@6b791b5369ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs933101
Bug 933101 - Properly enable Send button if recipients are drag'n'dropped into the address widget or filled in by switching identities. r=mkmelin
mail/components/compose/content/MsgComposeCommands.js
mail/components/compose/content/addressingWidgetOverlay.js
mail/components/compose/content/messengercompose.xul
mail/test/mozmill/composition/test-send-button.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -2991,20 +2991,29 @@ function addRecipientsToIgnoreList(aAddr
 
 function onAddressColCommand(aAddressWidgetId)
 {
   gContentChanged = true;
   awSetAutoComplete(aAddressWidgetId.slice(aAddressWidgetId.lastIndexOf('#') + 1));
   updateSendCommands(true);
 }
 
-function onRecipientsInput()
+/**
+ * Called if the list of recipients changed in any way.
+ *
+ * @param aAutomatic  Set to true if the change of recipients was invoked
+ *                    programatically and should not be considered a change
+ *                    of message content.
+ */
+function onRecipientsChanged(aAutomatic)
 {
-  gContentChanged = true;
-  setupAutocomplete();
+  if (!aAutomatic) {
+    gContentChanged = true;
+    setupAutocomplete();
+  }
   updateSendCommands(true);
 }
 
 function InitLanguageMenu()
 {
   var languageMenuList = document.getElementById('languageMenuList');
   if (!languageMenuList)
     return;
@@ -4459,17 +4468,16 @@ function toggleAddressPicker()
     elt.removeAttribute("checked");
   }
 }
 
 // public method called by the address picker sidebar
 function AddRecipient(recipientType, address)
 {
   awAddRecipient(recipientType, address);
-  onRecipientsInput();
 }
 
 function loadHTMLMsgPrefs()
 {
   var fontFace;
   var fontSize;
   var textColor;
   var bgColor;
--- a/mail/components/compose/content/addressingWidgetOverlay.js
+++ b/mail/components/compose/content/addressingWidgetOverlay.js
@@ -251,16 +251,18 @@ function awSetInputAndPopupValue(inputEl
   inputElem.value = inputValue;
 
   popupElem.selectedItem = popupElem.childNodes[0].childNodes[awGetSelectItemIndex(popupValue)];
 
   if (rowNumber >= 0)
     awSetInputAndPopupId(inputElem, popupElem, rowNumber);
 
   _awSetAutoComplete(popupElem, inputElem);
+
+  onRecipientsChanged(true);
 }
 
 function _awSetInputAndPopup(inputValue, popupValue, parentNode, templateNode)
 {
     top.MAX_RECIPIENTS++;
 
     var newNode = templateNode.cloneNode(true);
     parentNode.appendChild(newNode); // we need to insert the new node before we set the value of the select element!
--- a/mail/components/compose/content/messengercompose.xul
+++ b/mail/components/compose/content/messengercompose.xul
@@ -877,18 +877,18 @@
                          type="autocomplete" flex="1"
                          autocompletesearch="mydomain addrbook ldap news"
                          autocompletesearchparam="{}"
                          timeout="300" maxrows="4"
                          completedefaultindex="true" forcecomplete="true"
                          minresultsforpopup="2" ignoreblurwhilesearching="true"
                          ontextentered="awRecipientTextCommand(eventParam, this)"
                          onerrorcommand="awRecipientErrorCommand(eventParam, this)"
-                         onchange="onRecipientsInput();"
-                         oninput="onRecipientsInput();"
+                         onchange="onRecipientsChanged();"
+                         oninput="onRecipientsChanged();"
                          onkeypress="awRecipientKeyPress(event, this)"
                          onkeydown="awRecipientKeyDown(event, this)"
                          disableonsend="true">
                   <image class="person-icon" onclick="this.parentNode.select();"/>
                 </textbox>
               </listcell>
             </listitem>
           </listbox>
--- a/mail/test/mozmill/composition/test-send-button.js
+++ b/mail/test/mozmill/composition/test-send-button.js
@@ -81,32 +81,68 @@ function test_send_enabled_manual_addres
 /**
  * Bug 431217
  * Test that the Send buttons are properly enabled if an addressee is prefilled
  * automatically via account prefs.
  */
 function test_send_enabled_prefilled_address() {
   // Set the prefs to prefill a default CC address when Compose is opened.
   let identity = account.defaultIdentity;
-  let identityBranch = Services.prefs.getBranch("mail.identity." + identity.key + ".");
-  identityBranch.setBoolPref("doCc", true);
-  identityBranch.setCharPref("doCcList", "Auto recipient");
+  identity.doCc = true;
+  identity.doCcList = "Auto@recipient.invalid";
+
   // In that case the recipient is input, enabled Send.
   let cwc = open_compose_new_mail(); // compose controller
   check_send_commands_state(cwc, true);
 
   // Press backspace to remove the recipient. No other valid one is there,
-  // disable Send.
+  // Send should become disabled.
   cwc.e("addressCol2#1").select();
   cwc.keypress(null, "VK_BACK_SPACE", {});
   check_send_commands_state(cwc, false);
 
   close_compose_window(cwc);
-  identityBranch.clearUserPref("doCc");
-  identityBranch.clearUserPref("doCcList");
+  identity.doCcList = "";
+  identity.doCc = false;
+}
+
+/**
+ * Bug 933101
+ * Similar to test_send_enabled_prefilled_address but switched between an identity
+ * that has a CC list and one that doesn't directly in the compose window.
+ */
+function test_send_enabled_prefilled_address_from_identity() {
+  // The first identity will have an automatic CC enabled.
+  let identityWithCC = account.defaultIdentity;
+  identityWithCC.doCc = true;
+  identityWithCC.doCcList = "Auto@recipient.invalid";
+
+  // CC is prefilled, Send enabled.
+  let cwc = open_compose_new_mail();
+  check_send_commands_state(cwc, true);
+
+  let identityPicker = cwc.e("msgIdentity");
+  assert_equals(identityPicker.selectedIndex, 0);
+
+  // Switch to the second identity that has no CC. Send should be disabled.
+  assert_true(account.identities.length >= 2);
+  let identityWithoutCC = account.identities.queryElementAt(1, Ci.nsIMsgIdentity);
+  assert_false(identityWithoutCC.doCc);
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"),
+                              [ { value: identityWithoutCC.key } ]);
+  check_send_commands_state(cwc, false);
+
+  // Check the first identity again.
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"),
+                              [ { value: identityWithCC.key } ]);
+  check_send_commands_state(cwc, true);
+
+  close_compose_window(cwc);
+  identityWithCC.doCcList = "";
+  identityWithCC.doCc = false;
 }
 
 /**
  * Bug 863231
  * Test that the Send buttons are properly enabled if an addressee is populated
  * via the Contacts sidebar.
  */
 function test_send_enabled_address_contacts_sidebar() {