PointerTests_MacOS.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Threading;
  3. using OpenQA.Selenium.Appium;
  4. using OpenQA.Selenium.Interactions;
  5. using Xunit;
  6. namespace Avalonia.IntegrationTests.Appium;
  7. [Collection("Default")]
  8. public class PointerTests_MacOS : TestBase, IDisposable
  9. {
  10. public PointerTests_MacOS(DefaultAppFixture fixture)
  11. : base(fixture, "Window Decorations")
  12. {
  13. }
  14. [PlatformFact(TestPlatforms.MacOS)]
  15. public void OSXThickTitleBar_Pointer_Events_Continue_Outside_Window_During_Drag()
  16. {
  17. // issue #15696
  18. SetParameters(true, false, true, true, true);
  19. var showNewWindowDecorations = Session.FindElementByAccessibilityId("ShowNewWindowDecorations");
  20. showNewWindowDecorations.Click();
  21. Thread.Sleep(1000);
  22. var secondaryWindow = Session.GetWindowById("SecondaryWindow");
  23. var titleAreaControl = secondaryWindow.FindElementByAccessibilityId("TitleAreaControl");
  24. Assert.NotNull(titleAreaControl);
  25. new Actions(Session).MoveToElement(secondaryWindow).Perform();
  26. new Actions(Session).MoveToElement(titleAreaControl).Perform();
  27. new Actions(Session).DragAndDropToOffset(titleAreaControl, 50, -100).Perform();
  28. var finalMoveCount = GetMoveCount(secondaryWindow);
  29. var finalReleaseCount = GetReleaseCount(secondaryWindow);
  30. Assert.True(finalMoveCount >= 10, $"Expected at least 10 new mouse move events outside window, got {finalMoveCount})");
  31. Assert.Equal(1, finalReleaseCount);
  32. secondaryWindow.FindElementByAccessibilityId("_XCUI:CloseWindow").Click();
  33. }
  34. [PlatformFact(TestPlatforms.MacOS)]
  35. public void OSXThickTitleBar_Single_Click_Does_Not_Generate_DoubleTapped_Event()
  36. {
  37. SetParameters(true, false, true, true, true);
  38. var showNewWindowDecorations = Session.FindElementByAccessibilityId("ShowNewWindowDecorations");
  39. showNewWindowDecorations.Click();
  40. Thread.Sleep(1000);
  41. var secondaryWindow = Session.GetWindowById("SecondaryWindow");
  42. var titleAreaControl = secondaryWindow.FindElementByAccessibilityId("TitleAreaControl");
  43. Assert.NotNull(titleAreaControl);
  44. // Verify initial state - counters should be 0
  45. var initialDoubleClickCount = GetDoubleClickCount(secondaryWindow);
  46. var initialReleaseCount = GetReleaseCount(secondaryWindow);
  47. var initialMouseDownCount = GetMouseDownCount(secondaryWindow);
  48. Assert.Equal(0, initialDoubleClickCount);
  49. Assert.Equal(0, initialReleaseCount);
  50. Assert.Equal(0, initialMouseDownCount);
  51. // Perform a single click in titlebar area
  52. secondaryWindow.MovePointerOver();
  53. titleAreaControl.MovePointerOver();
  54. titleAreaControl.SendClick();
  55. Thread.Sleep(800);
  56. // After first single click - mouse down = 1, release = 1, double-click = 0
  57. var afterFirstClickMouseDownCount = GetMouseDownCount(secondaryWindow);
  58. var afterFirstClickReleaseCount = GetReleaseCount(secondaryWindow);
  59. var afterFirstClickDoubleClickCount = GetDoubleClickCount(secondaryWindow);
  60. Assert.Equal(1, afterFirstClickMouseDownCount);
  61. Assert.Equal(1, afterFirstClickReleaseCount);
  62. Assert.Equal(0, afterFirstClickDoubleClickCount);
  63. secondaryWindow.FindElementByAccessibilityId("_XCUI:CloseWindow").Click();
  64. }
  65. private void SetParameters(
  66. bool extendClientArea,
  67. bool forceSystemChrome,
  68. bool preferSystemChrome,
  69. bool macOsThickSystemChrome,
  70. bool showTitleAreaControl)
  71. {
  72. var extendClientAreaCheckBox = Session.FindElementByAccessibilityId("WindowExtendClientAreaToDecorationsHint");
  73. var forceSystemChromeCheckBox = Session.FindElementByAccessibilityId("WindowForceSystemChrome");
  74. var preferSystemChromeCheckBox = Session.FindElementByAccessibilityId("WindowPreferSystemChrome");
  75. var macOsThickSystemChromeCheckBox = Session.FindElementByAccessibilityId("WindowMacThickSystemChrome");
  76. var showTitleAreaControlCheckBox = Session.FindElementByAccessibilityId("WindowShowTitleAreaControl");
  77. if (extendClientAreaCheckBox.GetIsChecked() != extendClientArea)
  78. extendClientAreaCheckBox.Click();
  79. if (forceSystemChromeCheckBox.GetIsChecked() != forceSystemChrome)
  80. forceSystemChromeCheckBox.Click();
  81. if (preferSystemChromeCheckBox.GetIsChecked() != preferSystemChrome)
  82. preferSystemChromeCheckBox.Click();
  83. if (macOsThickSystemChromeCheckBox.GetIsChecked() != macOsThickSystemChrome)
  84. macOsThickSystemChromeCheckBox.Click();
  85. if (showTitleAreaControlCheckBox.GetIsChecked() != showTitleAreaControl)
  86. showTitleAreaControlCheckBox.Click();
  87. }
  88. private int GetMoveCount(AppiumWebElement window)
  89. {
  90. var mouseMoveCountTextBox = window.FindElementByAccessibilityId("MouseMoveCount");
  91. return int.Parse(mouseMoveCountTextBox.Text ?? "0");
  92. }
  93. private int GetReleaseCount(AppiumWebElement window)
  94. {
  95. var mouseReleaseCountTextBox = window.FindElementByAccessibilityId("MouseReleaseCount");
  96. return int.Parse(mouseReleaseCountTextBox.Text ?? "0");
  97. }
  98. private int GetMouseDownCount(AppiumWebElement window)
  99. {
  100. var mouseDownCountTextBox = window.FindElementByAccessibilityId("MouseDownCount");
  101. return int.Parse(mouseDownCountTextBox.Text ?? "0");
  102. }
  103. private int GetDoubleClickCount(AppiumWebElement window)
  104. {
  105. var doubleClickCountTextBox = window.FindElementByAccessibilityId("DoubleClickCount");
  106. return int.Parse(doubleClickCountTextBox.Text ?? "0");
  107. }
  108. public void Dispose()
  109. {
  110. SetParameters(false, false, false, false, false);
  111. var applyButton = Session.FindElementByAccessibilityId("ApplyWindowDecorations");
  112. applyButton.Click();
  113. }
  114. }