From d0da2319ab7faca4c07b5ba3c45178dcd1096374 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Fri, 15 Nov 2024 01:01:36 +0200 Subject: [PATCH] test: add a runtime regression test --- .../Tests/Windows_UI_Xaml/Given_UIElement.cs | 56 +++++++++++++++++++ 1 file changed, 56 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..99e6f0786d26 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 @@ -1772,6 +1772,62 @@ await UITestHelper.Load(new StackPanel Assert.AreEqual(waitAfterRelease ? 1 : 0, dropCount); } + [TestMethod] + [RunsOnUIThread] + [DataRow(true)] + [DataRow(false)] +#if !HAS_INPUT_INJECTOR + [Ignore("InputInjector is not supported on this platform.")] +#endif + public async Task When_CanDrag_Child_And_Parent(bool childCanDrag) + { + var child = new Rectangle + { + Fill = new SolidColorBrush(Microsoft.UI.Colors.LightBlue), + Width = 100, + Height = 80, + CanDrag = childCanDrag + }; + var parent = new Frame + { + Background = new SolidColorBrush(Microsoft.UI.Colors.LightCoral), + Width = 400, + Height = 300, + CanDrag = true, + Content = child + }; + + var parentDragStartingCount = 0; + var childDragStartingCount = 0; + parent.DragStarting += (_, _) => parentDragStartingCount++; + child.DragStarting += (_, _) => childDragStartingCount++; + + await UITestHelper.Load(parent); + + var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException("Failed to init the InputInjector"); + using var mouse = injector.GetMouse(); + + mouse.MoveTo(child.GetAbsoluteBoundsRect().GetCenter()); + await UITestHelper.WaitForIdle(); + mouse.Press(); + await UITestHelper.WaitForIdle(); + mouse.MoveTo(child.GetAbsoluteBoundsRect().GetCenter() + new Windows.Foundation.Point(20, 0), steps: 10); + await UITestHelper.WaitForIdle(); + mouse.Release(); + await UITestHelper.WaitForIdle(); + + if (childCanDrag) + { + Assert.AreEqual(1, childDragStartingCount); + Assert.AreEqual(0, parentDragStartingCount); + } + else + { + Assert.AreEqual(0, childDragStartingCount); + Assert.AreEqual(1, parentDragStartingCount); + } + } + #endregion #endif }