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

[Servicing 3.1] Fixing regression in Control.AccessibleName property #3600

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ internal FormAccessibleObject(Form owner) : base(owner)

internal override Rectangle BoundingRectangle => _owner.Bounds;

internal override object GetPropertyValue(int propertyID)
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
{
return propertyID == NativeMethods.UIA_NamePropertyId
? Name
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
: base.GetPropertyValue(propertyID);
}

internal override bool IsIAccessibleExSupported()
{
if (_owner != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ internal override bool IsIAccessibleExSupported()
internal override bool IsPatternSupported(int patternId)
{
if (patternId == NativeMethods.UIA_ScrollPatternId ||
patternId == NativeMethods.UIA_SelectionPatternId ||
patternId == NativeMethods.UIA_LegacyIAccessiblePatternId)
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
patternId == NativeMethods.UIA_SelectionPatternId)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,9 @@ public override AccessibleRole Role

internal override object GetPropertyValue(int propertyID)
{
switch (propertyID)
if (propertyID == NativeMethods.UIA_ControlTypePropertyId)
{
case NativeMethods.UIA_ControlTypePropertyId:
return NativeMethods.UIA_MenuBarControlTypeId;
case NativeMethods.UIA_NamePropertyId:
return Name;
return NativeMethods.UIA_MenuBarControlTypeId;
}

return base.GetPropertyValue(propertyID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ internal override bool IsPatternSupported(int patternId) =>
var p when
p == NativeMethods.UIA_ValuePatternId ||
p == NativeMethods.UIA_GridPatternId ||
p == NativeMethods.UIA_TablePatternId ||
p == NativeMethods.UIA_LegacyIAccessiblePatternId => true,
p == NativeMethods.UIA_TablePatternId => true,
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
_ => base.IsPatternSupported(patternId)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,19 @@ internal override object GetPropertyValue(int propertyID)
}
}

/// <summary>
/// Indicates whether the specified pattern is supported.
/// </summary>
/// <param name="patternId">The pattern ID.</param>
/// <returns>True if specified pattern is supported, otherwise false.</returns>
internal override bool IsPatternSupported(int patternId)
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
{
if (patternId == NativeMethods.UIA_LegacyIAccessiblePatternId)
{
return true;
}

return base.IsPatternSupported(patternId);
}

/// <summary>
/// Gets the accessible role.
/// </summary>
public override AccessibleRole Role
{
get
{
AccessibleRole role = Owner.AccessibleRole;
if (role != AccessibleRole.Default)
Tanya-Solyanik marked this conversation as resolved.
Show resolved Hide resolved
{
return role;
}

return AccessibleRole.PushButton;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,60 +70,5 @@ public void ComboBoxEditAccessibleObject_NameNotNull(string name)
object editAccessibleName = comboBox.ChildEditAccessibleObject.GetPropertyValue(NativeMethods.UIA_NamePropertyId);
Assert.NotNull(editAccessibleName);
}

[WinFormsFact]
public void ComboBoxAccessibleObject_GetPropertyValue_Custom_Name_ReturnsExpected()
{
using var comboBox = new ComboBox()
{
Name = "Name1",
AccessibleName = "Test Name"
};

AccessibleObject comboBoxAccessibleObject = comboBox.AccessibilityObject;
var accessibleName = comboBoxAccessibleObject.GetPropertyValue(NativeMethods.UIA_NamePropertyId);

Assert.Equal("Test Name", accessibleName);
}

[WinFormsFact]
public void ComboBoxAccessibleObject_IsPatternSupported_LegacyIAccessible_ReturnsTrue()
{
using var comboBox = new ComboBox();
AccessibleObject comboBoxAccessibleObject = comboBox.AccessibilityObject;

bool supportsLegacyIAccessiblePatternId = comboBoxAccessibleObject.IsPatternSupported(NativeMethods.UIA_LegacyIAccessiblePatternId);

Assert.True(supportsLegacyIAccessiblePatternId);
}

[WinFormsFact]
public void ComboBoxAccessibleObject_LegacyIAccessible_Custom_Role_ReturnsExpected()
{

using var comboBox = new ComboBox()
{
AccessibleRole = AccessibleRole.Link
};

AccessibleObject comboBoxAccessibleObject = comboBox.AccessibilityObject;
var accessibleObjectRole = comboBoxAccessibleObject.Role;

Assert.Equal(AccessibleRole.Link, accessibleObjectRole);
}

[WinFormsFact]
public void ComboBoxAccessibleObject_LegacyIAccessible_Custom_Description_ReturnsExpected()
{
using var comboBox = new ComboBox()
{
AccessibleDescription = "Test Description"
};

AccessibleObject comboBoxAccessibleObject = comboBox.AccessibilityObject;
var accessibleObjectDescription = comboBoxAccessibleObject.Description;

Assert.Equal("Test Description", accessibleObjectDescription);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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;
using Xunit;

namespace System.Windows.Forms.Tests.AccessibleObjects
{
public class ControlAccessibleObjectTests
RussKie marked this conversation as resolved.
Show resolved Hide resolved
{
[Theory]
[MemberData(nameof(ControlObject_TestData))]
public void ControlAccessibleObject_LegacyIAccessible_Custom_Role_ReturnsExpected(Type type)
{
Control control = GetControl(type);

if (control == null || !control.SupportsUiaProviders)
{
return;
}

control.AccessibleRole = AccessibleRole.Link;
AccessibleObject controlAccessibleObject = control.AccessibilityObject;

var accessibleObjectRole = controlAccessibleObject.Role;

Assert.Equal(AccessibleRole.Link, accessibleObjectRole);
}

[Theory]
[MemberData(nameof(ControlObject_TestData))]
public void ControlAccessibleObject_IsPatternSupported_LegacyIAccessible_ReturnsTrue(Type type)
{
Control control = GetControl(type);

if (control == null || !control.SupportsUiaProviders)
{
return;
}

AccessibleObject controlAccessibleObject = control.AccessibilityObject;

bool supportsLegacyIAccessiblePatternId = controlAccessibleObject.IsPatternSupported(NativeMethods.UIA_LegacyIAccessiblePatternId);

Assert.True(supportsLegacyIAccessiblePatternId);
}

[Theory]
[MemberData(nameof(ControlObject_TestData))]
public void ControlAccessibleObject_LegacyIAccessible_Custom_Description_ReturnsExpected(Type type)
{
Control control = GetControl(type);

if (control == null || !control.SupportsUiaProviders)
{
return;
}

control.AccessibleDescription = "Test Accessible Description";
AccessibleObject controlAccessibleObject = control.AccessibilityObject;

var accessibleObjectDescription = controlAccessibleObject.Description;

Assert.Equal("Test Accessible Description", accessibleObjectDescription);
}

[Theory]
[MemberData(nameof(ControlObject_TestData))]
public void ToolStripItemAccessibleObject_GetPropertyValue_Custom_Name_ReturnsExpected(Type type)
{
Control control = GetControl(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);
}

public static IEnumerable<object[]> ControlObject_TestData()
{
var types = typeof(Control).Assembly.GetTypes().Where(type => !type.IsAbstract && type != typeof(WebBrowser));
foreach (var type in types)
{
yield return new object[] { type };
}
}

private Control GetControl(Type type)
{
if (!typeof(Control).IsAssignableFrom(type))
{
return null;
}

var ctor = type.GetConstructor(
bindingAttr: BindingFlags.Public | BindingFlags.Instance,
binder: null,
types: Array.Empty<Type>(),
modifiers: null);

if (ctor == null)
{
return null;
}

return (Control)ctor.Invoke(new object[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,5 @@ public void DataGridViewAccessibleObject_ItemStatus()
string expectedStatus = "Sorted ascending by Some column.";
Assert.Equal(expectedStatus, itemStatus);
}

[WinFormsFact]
public void DataGridViewAccessibleObject_GetPropertyValue_Custom_Name_ReturnsExpected()
{
using var dataGridView = new DataGridView()
{
Name = "Name1",
AccessibleName = "Test Name"
};

AccessibleObject dataGridViewAccessibleObject = dataGridView.AccessibilityObject;
var accessibleName = dataGridViewAccessibleObject.GetPropertyValue(NativeMethods.UIA_NamePropertyId);

Assert.Equal("Test Name", accessibleName);
}

[WinFormsFact]
public void DataGridViewAccessibleObject_IsPatternSupported_LegacyIAccessible_ReturnsTrue()
{
using var dataGridView = new DataGridView();
AccessibleObject dataGridViewAccessibleObject = dataGridView.AccessibilityObject;

bool supportsLegacyIAccessiblePatternId = dataGridViewAccessibleObject.IsPatternSupported(NativeMethods.UIA_LegacyIAccessiblePatternId);

Assert.True(supportsLegacyIAccessiblePatternId);
}

[WinFormsFact]
public void DataGridViewAccessibleObject_LegacyIAccessible_Custom_Role_ReturnsExpected()
{
using var dataGridView = new DataGridView()
{
AccessibleRole = AccessibleRole.Link
};

AccessibleObject dataGridViewAccessibleObject = dataGridView.AccessibilityObject;
var accessibleObjectRole = dataGridViewAccessibleObject.Role;

Assert.Equal(AccessibleRole.Link, accessibleObjectRole);
}

[WinFormsFact]
public void DataGridViewAccessibleObject_LegacyIAccessible_Custom_Description_ReturnsExpected()
{
using var dataGridView = new DataGridView()
{
AccessibleDescription = "Test Description"
};

AccessibleObject dataGridViewAccessibleObject = dataGridView.AccessibilityObject;
var accessibleObjectDescription = dataGridViewAccessibleObject.Description;

Assert.Equal("Test Description", accessibleObjectDescription);
}
}
}

This file was deleted.

Loading