Skip to content

Commit

Permalink
Add switch to test project
Browse files Browse the repository at this point in the history
  • Loading branch information
LeafShi1 committed Feb 21, 2025
1 parent 39ef382 commit 0902800
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Windows.Forms.Primitives;

namespace System;

/// <summary>
/// Scope for enabling / disabling the NotifyUIAProviderTheText Switch.
/// </summary>
public readonly ref struct NotifyUIAProviderTheRichTextContent
{
private readonly AppContextSwitchScope _switchScope;

public NotifyUIAProviderTheRichTextContent(bool enable)
{
// Prevent multiple NotifyUIAProviderTheRichTextContent from running simultaneously. Using Monitor to allow recursion on
// the same thread.
Monitor.Enter(typeof(NotifyUIAProviderTheRichTextContent));
_switchScope = new(WinFormsAppContextSwitchNames.NotifyUIAProviderTheText, GetDefaultValue, enable);
}

public void Dispose()
{
try
{
_switchScope.Dispose();
}
finally
{
Monitor.Exit(typeof(NotifyUIAProviderTheRichTextContent));
}
}

public static bool GetDefaultValue() =>
typeof(LocalAppContextSwitches).TestAccessor()
.CreateDelegate<Func<string, bool>>("GetSwitchDefaultValue")(WinFormsAppContextSwitchNames.NotifyUIAProviderTheText);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ public const string ServicePointManagerCheckCrl
/// </summary>
public const string TreeNodeCollectionAddRangeRespectsSortOrder
= "System.Windows.Forms.TreeNodeCollectionAddRangeRespectsSortOrder";

/// <summary>
/// The switch that controls whether the text of the <see cref="Windows.Forms.RichTextBox" /> is sent to the UIA provider.
/// </summary>
public const string NotifyUIAProviderTheText
= "System.Windows.Forms.RichTextBox.NotifyUIAProviderTheText";
}
Original file line number Diff line number Diff line change
Expand Up @@ -10594,6 +10594,7 @@ public void RichTextBox_CheckRichEditWithVersionCanCreateOldVersions()
[NewAndDefaultData<EventArgs>]
public void RichTextBox_OnGotFocus_RaisesAutomationNotification_WithText(EventArgs eventArgs)
{
using NotifyUIAProviderTheRichTextContent scope = new(enable: true);
Mock<Control> mockParent = new() { CallBase = true };
Mock<Control.ControlAccessibleObject> mockAccessibleObject = new(MockBehavior.Strict, mockParent.Object);
mockAccessibleObject
Expand Down

0 comments on commit 0902800

Please sign in to comment.