Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RadioButtons: Fix selected radio button not being focused on tab navigation when first element in TAB navigation #3048

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions dev/RadioButtons/InteractionTests/RadioButtonsFocusTestPageElements.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common;
using System;
using System.Numerics;
using Common;

#if USING_TAEF
using WEX.TestExecution;
using WEX.TestExecution.Markup;
using WEX.Logging.Interop;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
#endif

using Microsoft.Windows.Apps.Test.Automation;
using Microsoft.Windows.Apps.Test.Foundation.Controls;
using Microsoft.Windows.Apps.Test.Foundation.Waiters;
using Microsoft.Windows.Apps.Test.Foundation;

namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests
{
class RadioButtonsFocusTestPageElements
{
public UIObject GetTestRadioButtons1()
{
return GetElement(ref TestRadioButtons1, "TestRadioButtons1");
}
private UIObject TestRadioButtons1;

public UIObject GetTestRadioButtons2()
{
return GetElement(ref TestRadioButtons2, "TestRadioButtons2");
}
private UIObject TestRadioButtons2;

public TextBlock GetSelectedIndexTextBlock1()
{
return GetElement(ref SelectedIndexTextBlock1, "SelectedIndexTextBlock1");
}
private TextBlock SelectedIndexTextBlock1;

public TextBlock GetSelectedIndexTextBlock2()
{
return GetElement(ref SelectedIndexTextBlock2, "SelectedIndexTextBlock2");
}
private TextBlock SelectedIndexTextBlock2;

public TextBlock GetFocusedIndexTextBlock1()
{
return GetElement(ref FocusedIndexTextBlock1, "FocusedIndexTextBlock1");
}
private TextBlock FocusedIndexTextBlock1;

public TextBlock GetFocusedIndexTextBlock2()
{
return GetElement(ref FocusedIndexTextBlock2, "FocusedIndexTextBlock2");
}
private TextBlock FocusedIndexTextBlock2;

public CheckBox GetRadioButtons1HasFocusCheckBox()
{
return GetElement(ref RadioButtons1HasFocusCheckBox, "TestRadioButtons1HasFocusCheckBox");
}
private CheckBox RadioButtons1HasFocusCheckBox;

public CheckBox GetRadioButtons2HasFocusCheckBox()
{
return GetElement(ref RadioButtons2HasFocusCheckBox, "TestRadioButtons2HasFocusCheckBox");
}
private CheckBox RadioButtons2HasFocusCheckBox;

public Edit GetIndexToSelectTextBox1()
{
return GetElement(ref IndexToSelectTextBox1, "IndexToSelectTextBox1");
}
private Edit IndexToSelectTextBox1;

public Edit GetIndexToSelectTextBox2()
{
return GetElement(ref IndexToSelectTextBox2, "IndexToSelectTextBox2");
}
private Edit IndexToSelectTextBox2;

public Button GetSelectByIndexButton1()
{
return GetElement(ref SelectByIndexButton, "SelectByIndexButton1");
}
private Button SelectByIndexButton;

public Button GetSelectByIndexButton2()
{
return GetElement(ref SelectByIndexButton2, "SelectByIndexButton2");
}
private Button SelectByIndexButton2;

private T GetElement<T>(ref T element, string elementName) where T : UIObject
{
if (element == null)
{
Log.Comment("Find the " + elementName);
element = FindElement.ByNameOrId<T>(elementName);
Verify.IsNotNull(element);
}
return element;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common;
using System;
using System.Numerics;
Expand Down
125 changes: 93 additions & 32 deletions dev/RadioButtons/InteractionTests/RadioButtonsTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.


Expand Down Expand Up @@ -50,7 +50,7 @@ public void TestCleanup()
[TestProperty("TestSuite", "A")]
public void SelectionTest()
{
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
Expand Down Expand Up @@ -81,7 +81,7 @@ public void SelectByItem()
Log.Warning("This test requires TrySetNewFocusedElement from RS4");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
Expand Down Expand Up @@ -118,29 +118,90 @@ public void FocusComingFromAnotherRepeaterTest()
Log.Warning("This test requires TrySetNewFocusedElement from RS4");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtonsFocus Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
var elements = new RadioButtonsFocusTestPageElements();

// Select items
SelectByIndex(1, false);
SelectByIndex(2, true);

// Verify selection
VerifySelectedIndex(1, false);
VerifySelectedIndex(2, true);

VerifyRadioButtonsHasFocus(true, false);

// Move focus to second RadioButtons control by pressing TAB
KeyboardHelper.PressKey(Key.Tab);

// Verify that
// - the first RadioButtons control no longer has focus and
// - the third radio button of the second RadioButtons control now has focus
VerifyRadioButtonsHasFocus(false, false);
VerifySelectedFocusedIndex(2, true);

// Move focus to the first RadioButtons control by pressing TAB again
KeyboardHelper.PressKey(Key.Tab);

// Verify that the second radio button is still selected and now has focus
VerifySelectedFocusedIndex(1, false);

void SelectByIndex(int index, bool checkRadioButtons2)
{
SetSource(location);
if (checkRadioButtons2)
{
elements.GetIndexToSelectTextBox2().SetValue(index.ToString());
elements.GetSelectByIndexButton2().Click();
}
else
{
elements.GetIndexToSelectTextBox1().SetValue(index.ToString());
elements.GetSelectByIndexButton1().Click();
}
}

TapOnItem(3);
VerifySelectedFocusedIndex(3);
RadioButton item3 = FindElement.ByName<RadioButton>("Radio Button 3");
Verify.IsTrue(item3.IsSelected);
void VerifySelectedIndex(int index, bool checkRadioButtons2)
{
if (checkRadioButtons2)
{
Verify.AreEqual(index, Int32.Parse(elements.GetSelectedIndexTextBlock2().DocumentText), $"RadioButton with index {index} should have been selected.");
}
else
{
Verify.AreEqual(index, Int32.Parse(elements.GetSelectedIndexTextBlock1().DocumentText), $"RadioButton with index {index} should have been selected.");
}
}

KeyboardHelper.PressKey(Key.Tab);
VerifyRadioButtonsHasFocus(false);
Verify.IsTrue(item3.IsSelected);
void VerifyRadioButtonsHasFocus(bool hasFocus, bool checkRadioButtons2)
{
if (checkRadioButtons2)
{
Verify.AreEqual(hasFocus, elements.GetRadioButtons2HasFocusCheckBox().ToggleState == ToggleState.On);
}
else
{
Verify.AreEqual(hasFocus, elements.GetRadioButtons1HasFocusCheckBox().ToggleState == ToggleState.On);
}
}

KeyboardHelper.PressDownModifierKey(ModifierKey.Shift);
KeyboardHelper.PressKey(Key.Tab);
KeyboardHelper.ReleaseModifierKey(ModifierKey.Shift);
VerifySelectedFocusedIndex(3);
Verify.IsTrue(item3.IsSelected);
void VerifyFocusedIndex(int index, bool checkRadioButtons2)
{
if (checkRadioButtons2)
{
Verify.AreEqual(index, Int32.Parse(elements.GetFocusedIndexTextBlock2().DocumentText), $"RadioButton with index {index} should have focus.");
}
else
{
Verify.AreEqual(index, Int32.Parse(elements.GetFocusedIndexTextBlock1().DocumentText), $"RadioButton with index {index} should have focus.");
}

}

void VerifySelectedFocusedIndex(int index, bool checkRadioButtons2)
{
VerifySelectedIndex(index, checkRadioButtons2);
VerifyFocusedIndex(index, checkRadioButtons2);
}
}
}
Expand All @@ -154,7 +215,7 @@ public void BasicKeyboardTest()
Log.Warning("This test requires RS3+ keyboarding behavior");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down Expand Up @@ -198,7 +259,7 @@ public void MultiColumnKeyboardTest()
Log.Warning("This test requires RS3+ keyboarding behavior");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down Expand Up @@ -261,7 +322,7 @@ public void DisabledItemsKeyboardTest()
Log.Warning("This test requires RS3+ keyboarding behavior");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
Expand Down Expand Up @@ -333,7 +394,7 @@ public void DisabledItemsAtTopOfColumnKeyboardTest()
Log.Warning("This test requires RS3+ keyboarding behavior");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
Expand Down Expand Up @@ -396,7 +457,7 @@ public void RS2MultiColumnKeyboardTest()
Log.Warning("This test requires RS2 keyboarding behavior");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down Expand Up @@ -447,7 +508,7 @@ public void RS2MultiColumnKeyboardTest()
[TestProperty("TestSuite", "B")]
public void GamepadCanEscapeAndDoesNotSelectWithFocus()
{
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down Expand Up @@ -506,7 +567,7 @@ public void ControlKeyKeyboardTest()
Log.Warning("This test fails on RS2 because of a repeater bug: #1447");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand All @@ -532,7 +593,7 @@ public void ControlKeyKeyboardTest()
[TestProperty("TestSuite", "A")]
public void ColumnsTest()
{
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down Expand Up @@ -579,7 +640,7 @@ public void ColumnsTest()
[TestProperty("TestSuite", "B")]
public void UIAProperties()
{
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
Expand Down Expand Up @@ -622,7 +683,7 @@ public void UIAProperties()
[TestProperty("TestSuite", "C")]
public void InsertedCheckedRadioButtonGetsSelection()
{
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
SetItemType(RadioButtonsSourceType.RadioButton);
Expand All @@ -645,7 +706,7 @@ public void ScrollViewerSettingSelectionDoesNotMoveFocus()
Log.Warning("This test is disabled on RS2 because it requires RS3+ keyboarding behavior.");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down Expand Up @@ -678,7 +739,7 @@ public void AccessKeys()
Log.Warning("This test requires RS3+ keyboarding behavior");
return;
}
using (var setup = new TestSetupHelper("RadioButtons Tests"))
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
{
elements = new RadioButtonsTestPageElements();
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Import_RootNamespace>RadioButtons_InteractionTests</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonsFocusTestPageElements.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonsTestPageElements.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonsTests.cs" />
</ItemGroup>
Expand Down
Loading