Unit test for Bug 580764 - Setting pop/imap port to the default value for the security setting not selected appears to get reset.; r=bwinton
authorMark Banner <bugzilla@standard8.plus.com>
Fri, 10 Sep 2010 11:50:51 +0100
changeset 6349 bcb4ed3a3eb96dab70953066bb3aba499f9770fb
parent 6348 3747f1d60f0a690d2298bd17b964db6360092a7e
child 6350 703a416ff5c3425f59006e36645e017938dcb77b
push id4897
push userbugzilla@standard8.plus.com
push dateFri, 10 Sep 2010 10:51:40 +0000
treeherdercomm-central@b9feb6dbd2a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwinton
bugs580764
Unit test for Bug 580764 - Setting pop/imap port to the default value for the security setting not selected appears to get reset.; r=bwinton
mail/test/mozmill/account/test-account-port-setting.js
mail/test/mozmill/account/test-mail-account-setup-wizard.js
mail/test/mozmill/shared-modules/test-account-manager-helpers.js
mail/test/mozmill/shared-modules/test-keyboard-helpers.js
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/account/test-account-port-setting.js
@@ -0,0 +1,143 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * The Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mark Banner <bugzilla@standard8.plus.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var MODULE_NAME = "test-account-port-setting";
+
+var RELATIVE_ROOT = "../shared-modules";
+var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
+                       "account-manager-helpers", "keyboard-helpers" ];
+
+var mozmill = {};
+Components.utils.import("resource://mozmill/modules/mozmill.js", mozmill);
+var controller = {};
+Components.utils.import("resource://mozmill/modules/controller.js", controller);
+var elib = {};
+Components.utils.import("resource://mozmill/modules/elementslib.js", elib);
+
+// This test expects the first account to be a POP account with port number 110
+// and no security
+const PORT_NUMBERS_TO_TEST =
+  [
+    "110", // The original port number. We don't input this though.
+    "456", // Random port number.
+    "995", // The SSL port number.
+    "110"  // Back to the original.
+  ];
+
+var gTestNumber;
+
+/**
+ * Click the specified tree cell
+ *
+ * @param {MozMillController} controller
+ *        MozMillController of the browser window to operate on
+ * @param {tree} tree
+ *        Tree to operate on
+ * @param {number } rowIndex
+ *        Index of the row
+ * @param {number} columnIndex
+ *        Index of the column
+ * @param {object} eventDetails
+ *        Details about the mouse event
+ */
+function clickTreeCell(controller, tree, rowIndex, columnIndex, eventDetails)
+{
+  var selection = tree.view.selection;
+  selection.select(rowIndex);
+  tree.treeBoxObject.ensureRowIsVisible(rowIndex);
+
+  // get cell coordinates
+  var x = {}, y = {}, width = {}, height = {};
+  var column = tree.columns[columnIndex];
+  tree.treeBoxObject.getCoordsForCellItem(rowIndex, column, "text",
+                                           x, y, width, height);
+
+  controller.sleep(0);
+  EventUtils.synthesizeMouse(tree.body, x.value + 4, y.value + 4,
+                             eventDetails, tree.ownerDocument.defaultView);
+  controller.sleep(0);
+}
+
+function subtest_check_set_port_number(amc, aDontSet) {
+  amc.waitForEval("subject.currentAccount != null", 6000, 600, amc.window);
+
+  clickTreeCell(amc, amc.window.document.getElementById("accounttree"),
+                1, 0, {});
+
+  amc.waitForEval("subject.pendingAccount == null", 6000, 600, amc.window);
+
+  let iframe = amc.window.document.getElementById("contentFrame");
+  let portElem = iframe.contentDocument.getElementById("server.port");
+  portElem.focus();
+
+  if (portElem.value != PORT_NUMBERS_TO_TEST[gTestNumber - 1])
+    throw new Error("Port Value is not " +
+                    PORT_NUMBERS_TO_TEST[gTestNumber - 1] +
+                    " as expected, it is: " + portElem.value);
+
+  if (!aDontSet) {
+    delete_existing(amc, new elib.Elem(portElem), 3);
+    input_value(amc, PORT_NUMBERS_TO_TEST[gTestNumber]);
+
+    mc.sleep(0);
+  }
+
+  amc.window.document.getElementById("accountManager").acceptDialog();
+}
+
+function subtest_check_port_number(amc) {
+  subtest_check_set_port_number(amc, true);
+}
+
+function setupModule(module) {
+  let wh = collector.getModule("window-helpers");
+  wh.installInto(module);
+  let fdh = collector.getModule("folder-display-helpers");
+  fdh.installInto(module);
+  let amh = collector.getModule("account-manager-helpers");
+  amh.installInto(module);
+  let kh = collector.getModule("keyboard-helpers");
+  kh.installInto(module);
+}
+
+function test_account_port_setting() {
+  for (gTestNumber = 1; gTestNumber < PORT_NUMBERS_TO_TEST.length; ++gTestNumber) {
+    open_advanced_settings(subtest_check_set_port_number);
+  }
+
+  open_advanced_settings(subtest_check_port_number);
+}
--- a/mail/test/mozmill/account/test-mail-account-setup-wizard.js
+++ b/mail/test/mozmill/account/test-mail-account-setup-wizard.js
@@ -33,17 +33,18 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 var MODULE_NAME = "test-mail-account-setup-wizard";
 
 var RELATIVE_ROOT = "../shared-modules";
