Hotfix for test failures following landing of BenB's account wizard patch. Landing on a CLOSED TREE.
authorJonathan Protzenko <jonathan.protzenko@gmail.com>
Tue, 08 Mar 2011 16:12:49 +0100
changeset 7282 ef7477439a051877edc96613a184757ab43cd8d3
parent 7281 22e2a5cf34abcdd83602d705135666c1863512f2
child 7283 d02ad4f0a6dbc01bd187d32dd0ac991ed25bca35
push idunknown
push userunknown
push dateunknown
Hotfix for test failures following landing of BenB's account wizard patch. Landing on a CLOSED TREE.
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
mail/test/mozmill/shared-modules/test-window-helpers.js
--- a/mail/test/mozmill/account/test-mail-account-setup-wizard.js
+++ b/mail/test/mozmill/account/test-mail-account-setup-wizard.js
@@ -43,17 +43,17 @@ var MODULE_REQUIRES = ["folder-display-h
 
 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);
 
-var wh, awc, account, incoming, outgoing;
+var wh, account, incoming, outgoing;
 
 var user = {
   name: "Yamato Nadeshiko",
   email: "yamato.nadeshiko@example.com",
   password: "abc12345",
   incomingHost: "testin.example.com",
   outgoingHost: "testout.example.com",
 };
