Skip to content

fix: Namespace and logic in ProgressBarAutomationPeer #20501

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

Merged
merged 5 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,7 @@

<IgnoreSet baseVersion="6.0">
<Types>
<Member fullName="Microsoft.UI.Xaml.Controls.ProgressBarAutomationPeer" reason="Does not exist in WinUI" />
</Types>

<Events>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using Private.Infrastructure;
#if __SKIA__
using Uno.UI.Xaml;
#endif

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls;

[TestClass]
public class Given_ProgressBar
{
#if __SKIA__
[TestMethod]
[RunsOnUIThread]
public async Task When_ProgressBar_Automation_Listener_Attached()
{
try
{
var grid = new Grid() { Width = 100, Height = 100 };
var progressBar = new ProgressBar();
grid.Children.Add(progressBar);
TestServices.WindowHelper.WindowContent = grid;
await TestServices.WindowHelper.WaitForLoaded(grid);

var stubListener = new StubListener();
AutomationPeer.TestAutomationPeerListener = stubListener;
progressBar.Maximum = 10;
Assert.IsTrue(stubListener.Notified);
}
finally
{
AutomationPeer.TestAutomationPeerListener = null;
}
}

private class StubListener : IAutomationPeerListener
{
public bool Notified { get; private set; }

public bool ListenerExistsHelper(AutomationEvents eventId) => true;
public void NotifyPropertyChangedEvent(AutomationPeer peer, AutomationProperty automationProperty, object oldValue, object newValue) =>
Notified = true;
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma warning disable 114 // new keyword hiding
namespace Microsoft.UI.Xaml.Automation.Peers
{
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
#if false
[global::Uno.NotImplemented]
#endif
public partial class ProgressBarAutomationPeer : global::Microsoft.UI.Xaml.Automation.Peers.RangeBaseAutomationPeer
{
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "__TVOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
public ProgressBarAutomationPeer(global::Microsoft.UI.Xaml.Controls.ProgressBar owner) : base(owner)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Automation.Provider;

namespace Microsoft/* UWP don't rename */.UI.Xaml.Controls;
namespace Microsoft.UI.Xaml.Automation.Peers;

public class ProgressBarAutomationPeer : AutomationPeer, IRangeValueProvider
public partial class ProgressBarAutomationPeer : RangeBaseAutomationPeer, IRangeValueProvider
{
private readonly ProgressBar _owner;

public ProgressBarAutomationPeer(ProgressBar owner)
public ProgressBarAutomationPeer(ProgressBar owner) : base(owner)
{
_owner = owner;
}

protected override object GetPatternCore(PatternInterface patternInterface)
{
if (patternInterface == PatternInterface.RangeValue)
{
if (_owner.IsIndeterminate)
if (Owner is ProgressBar progressBar && progressBar.IsIndeterminate)
{
return null;
}
Expand All @@ -33,30 +31,39 @@ protected override string GetNameCore()
{
var name = base.GetNameCore();

var progressBar = _owner;

if (progressBar.ShowError)
{
return "Error" + name;
}
else if (progressBar.ShowPaused)
{
return "Busy" + name;
}
else if (progressBar.IsIndeterminate)
if (Owner is ProgressBar progressBar)
{
return "Paused" + name;
if (progressBar.ShowError)
{
return "Error" + name;
}
else if (progressBar.ShowPaused)
{
return "Busy" + name;
}
else if (progressBar.IsIndeterminate)
{
return "Paused" + name;
}
}
return name;
}

protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.ProgressBar;

public bool IsReadOnly => true;
public double Value => _owner.Value;
public double SmallChange => double.NaN;
public double LargeChange => double.NaN;
public double Minimum => _owner.Minimum;
public double Maximum => _owner.Maximum;
public void SetValue(double value) => _owner.Value = value; // ???
private ProgressBar GetImpl() => (ProgressBar)Owner;

bool IRangeValueProvider.IsReadOnly => true;

double IRangeValueProvider.Value => GetImpl().Value;

double IRangeValueProvider.SmallChange => double.NaN;

double IRangeValueProvider.LargeChange => double.NaN;

double IRangeValueProvider.Minimum => GetImpl().Minimum;

double IRangeValueProvider.Maximum => GetImpl().Maximum;

void IRangeValueProvider.SetValue(double value) => GetImpl().Value = value;
}
4 changes: 3 additions & 1 deletion src/Uno.UI/UI/Xaml/Automation/Peers/AutomationPeer.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ partial class AutomationPeer

internal static IAutomationPeerListener? AutomationPeerListener
{
get => _automationPeerListener;
get => TestAutomationPeerListener ?? _automationPeerListener;
set
{
if (_automationPeerListener is not null)
Expand All @@ -22,6 +22,8 @@ internal static IAutomationPeerListener? AutomationPeerListener
}
}

internal static IAutomationPeerListener? TestAutomationPeerListener { get; set; }

public void RaisePropertyChangedEvent(AutomationProperty automationProperty, object oldValue, object newValue)
{
AutomationPeerListener?.NotifyPropertyChangedEvent(this, automationProperty, oldValue, newValue);
Expand Down
Loading
Loading