PointerTests.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Avalonia.Controls;
  4. using Avalonia.UnitTests;
  5. using Avalonia.VisualTree;
  6. using Xunit;
  7. namespace Avalonia.Input.UnitTests
  8. {
  9. public class PointerTests
  10. {
  11. [Fact]
  12. public void On_Capture_Transfer_PointerCaptureLost_Should_Propagate_Up_To_The_Common_Parent()
  13. {
  14. Border initialParent, initialCapture, newParent, newCapture;
  15. var el = new StackPanel
  16. {
  17. Children =
  18. {
  19. (initialParent = new Border { Child = initialCapture = new Border() }),
  20. (newParent = new Border { Child = newCapture = new Border() })
  21. }
  22. };
  23. var receivers = new List<object>();
  24. var root = new TestRoot(el);
  25. foreach (InputElement d in root.GetSelfAndVisualDescendants())
  26. d.PointerCaptureLost += (s, e) => receivers.Add(s);
  27. var pointer = new Pointer(Pointer.GetNextFreeId(), PointerType.Mouse, true);
  28. pointer.Capture(initialCapture);
  29. pointer.Capture(newCapture);
  30. Assert.True(receivers.SequenceEqual(new[] { initialCapture, initialParent }));
  31. receivers.Clear();
  32. pointer.Capture(null);
  33. Assert.True(receivers.SequenceEqual(new object[] { newCapture, newParent, el, root }));
  34. }
  35. }
  36. }