-
Notifications
You must be signed in to change notification settings - Fork 975
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding UIA support for WebBrowser (#7314)
- Loading branch information
Showing
5 changed files
with
93 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
~override System.Windows.Forms.WebBrowser.CreateAccessibilityInstance() -> System.Windows.Forms.AccessibleObject |
27 changes: 27 additions & 0 deletions
27
src/System.Windows.Forms/src/System/Windows/Forms/WebBrowser.WebBrowserAccessibleObject.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,27 @@ | ||
// 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 static Interop; | ||
|
||
namespace System.Windows.Forms | ||
{ | ||
public partial class WebBrowser | ||
{ | ||
internal class WebBrowserAccessibleObject : ControlAccessibleObject | ||
{ | ||
public WebBrowserAccessibleObject(WebBrowser owner) : base(owner) | ||
{ } | ||
|
||
internal override object? GetPropertyValue(UiaCore.UIA propertyID) | ||
=> propertyID switch | ||
{ | ||
UiaCore.UIA.AutomationIdPropertyId | ||
=> Owner.Name, | ||
UiaCore.UIA.HasKeyboardFocusPropertyId | ||
=> Owner.Focused, | ||
_ => base.GetPropertyValue(propertyID) | ||
}; | ||
} | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
....Forms/tests/UnitTests/System/Windows/Forms/WebBrowser.WebBrowserAccessibleObjectTests.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,53 @@ | ||
// 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 Xunit; | ||
using static System.Windows.Forms.WebBrowser; | ||
using static Interop.UiaCore; | ||
|
||
namespace System.Windows.Forms.Tests | ||
{ | ||
public class WebBrowser_WebBrowserAccessibleObjectTests : IClassFixture<ThreadExceptionFixture> | ||
{ | ||
[WinFormsFact] | ||
public void WebBrowserAccessibleObject_Ctor_Default() | ||
{ | ||
using WebBrowser webBrowser = new(); | ||
WebBrowserAccessibleObject accessibleObject = (WebBrowserAccessibleObject)webBrowser.AccessibilityObject; | ||
|
||
Assert.Equal(webBrowser, accessibleObject.Owner); | ||
Assert.False(webBrowser.IsHandleCreated); | ||
} | ||
|
||
[WinFormsTheory] | ||
[InlineData((int)UIA.NamePropertyId, "TestName")] | ||
[InlineData((int)UIA.AutomationIdPropertyId, "ToolStripContainer1")] | ||
public void WebBrowserAccessibleObject_GetPropertyValue_Invoke_ReturnsExpected(int propertyID, object expected) | ||
{ | ||
using WebBrowser webBrowser = new WebBrowser | ||
{ | ||
Name = expected.ToString(), | ||
AccessibleName = expected.ToString() | ||
}; | ||
|
||
WebBrowserAccessibleObject accessibleObject = (WebBrowserAccessibleObject)webBrowser.AccessibilityObject; | ||
object value = accessibleObject.GetPropertyValue((UIA)propertyID); | ||
|
||
Assert.Equal(expected, value); | ||
Assert.False(webBrowser.IsHandleCreated); | ||
} | ||
|
||
[WinFormsFact] | ||
public void WebBrowserAccessibleObject_GetPropertyValue_HasKeyboardFocus_ReturnsFalse_IfControlHasNoFocus() | ||
{ | ||
using WebBrowser webBrowser = new(); | ||
|
||
WebBrowserAccessibleObject accessibleObject = (WebBrowserAccessibleObject)webBrowser.AccessibilityObject; | ||
bool value = (bool)accessibleObject.GetPropertyValue(UIA.HasKeyboardFocusPropertyId); | ||
|
||
Assert.False(value); | ||
Assert.False(webBrowser.IsHandleCreated); | ||
} | ||
} | ||
} |