From 508f638b3a434b571af6708e77c7f04d20fb7060 Mon Sep 17 00:00:00 2001 From: Mihaela Stoica Date: Thu, 8 Dec 2016 14:47:58 +0000 Subject: [PATCH] CA-216752: Not all wizards progress through to the next page by pressing the Enter key - Added a new method in XenTabPage which the derived classes can implement to select a default control after the page is loaded. - Added a new wizard test that runs through the wizard by pressing the Enter key and checks if it has landed on the right page. Signed-off-by: Mihaela Stoica --- XenAdmin/Controls/XenTabPage.cs | 5 ++ XenAdmin/SettingsPanels/GpuEditPage.cs | 6 +++ .../SelectMultipleVMDestinationPage.cs | 5 ++ .../HAWizard_Pages/AssignPriorities.cs | 5 ++ .../Wizards/ImportWizard/ImageVMConfigPage.cs | 5 ++ .../Wizards/ImportWizard/ImportEulaPage.cs | 5 ++ XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs | 5 ++ XenAdmin/Wizards/NewVMWizard/Page_Finish.cs | 5 +- .../Wizards/NewVMWizard/Page_HomeServer.cs | 4 ++ XenAdmin/Wizards/NewVMWizard/Page_Name.cs | 4 ++ .../Wizards/NewVMWizard/Page_Networking.cs | 4 ++ XenAdmin/Wizards/NewVMWizard/Page_Storage.cs | 4 ++ .../PatchingWizard_PrecheckPage.cs | 5 ++ .../PatchingWizard_SelectServers.cs | 5 ++ .../PatchingWizard_UploadPage.cs | 5 ++ .../RollingUpgradeWizardSelectPool.cs | 5 ++ XenAdmin/Wizards/XenWizardBase.cs | 5 ++ XenAdminTests/WizardTests/WizardTest.cs | 51 +++++++++++++++++-- 18 files changed, 127 insertions(+), 6 deletions(-) diff --git a/XenAdmin/Controls/XenTabPage.cs b/XenAdmin/Controls/XenTabPage.cs index 2553d30de..0a755151d 100644 --- a/XenAdmin/Controls/XenTabPage.cs +++ b/XenAdmin/Controls/XenTabPage.cs @@ -191,6 +191,11 @@ namespace XenAdmin.Controls /// Check whether this step needs to be disabled. Not always overriden in derived classes /// public virtual void CheckPageDisabled() { } + + /// + /// Select a control on the page. Not always overriden in derived classes + /// + public virtual void SelectDefaultControl() { } protected void OnPageUpdated() { diff --git a/XenAdmin/SettingsPanels/GpuEditPage.cs b/XenAdmin/SettingsPanels/GpuEditPage.cs index ab7b650bb..f3958b03f 100644 --- a/XenAdmin/SettingsPanels/GpuEditPage.cs +++ b/XenAdmin/SettingsPanels/GpuEditPage.cs @@ -233,6 +233,12 @@ namespace XenAdmin.SettingsPanels } } + public override void SelectDefaultControl() + { + if (comboBoxGpus.CanSelect) + comboBoxGpus.Select(); + } + #endregion private void PopulateComboBox() diff --git a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs index a24354c9e..afa59f6f9 100644 --- a/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs +++ b/XenAdmin/Wizards/GenericPages/SelectMultipleVMDestinationPage.cs @@ -173,6 +173,11 @@ namespace XenAdmin.Wizards.GenericPages restoreGridHomeServerSelection = (direction == PageLoadedDirection.Back); } + public override void SelectDefaultControl() + { + m_comboBoxConnection.Select(); + } + public override bool EnableNext() { return m_buttonNextEnabled; diff --git a/XenAdmin/Wizards/HAWizard_Pages/AssignPriorities.cs b/XenAdmin/Wizards/HAWizard_Pages/AssignPriorities.cs index 96b69ad40..f5553d589 100644 --- a/XenAdmin/Wizards/HAWizard_Pages/AssignPriorities.cs +++ b/XenAdmin/Wizards/HAWizard_Pages/AssignPriorities.cs @@ -686,6 +686,11 @@ namespace XenAdmin.Wizards.HAWizard_Pages StartNtolUpdate(); } + public override void SelectDefaultControl() + { + dataGridViewVms.Select(); + } + public override void PageLeave(PageLoadedDirection direction, ref bool cancel) { StopNtolUpdate(); diff --git a/XenAdmin/Wizards/ImportWizard/ImageVMConfigPage.cs b/XenAdmin/Wizards/ImportWizard/ImageVMConfigPage.cs index 41be9d2be..188b9065f 100644 --- a/XenAdmin/Wizards/ImportWizard/ImageVMConfigPage.cs +++ b/XenAdmin/Wizards/ImportWizard/ImageVMConfigPage.cs @@ -83,6 +83,11 @@ namespace XenAdmin.Wizards.ImportWizard m_upDownAddSpace.Value = m_upDownAddSpace.Minimum; } + public override void SelectDefaultControl() + { + m_textBoxVMName.Select(); + } + public override bool EnableNext() { return m_buttonNextEnabled; diff --git a/XenAdmin/Wizards/ImportWizard/ImportEulaPage.cs b/XenAdmin/Wizards/ImportWizard/ImportEulaPage.cs index d418d711b..754f0640d 100644 --- a/XenAdmin/Wizards/ImportWizard/ImportEulaPage.cs +++ b/XenAdmin/Wizards/ImportWizard/ImportEulaPage.cs @@ -129,6 +129,11 @@ namespace XenAdmin.Wizards.ImportWizard } } + public override void SelectDefaultControl() + { + m_tabControlEULA.Select(); + } + public override bool EnableNext() { return m_buttonNextEnabled; diff --git a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs index 9f78788ec..58a58d29f 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_CpuMem.cs @@ -126,6 +126,11 @@ namespace XenAdmin.Wizards.NewVMWizard initialising = false; } + public override void SelectDefaultControl() + { + comboBoxVCPUs.Select(); + } + private void InitialiseVcpuControls() { labelVCPUs.Text = isVcpuHotplugSupported diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs b/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs index b3dd557fe..2c5cad6de 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_Finish.cs @@ -84,7 +84,10 @@ namespace XenAdmin.Wizards.NewVMWizard var entries = SummaryRetreiver.Invoke(); foreach (KeyValuePair pair in entries) SummaryGridView.Rows.Add(pair.Key, pair.Value); - + } + + public override void SelectDefaultControl() + { AutoStartCheckBox.Select(); } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs b/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs index b8797282e..fe8d01540 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs @@ -114,6 +114,10 @@ namespace XenAdmin.Wizards.NewVMWizard affinityPicker1.SetAffinity(Connection, Affinity, CdAffinity ?? Template.GetStorageHost(false)); } + } + + public override void SelectDefaultControl() + { affinityPicker1.Select(); } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Name.cs b/XenAdmin/Wizards/NewVMWizard/Page_Name.cs index 5a7fb8272..8f3a2520c 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Name.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_Name.cs @@ -82,6 +82,10 @@ namespace XenAdmin.Wizards.NewVMWizard Template = SelectedTemplate; NameTextBox.Text = Helpers.DefaultVMName(Helpers.GetName(Template), Connection); + } + + public override void SelectDefaultControl() + { NameTextBox.Select(); } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Networking.cs b/XenAdmin/Wizards/NewVMWizard/Page_Networking.cs index f4e47e879..3a2b1380e 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Networking.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_Networking.cs @@ -98,6 +98,10 @@ namespace XenAdmin.Wizards.NewVMWizard NetworksGridView.Rows[0].Selected = true; UpdateEnablement(); + } + + public override void SelectDefaultControl() + { NetworksGridView.Select(); } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_Storage.cs b/XenAdmin/Wizards/NewVMWizard/Page_Storage.cs index 405510209..eae8d5df5 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_Storage.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_Storage.cs @@ -93,6 +93,10 @@ namespace XenAdmin.Wizards.NewVMWizard LoadDisks(); UpdateEnablement(); UpdateCloneCheckboxEnablement(true); + } + + public override void SelectDefaultControl() + { DisksGridView.Select(); } diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs index 8171630aa..9e0e0979c 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_PrecheckPage.cs @@ -149,6 +149,11 @@ namespace XenAdmin.Wizards.PatchingWizard } } + public override void SelectDefaultControl() + { + dataGridView1.Select(); + } + protected void RefreshRechecks() { buttonResolveAll.Enabled = buttonReCheckProblems.Enabled = checkBoxViewPrecheckFailuresOnly.Enabled = false; diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs index 2ac4a0c91..2683626fb 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs @@ -165,6 +165,11 @@ namespace XenAdmin.Wizards.PatchingWizard } } + public override void SelectDefaultControl() + { + dataGridViewHosts.Select(); + } + public bool IsInAutomaticMode { set; get; } private void EnabledRow(Host host, UpdateType type, int index) diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_UploadPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_UploadPage.cs index e59dea8c4..62d4de980 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_UploadPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_UploadPage.cs @@ -96,6 +96,11 @@ namespace XenAdmin.Wizards.PatchingWizard } } + public override void SelectDefaultControl() + { + flickerFreeListBox1.Select(); + } + private void DownloadFile() { string patchUri = ((XenServerPatchAlert)SelectedUpdateAlert).Patch.PatchUrl; diff --git a/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardSelectPool.cs b/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardSelectPool.cs index a1d2b2a33..924a4c27f 100644 --- a/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardSelectPool.cs +++ b/XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardSelectPool.cs @@ -189,6 +189,11 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard BuildServerList(); } + public override void SelectDefaultControl() + { + dataGridView1.Select(); + } + private void BuildServerList() { IList masters = SelectedMasters; diff --git a/XenAdmin/Wizards/XenWizardBase.cs b/XenAdmin/Wizards/XenWizardBase.cs index a073ee8e0..9eba48b11 100644 --- a/XenAdmin/Wizards/XenWizardBase.cs +++ b/XenAdmin/Wizards/XenWizardBase.cs @@ -166,6 +166,7 @@ namespace XenAdmin.Wizards xenTabControlBody.SelectedTab = wizardProgress.CurrentStepTabPage; wizardProgress.CurrentStepTabPage.PageLoaded(e.IsForwardsTransition ? PageLoadedDirection.Forward : PageLoadedDirection.Back); + wizardProgress.CurrentStepTabPage.SelectDefaultControl(); UpdateWizard(); if (wizardProgress.IsLastStep) @@ -325,7 +326,11 @@ namespace XenAdmin.Wizards private void XenWizardBase_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) + { + if (buttonNext.CanSelect) + buttonNext.Select(); buttonNext.PerformClick(); + } } [Browsable(false)] diff --git a/XenAdminTests/WizardTests/WizardTest.cs b/XenAdminTests/WizardTests/WizardTest.cs index 44615779a..62bf19f6e 100644 --- a/XenAdminTests/WizardTests/WizardTest.cs +++ b/XenAdminTests/WizardTests/WizardTest.cs @@ -30,15 +30,11 @@ */ using System; -using System.Collections.Generic; -using System.Text; using System.Threading; using System.Windows.Forms; using NUnit.Framework; -using XenAdmin; -using XenAdmin.Controls; using XenAdmin.Wizards; -using XenAdmin.Commands; +using XenAdmin.Core; namespace XenAdminTests.WizardTests { @@ -53,6 +49,8 @@ namespace XenAdminTests.WizardTests protected Button btnPrevious; protected Button btnCancel; + private static uint WM_KEYDOWN = 0x100; + protected WizardTest(string[] pageNames, bool canFinish, bool doFinish) { this.pageNames = pageNames; @@ -60,6 +58,49 @@ namespace XenAdminTests.WizardTests this.doFinish = doFinish; } + + [Test] + [Timeout(100 * 1000)] + public void RunWizardKeyboardTests() + { + RunBefore(); + + wizard = MW(NewWizard); + MW(wizard.Show); + + btnNext = TestUtils.GetButton(wizard, "buttonNext"); + btnPrevious = TestUtils.GetButton(wizard, "buttonPrevious"); + btnCancel = TestUtils.GetButton(wizard, "buttonCancel"); + + // Test that the Enter key takes us forward through the wizard + for (int i = 0; i < pageNames.Length; ++i) + { + bool lastPage = (i == pageNames.Length - 1); + + // Any specific setup or testing for this page defined in derived class + TestPage(pageNames[i]); + if (!lastPage) + { + // send th eenter key to the wizard window + MW(() => + { + Win32.PostMessage(wizard.Handle, WM_KEYDOWN, new IntPtr((int)Keys.Enter), IntPtr.Zero); + }); + // wait for any progress dialog to close + while (wizard.Visible && !wizard.CanFocus) + Thread.Sleep(1000); + // check if the wizard progressed to the next page + Assert.AreEqual(pageNames[i + 1], CurrentPageName(wizard), "Enter key button didn't get from page: " + pageNames[i] + " to page: " + pageNames[i + 1]); + } + else + { + MW(btnCancel.PerformClick); + } + } + + MW(() => wizard.Dispose()); + } + [Test] [Timeout(100 * 1000)] public void RunWizardTests()