-var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers"];
+var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
+                       "account-manager-helpers", "keyboard-helpers" ];
 
 var mozmill = {};
 Components.utils.import("resource://mozmill/modules/mozmill.js", mozmill);
 var controller = {};
 Components.utils.import("resource://mozmill/modules/controller.js", controller);
 var elib = {};
 Components.utils.import("resource://mozmill/modules/elementslib.js", elib);
 
@@ -55,44 +56,31 @@ var user = {
   password: "abc12345",
   incomingHost: "testin.example.com",
   outgoingHost: "testout.example.com",
 };
 
 function setupModule(module) {
   wh = collector.getModule("window-helpers");
   wh.installInto(module);
-  fdh = collector.getModule("folder-display-helpers");
+  var fdh = collector.getModule("folder-display-helpers");
   fdh.installInto(module);
+  var amh = collector.getModule("account-manager-helpers");
+  amh.installInto(module);
+  var kh = collector.getModule("keyboard-helpers");
+  kh.installInto(module);
 }
 
 // Select File > New > Mail Account to open the Mail Account Setup Wizard
 function open_mail_account_setup_wizard() {
   wh.plan_for_new_window("mail:autoconfig");
   mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
   return wh.wait_for_new_window("mail:autoconfig");
 }
 
-// Open the Account Manager from the Mail Account Setup Wizard
-function open_advanced_settings() {
-  wh.plan_for_modal_dialog("mailnews:accountmanager", subtest_verify_account);
-  awc.e("advanced_settings").click();
-  return wh.wait_for_modal_dialog("mailnews:accountmanager");
-}
-
-function close_mail_account_setup_wizard() {
-  wh.close_window(awc);
-}
-
-// Emulate manual input
-function input_value(str) {
-  for (let i = 0; i < str.length; i++)
-    awc.keypress(null, str.charAt(i), {});
-}
-
 // Remove an account on the Account Manager
 function remove_account(amc) {
   let win = amc.window;
 
   try {
     // Remove the account and incoming server
     let serverId = incoming.serverURI;
     Cc["@mozilla.org/messenger/account-manager;1"]
@@ -118,36 +106,36 @@ function test_mail_account_setup() {
 
   // Force .com MIME-Type to text/xml
   collector.httpd.registerContentType("com", "text/xml");
 
   awc = open_mail_account_setup_wizard();
 
   // Input user's account information
   awc.e("realname").focus();
-  input_value(user.name);
+  input_value(awc, user.name);
   awc.keypress(null, "VK_TAB", {});
-  input_value(user.email);
+  input_value(awc, user.email);
   awc.keypress(null, "VK_TAB", {});
-  input_value(user.password);
+  input_value(awc, user.password);
 
   // Load the autoconfig file from http://localhost:433**/autoconfig/example.com
   awc.e("next_button").click();
 
   let config = null;
 
   // XXX: This should probably use a notification, once we fix bug 561143.
   awc.waitForEval("subject._currentConfigFilledIn != null", 8000, 600,
                   awc.window.gEmailConfigWizard);
   config = awc.window.gEmailConfigWizard._currentConfigFilledIn;
 
   // 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();
+  open_advanced_settings_from_account_wizard(subtest_verify_account, awc);
 
   // Clean up
   pref.clearUserPref(pref_name);
 }
 
 function subtest_verify_account(amc) {
   amc.waitForEval("subject.currentAccount != null", 6000, 600, amc.window);
   account = amc.window.currentAccount;
@@ -205,21 +193,21 @@ function test_bad_password_uses_old_sett
     // Force .com MIME-Type to text/xml
    collector.httpd.registerContentType("com", "text/xml");
 
     mc.sleep(0);
     awc = open_mail_account_setup_wizard();
 
     // Input user's account information
     awc.e("realname").focus();
-    input_value(user.name);
+    input_value(awc, user.name);
     awc.keypress(null, "VK_TAB", {});
-    input_value(user.email);
+    input_value(awc, user.email);
     awc.keypress(null, "VK_TAB", {});
-    input_value(user.password);
+    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.waitForEval("subject.disabled == false", 8000, 600,
                     awc.e("create_button"));
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/shared-modules/test-account-manager-helpers.js
@@ -0,0 +1,94 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Thunderbird Mail Client.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mark Banner <bugzilla@standard8.plus.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var Ci = Components.interfaces;
+var Cc = Components.classes;
+var Cu = Components.utils;
+
+var elib = {};
+Cu.import('resource://mozmill/modules/elementslib.js', elib);
+var mozmill = {};
+Cu.import('resource://mozmill/modules/mozmill.js', mozmill);
+
+const MODULE_NAME = 'account-manager-helpers';
+const RELATIVE_ROOT = '../shared-modules';
+
+// we need this for the main controller
+const MODULE_REQUIRES = ['folder-display-helpers', 'window-helpers'];
+
+var wh, fdh, mc;
+
+function setupModule() {
+  fdh = collector.getModule('folder-display-helpers');
+  mc = fdh.mc;
+  wh = collector.getModule('window-helpers');
+}
+
+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;
+}
+
+/**
+ * Opens the Account Manager.
+ *
+ * @param callback Callback for the modal dialog that is opened.
+ */
+function open_advanced_settings(aCallback, aController) {
+  if (aController === undefined)
+    aController = mc;
+
+  wh.plan_for_modal_dialog("mailnews:accountmanager", aCallback);
+  aController.click(new elib.Elem(mc.menus.tasksMenu.menu_accountmgr));
+  return wh.wait_for_modal_dialog("mailnews:accountmanager");
+}
+
+/**
+ * Opens the Account Manager from the mail account setup wizard.
+ *
+ * @param callback Callback for the modal dialog that is opened.
+ */
+function open_advanced_settings_from_account_wizard(aCallback, aController) {
+  wh.plan_for_modal_dialog("mailnews:accountmanager", aCallback);
+  aController.e("advanced_settings").click();
+  return wh.wait_for_modal_dialog("mailnews:accountmanager");
+}
+
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/shared-modules/test-keyboard-helpers.js
@@ -0,0 +1,92 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ *   Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Thunderbird Mail Client.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Mark Banner <bugzilla@standard8.plus.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var Ci = Components.interfaces;
+var Cc = Components.classes;
+var Cu = Components.utils;
+
+var elib = {};
+Cu.import('resource://mozmill/modules/elementslib.js', elib);
+var mozmill = {};
+Cu.import('resource://mozmill/modules/mozmill.js', mozmill);
+
+const MODULE_NAME = 'keyboard-helpers';
+const RELATIVE_ROOT = '../shared-modules';
+
+// we need this for the main controller
+const MODULE_REQUIRES = ['folder-display-helpers', 'window-helpers',
+                         'keyboard-helpers'];
+
+var wh, fdh, mc;
+
+function setupModule() {
+  fdh = collector.getModule('folder-display-helpers');
+  mc = fdh.mc;
+  wh = collector.getModule('window-helpers');
+}
+
+function installInto(module) {
+  setupModule();
+
+  // Now copy helper functions
+  module.input_value = input_value;
+  module.delete_existing = delete_existing;
+}
+
+/**
+ * Emulates manual input
+ *
+ * @param aController The window controller to input keypresses into
+ * @param aStr        The string to input into the control element
+ */
+function input_value(aController, aStr) {
+  for (let i = 0; i < aStr.length; i++)
+    aController.keypress(null, aStr.charAt(i), {});
+}
+
+/**
+ * Emulates deleting strings via the keyboard
+ *
+ * @param aController The window controller to input keypresses into
+ * @param aElement    The element in which to delete characters
+ * @param aNumber     The number of times to press the delete key.
+ */
+function delete_existing(aController, aElement, aNumber) {
+  for (let i = 0; i < aNumber; ++i)
+    aController.keypress(aElement, 'VK_BACK_SPACE', {});
+}
+