From 256db036eab4bdd32f629631a602733649a5f23e Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 20 Dec 2023 15:56:57 +0200 Subject: [PATCH] chore: Partial fix only for UWP --- .../Engine/UI/UnitTestsUIContentHelper.cs | 10 ++++++++-- .../Engine/UI/_Private/UnitTestDispatcherCompat.cs | 10 +++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsUIContentHelper.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsUIContentHelper.cs index c9b5cbc..510b9f3 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsUIContentHelper.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/UnitTestsUIContentHelper.cs @@ -111,8 +111,14 @@ internal set /// public static async Task WaitForIdle() { - await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Idle, () => { }); - await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Idle, () => { }); +#if WINDOWS_WINUI || HAS_UNO_WINUI + // This is a wrong implementation. It doesn't really wait for "Idle". + await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { }); + await RootElementDispatcher.RunAsync(UnitTestDispatcherCompat.Priority.Low, () => { }); +#else + await RootElementDispatcher.RunIdleAsync(_ => { /* Empty to wait for the idle queue to be reached */ }); + await RootElementDispatcher.RunIdleAsync(_ => { /* Empty to wait for the idle queue to be reached */ }); +#endif } /// diff --git a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs index 564210d..296d1a1 100644 --- a/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs +++ b/src/Uno.UI.RuntimeTests.Engine.Library/Engine/UI/_Private/UnitTestDispatcherCompat.cs @@ -31,11 +31,10 @@ namespace Uno.UI.RuntimeTests.Internal.Helpers; public partial class UnitTestDispatcherCompat { - public enum Priority { Idle = -2, Low = -1, Normal = 0, High = 1 } + public enum Priority { Low = -1, Normal = 0, High = 1 } private static _Priority RemapPriority(Priority priority) => priority switch { - Priority.Idle => _Priority.Idle, Priority.Low => _Priority.Low, Priority.Normal => _Priority.Normal, Priority.High => _Priority.High, @@ -52,7 +51,12 @@ public UnitTestDispatcherCompat(_Impl impl) this._impl = impl; } - public static UnitTestDispatcherCompat From(UIElement x) => +#if !WINDOWS_WINUI && !HAS_UNO_WINUI + public Windows.Foundation.IAsyncAction RunIdleAsync(Windows.UI.Core.IdleDispatchedHandler agileCallback) + => _impl.RunIdleAsync(agileCallback); +#endif + + public static UnitTestDispatcherCompat From(UIElement x) => #if HAS_UNO_WINUI || WINDOWS_WINUI new UnitTestDispatcherCompat(x.DispatcherQueue); #else