Bug 1420695 - Don't take possibly empty user real name from the OS in the account setup tests. r=jorgk a=jorgk
authoraceman <acelists@atlas.sk>
Thu, 26 Apr 2018 15:38:00 +0200
changeset 31425 37a9e7a7f097d4a2e3bb3c59eda483cf1790e829
parent 31422 809d703185fad41ba2d60afe298e0e79411fb55d
child 31426 700521028a064b3a6ff44c16581b95087542dad0
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersjorgk, jorgk
bugs1420695
Bug 1420695 - Don't take possibly empty user real name from the OS in the account setup tests. r=jorgk a=jorgk
mail/components/accountcreation/content/fetchConfig.js
mail/test/mozmill/account/test-mail-account-setup-wizard.js
mail/test/mozmill/account/test-retest-config.js
mail/test/mozmill/shared-modules/test-account-manager-helpers.js
--- a/mail/components/accountcreation/content/fetchConfig.js
+++ b/mail/components/accountcreation/content/fetchConfig.js
@@ -19,16 +19,20 @@ function fetchConfigFromDisk(domain, suc
   return new TimeoutAbortable(runAsync(function()
   {
     try {
       // <TB installdir>/isp/example.com.xml
       var configLocation = Services.dirsvc.get("CurProcD", Ci.nsIFile);
       configLocation.append("isp");
       configLocation.append(sanitize.hostname(domain) + ".xml");
 
+      if (!configLocation.exists() || !configLocation.isReadable()) {
+        errorCallback("local file not found");
+        return;
+      }
       var contents =
         readURLasUTF8(Services.io.newFileURI(configLocation));
       let domParser = Cc["@mozilla.org/xmlextras/domparser;1"]
                        .createInstance(Ci.nsIDOMParser);
       successCallback(readFromXML(JXON.build(
         domParser.parseFromString(contents, "text/xml"))));
     } catch (e) { errorCallback(e); }
   }));
--- a/mail/test/mozmill/account/test-mail-account-setup-wizard.js
+++ b/mail/test/mozmill/account/test-mail-account-setup-wizard.js
@@ -1,17 +1,17 @@
 /* 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/. */
 
 var MODULE_NAME = "test-mail-account-setup-wizard";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
-                         "account-manager-helpers", "keyboard-helpers" ];
+                       "account-manager-helpers", "keyboard-helpers" ];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource:///modules/mailServices.js");
 
 var elib = {};
 ChromeUtils.import("resource://mozmill/modules/elementslib.js", elib);
 
 var user = {
@@ -21,31 +21,16 @@ var user = {
   incomingHost: "testin.example.com",
   outgoingHost: "testout.example.com",
 };
 
 function setupModule(module) {
   for (let lib of MODULE_REQUIRES) {
     collector.getModule(lib).installInto(module);
   }
-
-  try {
-    let userInfo = Cc["@mozilla.org/userinfo;1"].getService(Ci.nsIUserInfo);
-    user.name = userInfo.fullname;
-  } catch(e) {
-     // nsIUserInfo may not be implemented on all platforms, and name might
-     // not be available even if it is.
-  }
-}
-
-// Select File > New > Mail Account to open the Mail Account Setup Wizard
-function open_mail_account_setup_wizard(k) {
-  plan_for_modal_dialog("mail:autoconfig", k);
-  mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
-  return wait_for_modal_dialog("mail:autoconfig");
 }
 
 // Remove an account in the Account Manager, but not via the UI.
 function remove_account_internal(amc, aAccount, aOutgoing) {
   let win = amc.window;
 
   try {
     // Remove the account and incoming server
@@ -69,36 +54,34 @@ function test_mail_account_setup() {
   let url = collector.addHttpResource("../account/xml", "autoconfig");
   Services.prefs.setCharPref(pref_name, url);
 
   // Force .com MIME-Type to text/xml
   collector.httpd.registerContentType("com", "text/xml");
 
   open_mail_account_setup_wizard(function (awc) {
     // Input user's account information
-    awc.e("realname").focus();
-    if (!awc.e("realname").value) {
-       // Realname is likely already filled, if not, fill it now.
-      input_value(awc, user.name);
+    awc.click(awc.eid("realname"));
+    if (awc.e("realname").value) {
+      // If any realname is already filled, clear it out, we have our own.
+      delete_all_existing(awc, awc.eid("realname"));
     }
+    input_value(awc, user.name);
     awc.keypress(null, "VK_TAB", {});
     input_value(awc, user.email);
     awc.keypress(null, "VK_TAB", {});
     input_value(awc, user.password);
 
     // Load the autoconfig file from http://localhost:433**/autoconfig/example.com
-    awc.e("next_button").click();
-
-    let config = null;
+    awc.click(awc.eid("next_button"));
 
     // XXX: This should probably use a notification, once we fix bug 561143.
     awc.waitFor(() => awc.window.gEmailConfigWizard._currentConfig != null,
                 "Timeout waiting for current config to become non-null",
                 8000, 600);
-    config = awc.window.gEmailConfigWizard.getConcreteConfig();
 
     // Open the advanced settings (Account Manager) to create the account
     // immediately.  We use an invalid email/password so the setup will fail
     // anyway.
     open_advanced_settings_from_account_wizard(subtest_verify_account, awc);
 
     // Clean up
     Services.prefs.clearUserPref(pref_name);
@@ -158,21 +141,22 @@ function test_bad_password_uses_old_sett
 
   // Force .com MIME-Type to text/xml
   collector.httpd.registerContentType("com", "text/xml");
 
   mc.sleep(0);
   open_mail_account_setup_wizard(function (awc) {
     try {
       // Input user's account information
-      awc.e("realname").focus();
-      if (!awc.e("realname").value) {
-         // Realname is likely already filled, if not, fill it now.
-        input_value(awc, user.name);
+      awc.click(awc.eid("realname"));
+      if (awc.e("realname").value) {
+        // If any realname is already filled, clear it out, we have our own.
+        delete_all_existing(awc, awc.eid("realname"));
       }
+      input_value(awc, user.name);
       awc.keypress(null, "VK_TAB", {});
       input_value(awc, user.email);
       awc.keypress(null, "VK_TAB", {});
       input_value(awc, user.password);
 
       // Load the autoconfig file from http://localhost:433**/autoconfig/example.com
       awc.e("next_button").click();
 
@@ -235,18 +219,17 @@ function remember_password_test(aPrefVal
       if (aPrefValue) {
         awc.assertChecked(rememberPassword);
       }
       else {
         awc.assertNotChecked(rememberPassword);
       }
 
       // empty the password field
-      awc.keypress(password, 'a', {accelKey: true});
-      awc.keypress(password, 'VK_DELETE', {});
+      delete_all_existing(awc, password);
 
       // restore the saved signon.rememberSignons value
       Services.prefs.setBoolPref("signon.rememberSignons", rememberSignons_pref_save);
     } finally {
       // close the wizard
       awc.e("cancel_button").click();
     }
   });
--- a/mail/test/mozmill/account/test-retest-config.js
+++ b/mail/test/mozmill/account/test-retest-config.js
@@ -1,16 +1,17 @@
 /* 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/. */
 
 var MODULE_NAME = "test-retest-config";
 
 var RELATIVE_ROOT = "../shared-modules";
-var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers", "keyboard-helpers"];
+var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
+                       "keyboard-helpers", "account-manager-helpers"];
 
 var elib = {};
 ChromeUtils.import("resource://mozmill/modules/elementslib.js", elib);
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var user = {
   name: "test",
   email: "test@momo.invalid",
@@ -28,30 +29,27 @@ function setupModule(module) {
   collector.httpd.registerContentType("invalid", "text/xml");
 }
 
 function tearDownModule(module) {
   Services.prefs.clearUserPref("mailnews.auto_config_url");
   Services.prefs.clearUserPref("mail.wizard.logging.dump");
 }
 
-// Select File > New > Mail Account to open the Mail Account Setup Wizard
-function open_mail_account_setup_wizard(k) {
-  plan_for_modal_dialog("mail:autoconfig", k);
-  mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
-  return wait_for_modal_dialog("mail:autoconfig", 30000);
-}
-
 function test_re_test_config() {
   // Opening multiple windows in the same run seems to require letting the stack
   // unwind before opening the next one, so do that here.
   mc.sleep(0);
   open_mail_account_setup_wizard(function (awc) {
     // Input user's account information
-    awc.e("realname").focus();
+    awc.click(awc.eid("realname"));
+    if (awc.e("realname").value) {
+      // If any realname is already filled, clear it out, we have our own.
+      delete_all_existing(awc, awc.eid("realname"));
+    }
     input_value(awc, user.name);
     awc.keypress(null, "VK_TAB", {});
     input_value(awc, user.email);
 
     // Click "continue" button
     awc.e("next_button").click();
 
     // Wait for 'edit' button to be enabled
--- a/mail/test/mozmill/shared-modules/test-account-manager-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-account-manager-helpers.js
@@ -23,16 +23,17 @@ function setupModule() {
 
 function installInto(module) {
   setupModule();
 
   // Now copy helper functions
   module.open_advanced_settings = open_advanced_settings;
   module.open_advanced_settings_from_account_wizard =
     open_advanced_settings_from_account_wizard;
+  module.open_mail_account_setup_wizard = open_mail_account_setup_wizard;
   module.click_account_tree_row = click_account_tree_row;
   module.get_account_tree_row = get_account_tree_row;
   module.remove_account = remove_account;
 }
 
 /**
  * Opens the Account Manager.
  *
@@ -55,16 +56,28 @@ function open_advanced_settings(aCallbac
 function open_advanced_settings_from_account_wizard(aCallback, aController) {
   wh.plan_for_modal_dialog("mailnews:accountmanager", aCallback);
   aController.e("manual-edit_button").click();
   aController.e("advanced-setup_button").click();
   return wh.wait_for_modal_dialog("mailnews:accountmanager");
 }
 
 /**
+ * Use File > New > Mail Account to open the Mail Account Setup Wizard.
+ *
+ * @param aCallback  Function to run once the dialog is open. The function
+ *                   gets the new window controller passed as first argument.
+ */
+function open_mail_account_setup_wizard(aCallback) {
+  wh.plan_for_modal_dialog("mail:autoconfig", aCallback);
+  mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
+  return wh.wait_for_modal_dialog("mail:autoconfig", 30000);
+}
+
+/**
  * Click a row in the account settings tree
  *
  * @param controller the Mozmill controller for the account settings dialog
  * @param rowIndex the row to click
  */
 function click_account_tree_row(controller, rowIndex) {
   utils.waitFor(() => controller.window.currentAccount != null,
                 "Timeout waiting for currentAccount to become non-null");