Bug 1426328 - remove surrounding spaces when storing values from textboxes in account manager. r=mkmelin
authoraceman <acelists@atlas.sk>
Mon, 19 Nov 2018 15:40:00 +0100
changeset 33835 f93acb5a0e1b922f5a5c76e5aeebfbf208bea88b
parent 33834 e4612d760fefe9e52c9df8edafbf1d56605483c3
child 33836 0e9bf22a6b17f5859686fd464e11f4f8a078fdc7
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersmkmelin
bugs1426328
Bug 1426328 - remove surrounding spaces when storing values from textboxes in account manager. r=mkmelin
mail/test/mozmill/account/test-account-values.js
mailnews/base/prefs/content/AccountManager.js
--- a/mail/test/mozmill/account/test-account-values.js
+++ b/mail/test/mozmill/account/test-account-values.js
@@ -8,27 +8,27 @@
  */
 
 "use strict";
 
 var MODULE_NAME = "test-account-values";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
-                         "account-manager-helpers"];
+                       "account-manager-helpers", "keyboard-helpers"];
 
 var elib = {};
 ChromeUtils.import("chrome://mozmill/content/modules/elementslib.js", elib);
 
 var gPopAccount, gOriginalAccountCount;
 
 function setupModule(module) {
-  collector.getModule("window-helpers").installInto(module);
-  collector.getModule("folder-display-helpers").installInto(module);
-  collector.getModule("account-manager-helpers").installInto(module);
+  for (let lib of MODULE_REQUIRES) {
+    collector.getModule(lib).installInto(module);
+  }
 
   // There may be pre-existing accounts from other tests.
   gOriginalAccountCount = MailServices.accounts.allServers.length;
 
   // Create a POP server
   let popServer = MailServices.accounts
     .createIncomingServer("nobody", "example.invalid", "pop3")
     .QueryInterface(Ci.nsIPop3IncomingServer);
@@ -322,8 +322,50 @@ function subtest_check_invalid_hostname(
     });
 
     // Click OK on the Account settings.
     amc.window.document.documentElement.acceptDialog();
 
     wait_for_modal_dialog("commonDialog");
   }
 }
+
+/**
+ * Bug 1426328.
+ * Check that the AM will trim user added spaces around text values.
+ */
+const badName = "trailing  space ";
+const badEmail = " leading_space@example.com";
+
+function test_trailing_spaces() {
+  open_advanced_settings(function(amc) {
+    subtest_check_trailing_spaces(amc);
+  });
+  assert_equals(gPopAccount.incomingServer.prettyName, badName.trim());
+  assert_equals(gPopAccount.defaultIdentity.email, badEmail.trim());
+}
+
+/**
+ * Check that the AM will trim user added spaces around text values
+ * when storing them into the account.
+ *
+ * @param amc  the account options controller
+ */
+function subtest_check_trailing_spaces(amc)
+{
+  let accountRow = get_account_tree_row(gPopAccount.key, null, amc);
+  click_account_tree_row(amc, accountRow);
+
+  let iframe = amc.window.document.getElementById("contentFrame");
+
+  let accountName = iframe.contentDocument.getElementById("server.prettyName");
+  let defaultAddress = iframe.contentDocument.getElementById("identity.email");
+  delete_all_existing(amc, new elib.Elem(accountName));
+  delete_all_existing(amc, new elib.Elem(defaultAddress));
+  input_value(amc, badName, new elib.Elem(accountName));
+  input_value(amc, badEmail, new elib.Elem(defaultAddress));
+
+  assert_equals(accountName.value, badName);
+  assert_equals(defaultAddress.value, badEmail);
+
+  // We really need to save the new values so click OK on the Account settings.
+  amc.window.document.documentElement.acceptDialog();
+}
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -1351,17 +1351,17 @@ function getFormElementValue(formElement
                           .createInstance(Ci.nsIFile);
 
         localfile.initWithPath(formElement.value);
         return localfile;
       }
       return null;
     }
     if ((type == "textbox") || ("value" in formElement)) {
-      return formElement.value;
+      return formElement.value.trim();
     }
     return null;
   }
   catch (ex) {
     Cu.reportError("getFormElementValue failed, ex=" + ex + "\n");
   }
   return null;
 }