From d9741327ac1485a476fc14852f25344aecad7801 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Fri, 15 Nov 2024 18:55:06 +0200 Subject: [PATCH] test: add When_DragDrop_AcceptedOperation_None --- .../Tests/Windows_UI_Xaml/Given_UIElement.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs index ddb0c380ab13..4b77dae833af 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs @@ -33,6 +33,7 @@ using Windows.UI; using Windows.ApplicationModel.Appointments; using Microsoft.UI.Xaml.Hosting; +using Uno.UI.Helpers.Xaml; using Uno.UI.Toolkit.Extensions; #if __IOS__ @@ -1682,6 +1683,68 @@ public async Task When_ScaleTransform_HitTest(bool addClip) #if HAS_UNO #region Drag and Drop + [TestMethod] + [RunsOnUIThread] + [UnoWorkItem("https://github.com/unoplatform/uno/issues/18770")] + [DataRow(true)] + [DataRow(false)] +#if !HAS_INPUT_INJECTOR + [Ignore("InputInjector is not supported on this platform.")] +#endif + public async Task When_DragDrop_AcceptedOperation_None(bool setAcceptedOperation) + { + if (TestServices.WindowHelper.IsXamlIsland) + { + Assert.Inconclusive("Drag and drop doesn't work in Uno islands."); + } + + var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector"); + using var mouse = injector.GetMouse(); + + var dropCount = 0; + Rectangle source, target; + var sp = new StackPanel + { + (source = new Rectangle + { + Width = 100, + Height = 100, + Fill = new SolidColorBrush(Microsoft.UI.Colors.LightCoral), + CanDrag = true + }), + (target = new Rectangle + { + Width = 100, + Height = 100, + Fill = new SolidColorBrush(Microsoft.UI.Colors.LightCoral), + AllowDrop = true + }.GenericApply(rect => + { + rect.Drop += (_, _) => dropCount++; + if (setAcceptedOperation) + { + rect.DragOver += (_, e) => e.AcceptedOperation = DataPackageOperation.Copy; + } + })) + }; + + await UITestHelper.Load(sp); + + mouse.MoveTo(source.GetAbsoluteBoundsRect().GetCenter()); + await TestServices.WindowHelper.WaitForIdle(); + mouse.Press(); + await TestServices.WindowHelper.WaitForIdle(); + for (int i = 1; i <= 10; i++) + { + mouse.MoveBy(0, (target.GetAbsoluteBoundsRect().GetMidY() - source.GetAbsoluteBoundsRect().GetMidY()) * 0.1); + await TestServices.WindowHelper.WaitForIdle(); + } + mouse.Release(); + await TestServices.WindowHelper.WaitForIdle(); + + Assert.AreEqual(setAcceptedOperation ? 1 : 0, dropCount); + } + [TestMethod] [RunsOnUIThread] [DataRow(true)]