-
Notifications
You must be signed in to change notification settings - Fork 941
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Servicing 3.1] Fixing regression in Control.AccessibleName property (#…
- Loading branch information
1 parent
96f8bef
commit cf28cab
Showing
12 changed files
with
320 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Common/tests/InternalUtilitiesForTests/src/ReflectionHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace System | ||
{ | ||
public static class ReflectionHelper | ||
{ | ||
public static IEnumerable<Type> GetPublicNotAbstractClasses<T>() | ||
{ | ||
var types = typeof(T).Assembly.GetTypes().Where(type => IsPublicNonAbstract<T>(type)); | ||
foreach (var type in types) | ||
{ | ||
if (type.GetConstructor( | ||
bindingAttr: BindingFlags.Public | BindingFlags.Instance, | ||
binder: null, | ||
types: Array.Empty<Type>(), | ||
modifiers: null) == null) | ||
{ | ||
continue; | ||
} | ||
|
||
yield return type ; | ||
} | ||
} | ||
|
||
public static T InvokePublicConstructor<T>(Type type) | ||
{ | ||
var ctor = type.GetConstructor( | ||
bindingAttr: BindingFlags.Public | BindingFlags.Instance, | ||
binder: null, | ||
types: Array.Empty<Type>(), | ||
modifiers: null); | ||
|
||
if (ctor == null) | ||
{ | ||
return default; | ||
} | ||
|
||
return (T)ctor.Invoke(Array.Empty<object>()); | ||
} | ||
|
||
public static bool IsPublicNonAbstract<T>(Type type) | ||
{ | ||
return !type.IsAbstract && type.IsPublic && typeof(T).IsAssignableFrom(type); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...m.Windows.Forms/tests/UnitTests/AccessibleObjects/Control.ControlAccessibleObjectTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace System.Windows.Forms.Tests.AccessibleObjects | ||
{ | ||
public class Control_ControlAccessibleObjectTests | ||
{ | ||
public static IEnumerable<object[]> ControlAccessibleObject_IsPatternSupported_LegacyIAccessible_TestData() | ||
{ | ||
var supportedLegacyIAccessiblePatternClasses = new List<Type> { | ||
typeof(Form), | ||
typeof(ListBox), | ||
typeof(MonthCalendar), | ||
typeof(PrintPreviewDialog) | ||
}; | ||
|
||
return ReflectionHelper.GetPublicNotAbstractClasses<Control>() | ||
.Select(type => new object[] { type, supportedLegacyIAccessiblePatternClasses.Contains(type) }); | ||
} | ||
|
||
[StaTheory] | ||
[MemberData(nameof(ControlAccessibleObject_IsPatternSupported_LegacyIAccessible_TestData))] | ||
public void ControlAccessibleObject_IsPatternSupported_LegacyIAccessible_ReturnsExpected(Type type, bool legacyIAccessiblePatternSupported) | ||
{ | ||
using Control control = ReflectionHelper.InvokePublicConstructor<Control>(type); | ||
|
||
if (control == null) | ||
{ | ||
return; | ||
} | ||
|
||
AccessibleObject controlAccessibleObject = control.AccessibilityObject; | ||
|
||
bool supportsLegacyIAccessiblePatternId = controlAccessibleObject.IsPatternSupported(NativeMethods.UIA_LegacyIAccessiblePatternId); | ||
|
||
Assert.Equal(legacyIAccessiblePatternSupported, supportsLegacyIAccessiblePatternId); | ||
} | ||
|
||
public static IEnumerable<object[]> ControlAccessibleObject_TestData() | ||
{ | ||
return ReflectionHelper.GetPublicNotAbstractClasses<Control>().Select(type => new object[] { type }); | ||
} | ||
|
||
[StaTheory] | ||
[MemberData(nameof(ControlAccessibleObject_TestData))] | ||
public void ControlAccessibleObject_Custom_Role_ReturnsExpected(Type type) | ||
{ | ||
using Control control = ReflectionHelper.InvokePublicConstructor<Control>(type); | ||
|
||
if (control == null) | ||
{ | ||
return; | ||
} | ||
|
||
control.AccessibleRole = AccessibleRole.Link; | ||
AccessibleObject controlAccessibleObject = control.AccessibilityObject; | ||
|
||
var accessibleObjectRole = controlAccessibleObject.Role; | ||
|
||
Assert.Equal(AccessibleRole.Link, accessibleObjectRole); | ||
} | ||
|
||
[StaTheory] | ||
[MemberData(nameof(ControlAccessibleObject_TestData))] | ||
public void ControlAccessibleObject_Custom_Description_ReturnsExpected(Type type) | ||
{ | ||
using Control control = ReflectionHelper.InvokePublicConstructor<Control>(type); | ||
|
||
if (control == null) | ||
{ | ||
return; | ||
} | ||
|
||
control.AccessibleDescription = "Test Accessible Description"; | ||
AccessibleObject controlAccessibleObject = control.AccessibilityObject; | ||
|
||
var accessibleObjectDescription = controlAccessibleObject.Description; | ||
|
||
Assert.Equal("Test Accessible Description", accessibleObjectDescription); | ||
} | ||
|
||
[StaTheory] | ||
[MemberData(nameof(ControlAccessibleObject_TestData))] | ||
public void ControlAccessibleObject_GetPropertyValue_Custom_Name_ReturnsExpected(Type type) | ||
{ | ||
using Control control = ReflectionHelper.InvokePublicConstructor<Control>(type); | ||
|
||
if (control == null || !control.SupportsUiaProviders) | ||
{ | ||
return; | ||
} | ||
|
||
control.Name = "Name1"; | ||
control.AccessibleName = "Test Name"; | ||
AccessibleObject controlAccessibleObject = control.AccessibilityObject; | ||
|
||
var accessibleName = controlAccessibleObject.GetPropertyValue(NativeMethods.UIA_NamePropertyId); | ||
|
||
Assert.Equal("Test Name", accessibleName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.