From 5541236688d2fce0297c3b1769f98962db67dc77 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 14 Oct 2024 22:07:09 +0300 Subject: [PATCH 1/6] fix: Fix potential crash in PropertyValue.AreEqualImpl --- src/Uno.Foundation/PropertyValue.Internal.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Uno.Foundation/PropertyValue.Internal.cs b/src/Uno.Foundation/PropertyValue.Internal.cs index b67743b412cf..b7b4c02e5347 100644 --- a/src/Uno.Foundation/PropertyValue.Internal.cs +++ b/src/Uno.Foundation/PropertyValue.Internal.cs @@ -90,7 +90,8 @@ bool CompareOtherType() //} if (oldValueType.IsEnum) { - return oldValue switch + var oldValueUnwrapped = Convert.ChangeType(oldValue, oldValueType.GetEnumUnderlyingType()); + return oldValueUnwrapped switch { byte oldValueAsByte => oldValueAsByte == (byte)newValue, sbyte oldValueAsSByte => oldValueAsSByte == (sbyte)newValue, From 42e14559e3dccbf13d019ce750a494a2289f64da Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 15 Oct 2024 09:58:33 +0300 Subject: [PATCH 2/6] chore: Fix build --- src/Uno.Foundation/PropertyValue.Internal.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Uno.Foundation/PropertyValue.Internal.cs b/src/Uno.Foundation/PropertyValue.Internal.cs index b7b4c02e5347..0e99f4ddff5d 100644 --- a/src/Uno.Foundation/PropertyValue.Internal.cs +++ b/src/Uno.Foundation/PropertyValue.Internal.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; namespace Windows.Foundation; @@ -90,7 +91,7 @@ bool CompareOtherType() //} if (oldValueType.IsEnum) { - var oldValueUnwrapped = Convert.ChangeType(oldValue, oldValueType.GetEnumUnderlyingType()); + var oldValueUnwrapped = Convert.ChangeType(oldValue, oldValueType.GetEnumUnderlyingType(), CultureInfo.InvariantCulture); return oldValueUnwrapped switch { byte oldValueAsByte => oldValueAsByte == (byte)newValue, From f91d6f1eae4cd519d2da1869efb2169f3fc20ce7 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 15 Oct 2024 15:00:23 +0200 Subject: [PATCH 3/6] test: ComboBox with Enum values --- .../Given_ComboBox.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs index 4d49f9f6644d..b635b7da38e1 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using FluentAssertions; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; @@ -15,13 +16,16 @@ using MUXControlsTestApp.Utilities; using Private.Infrastructure; using SamplesApp.UITests; +using SkiaSharp; using Uno.Extensions; using Uno.UI.RuntimeTests.Helpers; using Uno.UI.RuntimeTests.Tests.ComboBoxTests; using Windows.Foundation; using Windows.Foundation.Metadata; +using Windows.Storage.Pickers; using Windows.UI.Input.Preview.Injection; using static Private.Infrastructure.TestServices; +using ComboBoxHelper = Microsoft.UI.Xaml.Tests.Common.ComboBoxHelper; #if WINAPPSDK using Uno.UI.Extensions; @@ -1293,6 +1297,31 @@ public async Task When_Customized_Popup_Placement(PopupPlacementMode mode, doubl } } + [TestMethod] + [RunsOnUIThread] + public async Task When_Items_Are_Enum_Values() + { + var comboBox = new ComboBox(); + comboBox.ItemsSource = Enum.GetValues(typeof(PickerLocationId)).Cast(); + comboBox.SelectedIndex = 0; + TestServices.WindowHelper.WindowContent = comboBox; + await TestServices.WindowHelper.WaitForLoaded(comboBox); + + await ComboBoxHelper.OpenComboBox(comboBox, ComboBoxHelper.OpenMethod.Programmatic); + await TestServices.WindowHelper.WaitForIdle(); + + Assert.IsTrue(comboBox.IsDropDownOpen); + + await TestServices.WindowHelper.WaitForIdle(); + + var popup = VisualTreeHelper.GetOpenPopupsForXamlRoot(comboBox.XamlRoot).FirstOrDefault(); + Assert.IsNotNull(popup); + + var child = (FrameworkElement)popup.Child; + var comboBoxItems = child.FindChildren().ToArray(); + Assert.AreEqual(Enum.GetValues(typeof(PickerLocationId)).Length, comboBoxItems.Length); + } + #if HAS_UNO [TestMethod] [RunsOnUIThread] From 974baa7d241eaf1d480dc09f3ba726b838aef290 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 15 Oct 2024 15:07:30 +0200 Subject: [PATCH 4/6] chore: Adjust test to run on WinUI --- .../Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs index b635b7da38e1..79bd6b00454c 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs @@ -16,7 +16,6 @@ using MUXControlsTestApp.Utilities; using Private.Infrastructure; using SamplesApp.UITests; -using SkiaSharp; using Uno.Extensions; using Uno.UI.RuntimeTests.Helpers; using Uno.UI.RuntimeTests.Tests.ComboBoxTests; @@ -1318,7 +1317,7 @@ public async Task When_Items_Are_Enum_Values() Assert.IsNotNull(popup); var child = (FrameworkElement)popup.Child; - var comboBoxItems = child.FindChildren().ToArray(); + var comboBoxItems = child.GetAllChildren().OfType().ToArray(); Assert.AreEqual(Enum.GetValues(typeof(PickerLocationId)).Length, comboBoxItems.Length); } From a4b128cc92aec9477e57df44928a5e8ab071dcb4 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Tue, 15 Oct 2024 15:35:57 +0200 Subject: [PATCH 5/6] chore: Adjust usings --- .../Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs index 79bd6b00454c..942b239a782f 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs @@ -25,10 +25,9 @@ using Windows.UI.Input.Preview.Injection; using static Private.Infrastructure.TestServices; using ComboBoxHelper = Microsoft.UI.Xaml.Tests.Common.ComboBoxHelper; - -#if WINAPPSDK using Uno.UI.Extensions; -#elif __IOS__ + +#if __IOS__ using UIKit; using _UIViewController = UIKit.UIViewController; using Uno.UI.Controls; From 6ad10db5d2cf8a5e9ada553adfac870d8f092356 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Wed, 16 Oct 2024 15:11:42 +0200 Subject: [PATCH 6/6] chore: Adjust usings --- .../Windows_UI_Xaml_Controls/Given_ComboBox.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs index 942b239a782f..5389e258e1a7 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ComboBox.cs @@ -28,7 +28,6 @@ using Uno.UI.Extensions; #if __IOS__ -using UIKit; using _UIViewController = UIKit.UIViewController; using Uno.UI.Controls; @@ -36,10 +35,6 @@ using Microsoft.UI.Xaml.Media.Animation; using static Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls.MultiFrame; using Microsoft.UI.Xaml.Controls.Primitives; - -#elif __MACOS__ -using AppKit; -#else #endif namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls @@ -1541,7 +1536,7 @@ public async Task OpenModal(FrameSectionsTransitionInfo transitionInfo, Page pag { var uiViewController = new UiViewController(page); - var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; + var rootController = UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController; await rootController.PresentViewControllerAsync(uiViewController, animated: false); } @@ -1550,7 +1545,7 @@ public async Task CloseModal() { try { - var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; + var rootController = UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController; await rootController.DismissViewControllerAsync(false); } @@ -1682,7 +1677,7 @@ public Task Run(Frame frameToHide, Frame frameToShow, bool frameToShowIsAboveFra public class UIViewControllerSectionsTransitionInfo : FrameSectionsTransitionInfo { - public UIViewControllerSectionsTransitionInfo(bool allowDismissFromGesture = true, UIModalPresentationStyle modalPresentationStyle = UIModalPresentationStyle.PageSheet, UIModalTransitionStyle modalTransitionStyle = UIModalTransitionStyle.CoverVertical) + public UIViewControllerSectionsTransitionInfo(bool allowDismissFromGesture = true, UIKit.UIModalPresentationStyle modalPresentationStyle = UIKit.UIModalPresentationStyle.PageSheet, UIKit.UIModalTransitionStyle modalTransitionStyle = UIKit.UIModalTransitionStyle.CoverVertical) { AllowDismissFromGesture = allowDismissFromGesture; ModalPresentationStyle = modalPresentationStyle; @@ -1691,9 +1686,9 @@ public UIViewControllerSectionsTransitionInfo(bool allowDismissFromGesture = tru public bool AllowDismissFromGesture { get; } - public UIModalPresentationStyle ModalPresentationStyle { get; } + public UIKit.UIModalPresentationStyle ModalPresentationStyle { get; } - public UIModalTransitionStyle ModalTransitionStyle { get; } + public UIKit.UIModalTransitionStyle ModalTransitionStyle { get; } public override FrameSectionsTransitionInfoTypes Type => FrameSectionsTransitionInfoTypes.UIViewControllerBased; }