-
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.
UIAProvider support for WebBrowser control and UnitTests
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
// 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, | ||
UiaCore.UIA.IsKeyboardFocusablePropertyId | ||
=> (State & AccessibleStates.Focusable) == AccessibleStates.Focusable, | ||
_ => 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
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); | ||
} | ||
} | ||
} |