@@ -65,20 +65,20 @@ function setupModule(module) {
   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");
+function open_mail_account_setup_wizard(k) {
+  wh.plan_for_modal_dialog("mail:autoconfig", k);
   mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
-  return wh.wait_for_new_window("mail:autoconfig");
+  return wh.wait_for_modal_dialog("mail:autoconfig");
 }
 
 // Remove an account on the Account Manager
 function remove_account(amc) {
   let win = amc.window;
 
   try {
     // Remove the account and incoming server
@@ -102,43 +102,43 @@ function test_mail_account_setup() {
   let pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
   let pref_name = "mailnews.auto_config_url";
   let url = collector.addHttpResource("../account/xml", "autoconfig");
   pref.setCharPref(pref_name, url);
 
   // Force .com MIME-Type to text/xml
   collector.httpd.registerContentType("com", "text/xml");
 
-  awc = open_mail_account_setup_wizard();
+  open_mail_account_setup_wizard(function (awc) {
+    // Input user's account information
+    awc.e("realname").focus();
+    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);
 
-  // Input user's account information
-  awc.e("realname").focus();
-  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();
 
-  // Load the autoconfig file from http://localhost:433**/autoconfig/example.com
-  awc.e("next_button").click();
+    let config = null;
 
-  let config = null;
-
-  // XXX: This should probably use a notification, once we fix bug 561143.
-  awc.waitForEval("subject._currentConfig != null", 8000, 600,
-                  awc.window.gEmailConfigWizard);
-  config = awc.window.gEmailConfigWizard.getConcreteConfig();
+    // XXX: This should probably use a notification, once we fix bug 561143.
+    awc.waitForEval("subject._currentConfig != null", 8000, 600,
+                    awc.window.gEmailConfigWizard);
+    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);
+    // 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
-  pref.clearUserPref(pref_name);
+    // Clean up
+    pref.clearUserPref(pref_name);
+  });
 }
 
 function subtest_verify_account(amc) {
   amc.waitForEval("subject.currentAccount != null", 6000, 600, amc.window);
   account = amc.window.currentAccount;
   let identity = account.defaultIdentity;
   incoming = account.incomingServer;
   outgoing = amc.window.smtpService.getServerByKey(identity.smtpServerKey);
@@ -182,59 +182,58 @@ function subtest_verify_account(amc) {
  * Make sure that we don't re-set the information we get from the config
  * file if the password is incorrect.
  **/
 function test_bad_password_uses_old_settings() {
   // Set the pref to load a local autoconfig file.
   let pref = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
   let pref_name = "mailnews.auto_config_url";
   let url = collector.addHttpResource("../account/xml", "autoconfig");
-  try {
-    pref.setCharPref(pref_name, url);
+  pref.setCharPref(pref_name, url);
 
-    // Force .com MIME-Type to text/xml
-    collector.httpd.registerContentType("com", "text/xml");
-
-    mc.sleep(0);
-    awc = open_mail_account_setup_wizard();
+  // Force .com MIME-Type to text/xml
+  collector.httpd.registerContentType("com", "text/xml");
 
-    // Input user's account information
-    awc.e("realname").focus();
-    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);
+  mc.sleep(0);
+  open_mail_account_setup_wizard(function (awc) {
+    try {
+      // Input user's account information
+      awc.e("realname").focus();
+      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();
+      // Load the autoconfig file from http://localhost:433**/autoconfig/example.com
+      awc.e("next_button").click();
 
-    let config = null;
+      let config = null;
 
-    awc.waitForEval("subject.disabled == false && subject.hidden == false",
-                    8000, 600, awc.e("create_button"));
-    awc.e("create_button").click();
+      awc.waitForEval("subject.disabled == false && subject.hidden == false",
+                      8000, 600, awc.e("create_button"));
+      awc.e("create_button").click();
 
-    awc.waitForEval("subject.disabled == false", 8000, 600,
-                    awc.e("create_button"));
-    awc.e("create_button").click();
-    awc.e("manual-edit_button").click();
+      awc.waitForEval("subject.disabled == false", 8000, 600,
+                      awc.e("create_button"));
+      awc.e("create_button").click();
+      awc.e("manual-edit_button").click();
 
-    // Make sure all the values are the same as in the user object.
-    awc.sleep(1000);
-    assert_equals(awc.e("outgoing_hostname").value, user.outgoingHost,
-                  "Outgoing server changed!");
-    assert_equals(awc.e("incoming_hostname").value, user.incomingHost,
-                  "incoming server changed!");
-  }
-  finally {
-    // Clean up
-    pref.clearUserPref(pref_name);
-    awc.e("cancel_button").click();
-  }
+      // Make sure all the values are the same as in the user object.
+      awc.sleep(1000);
+      assert_equals(awc.e("outgoing_hostname").value, user.outgoingHost,
+                    "Outgoing server changed!");
+      assert_equals(awc.e("incoming_hostname").value, user.incomingHost,
+                    "incoming server changed!");
+    } finally {
+      // Clean up
+      pref.clearUserPref(pref_name);
+      awc.e("cancel_button").click();
+    }
+  });
 }
 
 function test_remember_password() {
   remember_password_test(true);
   remember_password_test(false);
 }
 
 /* Test remember_password checkbox behavior with
@@ -247,39 +246,38 @@ function remember_password_test(aPrefVal
   // save the pref for backup purpose
   let rememberSignons_pref_save =
       pref.getBoolPref("signon.rememberSignons", true);
 
   pref.setBoolPref("signon.rememberSignons", aPrefValue);
 
   // without this, it breaks the test, don't know why
   mc.sleep(0);
-  awc = open_mail_account_setup_wizard();
+  open_mail_account_setup_wizard(function (awc) {
+    try {
+      let password = new elementslib.ID(awc.window.document, "password");
+      let rememberPassword =
+          new elementslib.ID(awc.window.document, "remember_password");
 
-  try {
-    let password = new elementslib.ID(awc.window.document, "password");
-    let rememberPassword =
-        new elementslib.ID(awc.window.document, "remember_password");
+      // type something in the password field
+      awc.e("password").focus();
+      input_value(awc, "testing");
 
-    // type something in the password field
-    awc.e("password").focus();
-    input_value(awc, "testing");
+      awc.assertProperty(rememberPassword, "disabled", !aPrefValue);
+      if (aPrefValue) {
+        awc.assertChecked(rememberPassword);
+      }
+      else {
+        awc.assertNotChecked(rememberPassword);
+      }
 
-    awc.assertProperty(rememberPassword, "disabled", !aPrefValue);
-    if (aPrefValue) {
-      awc.assertChecked(rememberPassword);
+      // empty the password field
+      awc.keypress(password, 'a', {accelKey: true});
+      awc.keypress(password, 'VK_DELETE', {});
+
+      // restore the saved signon.rememberSignons value
+      pref.setBoolPref("signon.rememberSignons", rememberSignons_pref_save);
+    } finally {
+      // close the wizard
+      awc.e("cancel_button").click();
     }
-    else {
-      awc.assertNotChecked(rememberPassword);
-    }
-
-    // empty the password field
-    awc.keypress(password, 'a', {accelKey: true});
-    awc.keypress(password, 'VK_DELETE', {});
-
-    // restore the saved signon.rememberSignons value
-    pref.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
@@ -42,91 +42,81 @@ var MODULE_REQUIRES = ["window-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);
 
-var wh, awc, account, incoming, outgoing;
+var wh, account, incoming, outgoing;
 
 var user = {
   name: "test",
   email: "test@yahoo.com",
   altEmail: "test2@yahoo.com",
 };
 
 function setupModule(module) {
   let fdh = collector.getModule("folder-display-helpers");
   fdh.installInto(module);
   wh = collector.getModule("window-helpers");
   wh.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");
+function open_mail_account_setup_wizard(k) {
+  wh.plan_for_modal_dialog("mail:autoconfig", k);
   mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
-  return wh.wait_for_new_window("mail:autoconfig");
-}
-
-function teardownTest() {
-  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), {});
+  return wh.wait_for_modal_dialog("mail:autoconfig", 30000);
 }
 
 function test_re_test_config() {
-
-  awc = open_mail_account_setup_wizard();
+  open_mail_account_setup_wizard(function (awc) {
+    // Input user's account information
+    awc.e("realname").focus();
+    input_value(awc, user.name);
+    awc.keypress(null, "VK_TAB", {});
+    input_value(awc, user.email);
 
-  // Input user's account information
-  awc.e("realname").focus();
-  input_value(user.name);
-  awc.keypress(null, "VK_TAB", {});
-  input_value(user.email);
+    // Click "continue" button
+    awc.e("next_button").click();
 
-  // Click "continue" button
-  awc.e("next_button").click();
+    // Wait for 'edit' button to be enabled
+    awc.waitForEval("subject.disabled == false && subject.hidden == false",
+                    8000, 600, awc.e("create_button"));
+
+    awc.e("manual-edit_button").click();
 
-  // Wait for 'edit' button to be enabled
-  awc.waitForEval("subject.disabled == false && subject.hidden == false",
-                  8000, 600, awc.e("create_button"));
+    // Click "re-test" button
+    awc.e("half-manual-test_button").click();
 
-  awc.e("manual-edit_button").click();
-  mc.sleep(0);
-
-  // Click "re-test" button
-  awc.e("half-manual-test_button").click();
+    awc.waitForEval("subject.disabled == false", 20000, 600,
+                    awc.e("half-manual-test_button"));
 
-  awc.waitForEval("subject.disabled == false", 20000, 600,
-                  awc.e("half-manual-test_button"));
+    // There used to be a "start over" button (line commented out below). Now just
+    // changing the value of the email field does the trick.
+    awc.e("realname").focus();
+    awc.keypress(null, "VK_TAB", {});
+    input_value(awc, user.altEmail);
+    awc.keypress(null, "VK_TAB", {});
 
-  // There used to be a "start over" button (line commented out below). Now just
-  // changing the value of the email field does the trick. Line left out for
-  // posterity.
-  //   awc.e("back_button").click();
-  awc.e("realname").focus();
-  awc.keypress(null, "VK_TAB", {});
-  input_value(user.altEmail);
-  awc.keypress(null, "VK_TAB", {});
+    // Wait for the "continue" button to be back, which means we're back to the
+    // original state.
+    awc.waitForEval("subject.hidden == false", 20000, 600,
+                    awc.e("next_button"));
 
-  // Wait for the "continue" button to be back, which means we're back to the
-  // original state.
-  awc.waitForEval("subject.hidden == false", 20000, 600,
-                  awc.e("next_button"));
-
-  awc.e("next_button").click();
+    awc.e("next_button").click();
 
-  // Previously, we'd switched to the manual editing state. Now we've started
-  // over, we should make sure the information is presented back in its original
-  // "automatic" mode.
-  assert_true(!awc.e("manual-edit_button").hidden,
-    "We're not back to the original state!");  
-  assert_true(awc.e("advanced-setup_button").hidden,
-    "We're not back to the original state!");  
+    // Previously, we'd switched to the manual editing state. Now we've started
+    // over, we should make sure the information is presented back in its original
+    // "automatic" mode.
+    assert_true(!awc.e("manual-edit_button").hidden,
+      "We're not back to the original state!");
+    assert_true(awc.e("advanced-setup_button").hidden,
+      "We're not back to the original state!");
+
+    wh.close_window(awc);
+  });
 }
 
--- a/mail/test/mozmill/shared-modules/test-account-manager-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-account-manager-helpers.js
@@ -72,17 +72,17 @@ function installInto(module) {
  *
  * @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);
-  if (mc.isLinux)
+  if (mozmill.isLinux)
     aController.click(new elib.Elem(mc.menus.menu_Edit.menu_accountmgr));
   else
     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.
--- a/mail/test/mozmill/shared-modules/test-window-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-window-helpers.js
@@ -271,24 +271,24 @@ var WindowWatcher = {
       throw new Error("Timeout while waiting for modal dialog.\n");
     }
   },
 
   /**
    * Symmetry for planForModalDialog; conceptually provides the waiting.  In
    *  reality, all we do is potentially soak up the event loop a little to
    */
-  waitForModalDialog: function WindowWatcher_waitForModalDialog(aWindowType) {
+  waitForModalDialog: function WindowWatcher_waitForModalDialog(aWindowType, aTimeout) {
     // did the window already come and go?
     if (this.subTestFunc == null)
       return;
     // spin the event loop until we the window has come and gone.
     if (!controller.waitForEval(
            'subject.waitingForOpen == null && subject.monitorizeClose()',
-            WINDOW_OPEN_TIMEOUT_MS, WINDOW_OPEN_CHECK_INTERVAL_MS, this))
+            aTimeout || WINDOW_OPEN_TIMEOUT_MS, WINDOW_OPEN_CHECK_INTERVAL_MS, this))
       throw new Error("Timeout waiting for modal dialog to open.");
     this.waitingForClose = null;
   },
 
   planForWindowClose: function WindowWatcher_planForWindowClose(aXULWindow) {
     let windowType =
       aXULWindow.document.documentElement.getAttribute("windowtype") ||
       aXULWindow.document.documentElement.getAttribute("id");
@@ -495,18 +495,24 @@ function wait_for_new_window(aWindowType
  * @param aSubTestFunction The sub-test function that will be run once the modal
  *     dialog appears and is loaded.  This function should take one argument,
  *     a MozmillController against the modal dialog.
  */
 function plan_for_modal_dialog(aWindowType, aSubTestFunction) {
   WindowWatcher.ensureInited();
   WindowWatcher.planForModalDialog(aWindowType, aSubTestFunction);
 }
-function wait_for_modal_dialog(aWindowType) {
-  WindowWatcher.waitForModalDialog(aWindowType);
+/**
+ * In case the dialog might be stuck for a long time, you can pass an optional
+ *  timeout.
+ *
+ * @param aTimeout Your custom timeout (default is WINDOW_OPEN_TIMEOUT_MS)
+ */
+function wait_for_modal_dialog(aWindowType, aTimeout) {
+  WindowWatcher.waitForModalDialog(aWindowType, aTimeout);
 }
 
 /**
  * Call this just before you trigger the event that will cause the provided
  *  controller's window to disappear.  You then follow this with a call to
  *  |wait_for_window_close| when you want to block on verifying the close.
  *
  * @param aController The MozmillController, potentially returned from a call to