Bug 399446 - Do not offer "Newsgroup:" in recipient dropdown if we are not sending from a newsgroup account. r=mkmelin, ui-r=bwinton
authoraceman <acelists@atlas.sk>
Mon, 10 Jun 2013 08:13:08 -0400
changeset 15714 16e20df57d08f38c89a93571c59eb3f410834239
parent 15713 d7d40b3d21d14ba337a00649fd3b1ede1544da6d
child 15715 1e4628bab2822914044f5f983619c66bcbe9c9a7
push id942
push userbugzilla@standard8.plus.com
push dateMon, 05 Aug 2013 19:15:38 +0000
treeherdercomm-beta@0e1a1c4a9f0c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, bwinton
bugs399446
Bug 399446 - Do not offer "Newsgroup:" in recipient dropdown if we are not sending from a newsgroup account. r=mkmelin, ui-r=bwinton
mail/components/compose/content/MsgComposeCommands.js
mail/test/mozmill/composition/test-address-widgets.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -4116,28 +4116,55 @@ function DetermineConvertibility()
         return nsIMsgCompConvertible.Plain;
 
     try {
         return gMsgCompose.bodyConvertible();
     } catch(ex) {}
     return nsIMsgCompConvertible.No;
 }
 
+/**
+ * Hides addressing options (To, CC, Bcc, Newsgroup, Followup-To, etc.)
+ * that are not relevant for the account type used for sending.
+ *
+ * @param aAccountKey  Key of the account that is currently selected
+ *                     as the sending account.
+ */
+function hideIrrelevantAddressingOptions(aAccountKey)
+{
+  let hideNews = MailServices.accounts.getAccount(aAccountKey)
+                                      .incomingServer.type != "nntp";
+  // If we are not posting from a News (NNTP) account
+  // hide the Newsgroup recipient type in all the menulists.
+  let addrWidget = document.getElementById("addressingWidget");
+  // Only really touch the News related items we know about.
+  let newsTypes = addrWidget
+    .querySelectorAll('menuitem[value="addr_newsgroups"], menuitem[value="addr_followup"]');
+  // Collapsing the menuitem only prevents it getting chosen, it does not
+  // affect the menulist widget display when Newsgroup is already selected.
+  for (let item of newsTypes) {
+    item.collapsed = hideNews;
+  }
+}
+
 function LoadIdentity(startup)
 {
     var identityElement = document.getElementById("msgIdentity");
     var prevIdentity = gCurrentIdentity;
 
     if (identityElement) {
         var idKey = identityElement.value;
         gCurrentIdentity = MailServices.accounts.getIdentity(idKey);
 
-        // set the  account name on the menu list value.
-        if (identityElement.selectedItem)
-          identityElement.setAttribute('accountname', identityElement.selectedItem.getAttribute('accountname'));
+        // Set the account key value on the menu list.
+        if (identityElement.selectedItem) {
+          let accountKey = identityElement.selectedItem.getAttribute("accountkey");
+          identityElement.setAttribute("accountkey", accountKey);
+          hideIrrelevantAddressingOptions(accountKey);
+        }
 
         let maxRecipients = awGetMaxRecipients();
         for (let i = 1; i <= maxRecipients; i++)
           awGetInputElement(i).setAttribute("autocompletesearchparam", idKey);
 
         if (!startup && prevIdentity && idKey != prevIdentity.key)
         {
           var prefstring = "mail.identity." + prevIdentity.key;
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/test-address-widgets.js
@@ -0,0 +1,126 @@
+/* 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 proper enabling of addressing widgets.
+ */
+
+const MODULE_NAME = "test-address-widgets";
+
+const RELATIVE_ROOT = "../shared-modules";
+const MODULE_REQUIRES = ["folder-display-helpers", "compose-helpers",
+                         "window-helpers"];
+
+var cwc = null; // compose window controller
+var accountPOP3 = null;
+var accountNNTP = null;
+
+function setupModule(module) {
+  for (let lib of MODULE_REQUIRES) {
+    collector.getModule(lib).installInto(module);
+  }
+
+  // Ensure we're in the tinderbox account as that has the right identities set
+  // up for this test.
+  let server = MailServices.accounts.FindServer("tinderbox", "tinderbox", "pop3");
+  accountPOP3 = MailServices.accounts.FindAccountForServer(server);
+
+  // There may be pre-existing accounts from other tests.
+  originalAccountCount = MailServices.accounts.allServers.length;
+
+  // Create a NNTP server
+  let nntpServer = MailServices.accounts
+    .createIncomingServer(null, "example.nntp.invalid", "nntp")
+    .QueryInterface(Components.interfaces.nsINntpIncomingServer);
+
+  identity = MailServices.accounts.createIdentity();
+  identity.email = "tinderbox2@example.invalid";
+
+  accountNNTP = MailServices.accounts.createAccount();
+  accountNNTP.incomingServer = nntpServer;
+  accountNNTP.addIdentity(identity);
+  // Now there should be 1 more account.
+  assert_equals(MailServices.accounts.allServers.length, originalAccountCount + 1);
+};
+
+function teardownModule(module) {
+  // Remove our test accounts to leave the profile clean.
+  MailServices.accounts.removeAccount(accountNNTP);
+  // There should be only the original accounts left.
+  assert_equals(MailServices.accounts.allServers.length, originalAccountCount);
+}
+
+/**
+ * Check if the address type items are in the wished state.
+ *
+ * @param aItemsEnabled  List of item values that should be enabled (uncollapsed).
+ */
+function check_address_types_state(aItemsEnabled) {
+  let addr_types = cwc.e("addressingWidget").querySelectorAll("menuitem[value]");
+  for (let item of addr_types)
+    assert_true(item.collapsed == (aItemsEnabled.indexOf(item.getAttribute("value")) == -1));
+
+  // Even if the currently selected type is collaped,
+  // the containing menulist should never be collapsed.
+  let addr_lists = cwc.e("addressingWidget").querySelectorAll("menulist");
+  for (let list in addr_lists) {
+    assert_false(list.collapsed);
+    assert_false(list.disabled);
+  }
+}
+
+/**
+ * For a POP3 account, no News related address types should be enabled.
+ */
+function allowed_mail_types() {
+  check_address_types_state(["addr_to", "addr_cc", "addr_reply", "addr_bcc"]);
+}
+
+/**
+ * On a NNTP account, all address types should be enabled.
+ */
+function allowed_nntp_types() {
+  check_address_types_state(["addr_to", "addr_cc", "addr_reply", "addr_bcc",
+                             "addr_newsgroups", "addr_followup"]);
+}
+
+/**
+ * Bug 399446
+ * Test that the allowed address types depend on the account type
+ * we are sending from.
+ */
+function test_address_types() {
+  // Open compose window on each account individually.
+  be_in_folder(accountPOP3.incomingServer.rootFolder);
+  cwc = open_compose_new_mail();
+  allowed_mail_types();
+  close_compose_window(cwc);
+
+  be_in_folder(accountNNTP.incomingServer.rootFolder);
+  cwc = open_compose_new_mail();
+  allowed_nntp_types();
+  close_compose_window(cwc);
+
+  // Now try the same accounts but choosing them in the From dropdown
+  // inside compose window.
+  be_in_folder(accountPOP3.incomingServer.rootFolder);
+  cwc = open_compose_new_mail();
+  allowed_mail_types();
+
+  let NNTPidentity = accountNNTP.defaultIdentity.key;
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { value: NNTPidentity } ]);
+  allowed_nntp_types();
+
+  // In a News account, choose "Newsgroup:" as the address type.
+  cwc.click_menus_in_sequence(cwc.e("addressCol1#1").menupopup,
+                              [ { value: "addr_newsgroups" } ]);
+  allowed_nntp_types();
+
+  // And switch back to the POP3 account.
+  let POP3identity = accountPOP3.defaultIdentity.key;
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { value: POP3identity } ]);
+  allowed_mail_types();
+
+  close_compose_window(cwc);
+}