Skip to content

Commit 3ff3437

Browse files
authored
RadioButtons: Fix selected radio button not being focused on tab navigation when first element in TAB navigation (#3048)
* Fix focus issue. * Modified interaction test and created special focus test page.
1 parent c37a961 commit 3ff3437

11 files changed

Lines changed: 548 additions & 53 deletions
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
5+
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common;
6+
using System;
7+
using System.Numerics;
8+
using Common;
9+
10+
#if USING_TAEF
11+
using WEX.TestExecution;
12+
using WEX.TestExecution.Markup;
13+
using WEX.Logging.Interop;
14+
#else
15+
using Microsoft.VisualStudio.TestTools.UnitTesting;
16+
using Microsoft.VisualStudio.TestTools.UnitTesting.Logging;
17+
#endif
18+
19+
using Microsoft.Windows.Apps.Test.Automation;
20+
using Microsoft.Windows.Apps.Test.Foundation.Controls;
21+
using Microsoft.Windows.Apps.Test.Foundation.Waiters;
22+
using Microsoft.Windows.Apps.Test.Foundation;
23+
24+
namespace Windows.UI.Xaml.Tests.MUXControls.InteractionTests
25+
{
26+
class RadioButtonsFocusTestPageElements
27+
{
28+
public UIObject GetTestRadioButtons1()
29+
{
30+
return GetElement(ref TestRadioButtons1, "TestRadioButtons1");
31+
}
32+
private UIObject TestRadioButtons1;
33+
34+
public UIObject GetTestRadioButtons2()
35+
{
36+
return GetElement(ref TestRadioButtons2, "TestRadioButtons2");
37+
}
38+
private UIObject TestRadioButtons2;
39+
40+
public TextBlock GetSelectedIndexTextBlock1()
41+
{
42+
return GetElement(ref SelectedIndexTextBlock1, "SelectedIndexTextBlock1");
43+
}
44+
private TextBlock SelectedIndexTextBlock1;
45+
46+
public TextBlock GetSelectedIndexTextBlock2()
47+
{
48+
return GetElement(ref SelectedIndexTextBlock2, "SelectedIndexTextBlock2");
49+
}
50+
private TextBlock SelectedIndexTextBlock2;
51+
52+
public TextBlock GetFocusedIndexTextBlock1()
53+
{
54+
return GetElement(ref FocusedIndexTextBlock1, "FocusedIndexTextBlock1");
55+
}
56+
private TextBlock FocusedIndexTextBlock1;
57+
58+
public TextBlock GetFocusedIndexTextBlock2()
59+
{
60+
return GetElement(ref FocusedIndexTextBlock2, "FocusedIndexTextBlock2");
61+
}
62+
private TextBlock FocusedIndexTextBlock2;
63+
64+
public CheckBox GetRadioButtons1HasFocusCheckBox()
65+
{
66+
return GetElement(ref RadioButtons1HasFocusCheckBox, "TestRadioButtons1HasFocusCheckBox");
67+
}
68+
private CheckBox RadioButtons1HasFocusCheckBox;
69+
70+
public CheckBox GetRadioButtons2HasFocusCheckBox()
71+
{
72+
return GetElement(ref RadioButtons2HasFocusCheckBox, "TestRadioButtons2HasFocusCheckBox");
73+
}
74+
private CheckBox RadioButtons2HasFocusCheckBox;
75+
76+
public Edit GetIndexToSelectTextBox1()
77+
{
78+
return GetElement(ref IndexToSelectTextBox1, "IndexToSelectTextBox1");
79+
}
80+
private Edit IndexToSelectTextBox1;
81+
82+
public Edit GetIndexToSelectTextBox2()
83+
{
84+
return GetElement(ref IndexToSelectTextBox2, "IndexToSelectTextBox2");
85+
}
86+
private Edit IndexToSelectTextBox2;
87+
88+
public Button GetSelectByIndexButton1()
89+
{
90+
return GetElement(ref SelectByIndexButton, "SelectByIndexButton1");
91+
}
92+
private Button SelectByIndexButton;
93+
94+
public Button GetSelectByIndexButton2()
95+
{
96+
return GetElement(ref SelectByIndexButton2, "SelectByIndexButton2");
97+
}
98+
private Button SelectByIndexButton2;
99+
100+
private T GetElement<T>(ref T element, string elementName) where T : UIObject
101+
{
102+
if (element == null)
103+
{
104+
Log.Comment("Find the " + elementName);
105+
element = FindElement.ByNameOrId<T>(elementName);
106+
Verify.IsNotNull(element);
107+
}
108+
return element;
109+
}
110+
}
111+
}

dev/RadioButtons/InteractionTests/RadioButtonsTestPageElements.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;
25
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common;
36
using System;
47
using System.Numerics;

dev/RadioButtons/InteractionTests/RadioButtonsTests.cs

Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44

@@ -50,7 +50,7 @@ public void TestCleanup()
5050
[TestProperty("TestSuite", "A")]
5151
public void SelectionTest()
5252
{
53-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
53+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
5454
{
5555
elements = new RadioButtonsTestPageElements();
5656
SetItemType(RadioButtonsSourceType.RadioButton);
@@ -81,7 +81,7 @@ public void SelectByItem()
8181
Log.Warning("This test requires TrySetNewFocusedElement from RS4");
8282
return;
8383
}
84-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
84+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
8585
{
8686
elements = new RadioButtonsTestPageElements();
8787
SetItemType(RadioButtonsSourceType.RadioButton);
@@ -118,29 +118,90 @@ public void FocusComingFromAnotherRepeaterTest()
118118
Log.Warning("This test requires TrySetNewFocusedElement from RS4");
119119
return;
120120
}
121-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
121+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtonsFocus Test" }))
122122
{
123-
elements = new RadioButtonsTestPageElements();
124-
SetItemType(RadioButtonsSourceType.RadioButton);
125-
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
123+
var elements = new RadioButtonsFocusTestPageElements();
124+
125+
// Select items
126+
SelectByIndex(1, false);
127+
SelectByIndex(2, true);
128+
129+
// Verify selection
130+
VerifySelectedIndex(1, false);
131+
VerifySelectedIndex(2, true);
132+
133+
VerifyRadioButtonsHasFocus(true, false);
134+
135+
// Move focus to second RadioButtons control by pressing TAB
136+
KeyboardHelper.PressKey(Key.Tab);
137+
138+
// Verify that
139+
// - the first RadioButtons control no longer has focus and
140+
// - the third radio button of the second RadioButtons control now has focus
141+
VerifyRadioButtonsHasFocus(false, false);
142+
VerifySelectedFocusedIndex(2, true);
143+
144+
// Move focus to the first RadioButtons control by pressing TAB again
145+
KeyboardHelper.PressKey(Key.Tab);
146+
147+
// Verify that the second radio button is still selected and now has focus
148+
VerifySelectedFocusedIndex(1, false);
149+
150+
void SelectByIndex(int index, bool checkRadioButtons2)
126151
{
127-
SetSource(location);
152+
if (checkRadioButtons2)
153+
{
154+
elements.GetIndexToSelectTextBox2().SetValue(index.ToString());
155+
elements.GetSelectByIndexButton2().Click();
156+
}
157+
else
158+
{
159+
elements.GetIndexToSelectTextBox1().SetValue(index.ToString());
160+
elements.GetSelectByIndexButton1().Click();
161+
}
162+
}
128163

129-
TapOnItem(3);
130-
VerifySelectedFocusedIndex(3);
131-
RadioButton item3 = FindElement.ByName<RadioButton>("Radio Button 3");
132-
Verify.IsTrue(item3.IsSelected);
164+
void VerifySelectedIndex(int index, bool checkRadioButtons2)
165+
{
166+
if (checkRadioButtons2)
167+
{
168+
Verify.AreEqual(index, Int32.Parse(elements.GetSelectedIndexTextBlock2().DocumentText), $"RadioButton with index {index} should have been selected.");
169+
}
170+
else
171+
{
172+
Verify.AreEqual(index, Int32.Parse(elements.GetSelectedIndexTextBlock1().DocumentText), $"RadioButton with index {index} should have been selected.");
173+
}
174+
}
133175

134-
KeyboardHelper.PressKey(Key.Tab);
135-
VerifyRadioButtonsHasFocus(false);
136-
Verify.IsTrue(item3.IsSelected);
176+
void VerifyRadioButtonsHasFocus(bool hasFocus, bool checkRadioButtons2)
177+
{
178+
if (checkRadioButtons2)
179+
{
180+
Verify.AreEqual(hasFocus, elements.GetRadioButtons2HasFocusCheckBox().ToggleState == ToggleState.On);
181+
}
182+
else
183+
{
184+
Verify.AreEqual(hasFocus, elements.GetRadioButtons1HasFocusCheckBox().ToggleState == ToggleState.On);
185+
}
186+
}
137187

138-
KeyboardHelper.PressDownModifierKey(ModifierKey.Shift);
139-
KeyboardHelper.PressKey(Key.Tab);
140-
KeyboardHelper.ReleaseModifierKey(ModifierKey.Shift);
141-
VerifySelectedFocusedIndex(3);
142-
Verify.IsTrue(item3.IsSelected);
188+
void VerifyFocusedIndex(int index, bool checkRadioButtons2)
189+
{
190+
if (checkRadioButtons2)
191+
{
192+
Verify.AreEqual(index, Int32.Parse(elements.GetFocusedIndexTextBlock2().DocumentText), $"RadioButton with index {index} should have focus.");
193+
}
194+
else
195+
{
196+
Verify.AreEqual(index, Int32.Parse(elements.GetFocusedIndexTextBlock1().DocumentText), $"RadioButton with index {index} should have focus.");
197+
}
198+
199+
}
143200

201+
void VerifySelectedFocusedIndex(int index, bool checkRadioButtons2)
202+
{
203+
VerifySelectedIndex(index, checkRadioButtons2);
204+
VerifyFocusedIndex(index, checkRadioButtons2);
144205
}
145206
}
146207
}
@@ -154,7 +215,7 @@ public void BasicKeyboardTest()
154215
Log.Warning("This test requires RS3+ keyboarding behavior");
155216
return;
156217
}
157-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
218+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
158219
{
159220
elements = new RadioButtonsTestPageElements();
160221
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -198,7 +259,7 @@ public void MultiColumnKeyboardTest()
198259
Log.Warning("This test requires RS3+ keyboarding behavior");
199260
return;
200261
}
201-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
262+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
202263
{
203264
elements = new RadioButtonsTestPageElements();
204265
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -261,7 +322,7 @@ public void DisabledItemsKeyboardTest()
261322
Log.Warning("This test requires RS3+ keyboarding behavior");
262323
return;
263324
}
264-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
325+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
265326
{
266327
elements = new RadioButtonsTestPageElements();
267328
SetItemType(RadioButtonsSourceType.RadioButton);
@@ -333,7 +394,7 @@ public void DisabledItemsAtTopOfColumnKeyboardTest()
333394
Log.Warning("This test requires RS3+ keyboarding behavior");
334395
return;
335396
}
336-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
397+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
337398
{
338399
elements = new RadioButtonsTestPageElements();
339400
SetItemType(RadioButtonsSourceType.RadioButton);
@@ -396,7 +457,7 @@ public void RS2MultiColumnKeyboardTest()
396457
Log.Warning("This test requires RS2 keyboarding behavior");
397458
return;
398459
}
399-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
460+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
400461
{
401462
elements = new RadioButtonsTestPageElements();
402463
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -447,7 +508,7 @@ public void RS2MultiColumnKeyboardTest()
447508
[TestProperty("TestSuite", "B")]
448509
public void GamepadCanEscapeAndDoesNotSelectWithFocus()
449510
{
450-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
511+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
451512
{
452513
elements = new RadioButtonsTestPageElements();
453514
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -506,7 +567,7 @@ public void ControlKeyKeyboardTest()
506567
Log.Warning("This test fails on RS2 because of a repeater bug: #1447");
507568
return;
508569
}
509-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
570+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
510571
{
511572
elements = new RadioButtonsTestPageElements();
512573
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -532,7 +593,7 @@ public void ControlKeyKeyboardTest()
532593
[TestProperty("TestSuite", "A")]
533594
public void ColumnsTest()
534595
{
535-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
596+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
536597
{
537598
elements = new RadioButtonsTestPageElements();
538599
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -579,7 +640,7 @@ public void ColumnsTest()
579640
[TestProperty("TestSuite", "B")]
580641
public void UIAProperties()
581642
{
582-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
643+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
583644
{
584645
elements = new RadioButtonsTestPageElements();
585646
SetItemType(RadioButtonsSourceType.RadioButton);
@@ -622,7 +683,7 @@ public void UIAProperties()
622683
[TestProperty("TestSuite", "C")]
623684
public void InsertedCheckedRadioButtonGetsSelection()
624685
{
625-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
686+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
626687
{
627688
elements = new RadioButtonsTestPageElements();
628689
SetItemType(RadioButtonsSourceType.RadioButton);
@@ -645,7 +706,7 @@ public void ScrollViewerSettingSelectionDoesNotMoveFocus()
645706
Log.Warning("This test is disabled on RS2 because it requires RS3+ keyboarding behavior.");
646707
return;
647708
}
648-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
709+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
649710
{
650711
elements = new RadioButtonsTestPageElements();
651712
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
@@ -678,7 +739,7 @@ public void AccessKeys()
678739
Log.Warning("This test requires RS3+ keyboarding behavior");
679740
return;
680741
}
681-
using (var setup = new TestSetupHelper("RadioButtons Tests"))
742+
using (var setup = new TestSetupHelper(new[] { "RadioButtons Tests", "RadioButtons Test" }))
682743
{
683744
elements = new RadioButtonsTestPageElements();
684745
foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))

dev/RadioButtons/InteractionTests/RadioButtons_InteractionTests.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Import_RootNamespace>RadioButtons_InteractionTests</Import_RootNamespace>
1111
</PropertyGroup>
1212
<ItemGroup>
13+
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonsFocusTestPageElements.cs" />
1314
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonsTestPageElements.cs" />
1415
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonsTests.cs" />
1516
</ItemGroup>

0 commit comments

Comments
 (0)