Bug 758626 - If Account Provisioner tab is opened, focus it instead of opening a new dialog. r+ui-r=bwinton, a=Standard8.
authorMike Conley <mconley@mozilla.com>
Mon, 28 May 2012 17:22:18 -0400
changeset 11353 0aa1e03d18936572f9d864ce5e9d3ceda43d71e6
parent 11352 ff96b286f8772382b4d5ededd19b4ab2d9ed9007
child 11354 7f4b2ca13eba52e89777007b8327d19279ae085c
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs758626
Bug 758626 - If Account Provisioner tab is opened, focus it instead of opening a new dialog. r+ui-r=bwinton, a=Standard8.
mail/test/mozmill/newmailaccount/test-newmailaccount.js
mailnews/base/prefs/content/accountUtils.js
--- a/mail/test/mozmill/newmailaccount/test-newmailaccount.js
+++ b/mail/test/mozmill/newmailaccount/test-newmailaccount.js
@@ -1145,8 +1145,45 @@ function test_search_button_disabled_if_
 
 function subtest_search_button_disabled_if_no_lang_support(aController) {
   wait_for_provider_list_loaded(aController);
 
   // The search button should be disabled.
   wait_for_element_enabled(aController, aController.e("searchSubmit"), false);
   close_dialog_immediately(aController);
 }
+
+/**
+ * Test that if we try to open the Account Provisioner dialog when an
+ * Account Provisioner tab is opened, that we focus the tab instead of opening
+ * the dialog.
+ */
+function test_get_new_account_focuses_existing_ap_tab() {
+  get_to_order_form("green@example.com");
+  let apTab = mc.tabmail.getTabInfoForCurrentOrFirstModeInstance(
+    mc.tabmail.tabModes["accountProvisionerTab"]);
+
+  // Switch back to the inbox tab.
+  mc.tabmail.switchToTab(0);
+
+  // Try to re-open the provisioner dialog
+  open_provisioner_window();
+
+  // If we got here, that means that we weren't blocked by a dialog
+  // being opened, which is good.
+  assert_selected_tab(apTab);
+
+  // Now open up the wizard, and try opening the Account Provisioner from
+  // there.
+  plan_for_new_window("mail:autoconfig");
+
+  // Open the wizard...
+  mc.click(new elib.Elem(mc.menus.menu_File.menu_New.newMailAccountMenuItem));
+  let wizard = wait_for_new_window("mail:autoconfig");
+
+  // Click on the "Get a new Account" button in the wizard.
+  wizard.click(wizard.eid("provisioner_button"));
+
+  // If we got here, that means that we weren't blocked by a dialog
+  // being opened, which is what we wanted..
+  assert_selected_tab(apTab);
+  mc.tabmail.closeTab(apTab);
+}
--- a/mailnews/base/prefs/content/accountUtils.js
+++ b/mailnews/base/prefs/content/accountUtils.js
@@ -362,16 +362,39 @@ function NewMailAccountProvisioner(aMsgW
   if (!aMsgWindow)
     aMsgWindow = Components.classes["@mozilla.org/messenger/services/session;1"]
                    .getService(Components.interfaces.nsIMsgMailSession)
                    .topmostMsgWindow;
   args.msgWindow = aMsgWindow;
 
   let mail3Pane = Services.wm.getMostRecentWindow("mail:3pane");
 
+  // If we couldn't find a 3pane, bail out.
+  if (!mail3Pane) {
+    Components.utils.reportError("Could not find a 3pane to connect to.");
+    return;
+  }
+
+  let tabmail = mail3Pane.document.getElementById("tabmail");
+
+  if (!tabmail) {
+    Components.utils.reportError("Could not find a tabmail in the 3pane!");
+    return;
+  }
+
+  // If there's already an accountProvisionerTab open, just focus it instead
+  // of opening a new dialog.
+  let apTab = tabmail.getTabInfoForCurrentOrFirstModeInstance(
+    tabmail.tabModes["accountProvisionerTab"]);
+
+  if (apTab) {
+    tabmail.switchToTab(apTab);
+    return;
+  }
+
   // XXX make sure these are all defined in all contexts... to be on the safe
   // side, just get a mail:3pane and borrow the functions from it?
   if (!args.NewMailAccount)
     args.NewMailAccount = NewMailAccount;
 
   if (!args.msgNewMailAccount)
     args.msgNewMailAccount = msgNewMailAccount;