From d87e7faa60bb00fef669dd6c591d3adeb447e4e6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 15 Mar 2023 17:53:46 +0100 Subject: [PATCH] Added failing tests for #10650. --- .../WindowTests_MacOS.cs | 85 ++++++++++++++++++- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs index 9c1f993e0f..d56f798722 100644 --- a/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs +++ b/tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs @@ -352,17 +352,85 @@ namespace Avalonia.IntegrationTests.Appium } } + [Fact] + public void Toggling_SystemDecorations_Should_Preserve_ExtendClientArea() + { + // #10650 + using (OpenWindow(extendClientArea: true)) + { + var secondaryWindow = GetWindow("SecondaryWindow"); + + // The XPath of the title bar text _should_ be "XCUIElementTypeStaticText" + // but Appium seems to put a fake node between the window and the title bar + // https://stackoverflow.com/a/71914227/6448 + var titleBar = secondaryWindow.FindElementsByXPath("/*/XCUIElementTypeStaticText").Count; + + Assert.Equal(0, titleBar); + + secondaryWindow.FindElementByAccessibilityId("CurrentSystemDecorations").Click(); + _session.FindElementByAccessibilityId("SystemDecorationsNone").SendClick(); + secondaryWindow.FindElementByAccessibilityId("CurrentSystemDecorations").Click(); + _session.FindElementByAccessibilityId("SystemDecorationsFull").SendClick(); + + titleBar = secondaryWindow.FindElementsByXPath("/*/XCUIElementTypeStaticText").Count; + Assert.Equal(0, titleBar); + } + } + + [Theory] + [InlineData(SystemDecorations.None)] + [InlineData(SystemDecorations.BorderOnly)] + [InlineData(SystemDecorations.Full)] + public void ExtendClientArea_SystemDecorations_Shows_Correct_Buttons(SystemDecorations decorations) + { + // #10650 + using (OpenWindow(extendClientArea: true, systemDecorations: decorations)) + { + var secondaryWindow = GetWindow("SecondaryWindow"); + + try + { + var chrome = secondaryWindow.GetChromeButtons(); + + if (decorations == SystemDecorations.Full) + { + Assert.NotNull(chrome.Close); + Assert.NotNull(chrome.Minimize); + Assert.NotNull(chrome.FullScreen); + } + else + { + Assert.Null(chrome.Close); + Assert.Null(chrome.Minimize); + Assert.Null(chrome.FullScreen); + } + } + finally + { + if (decorations != SystemDecorations.Full) + { + secondaryWindow.FindElementByAccessibilityId("CurrentSystemDecorations").Click(); + _session.FindElementByAccessibilityId("SystemDecorationsFull").SendClick(); + } + } + } + } + private IDisposable OpenWindow( - PixelSize? size, - ShowWindowMode mode, - WindowStartupLocation location, - bool canResize = true) + PixelSize? size = null, + ShowWindowMode mode = ShowWindowMode.NonOwned, + WindowStartupLocation location = WindowStartupLocation.Manual, + bool canResize = true, + SystemDecorations systemDecorations = SystemDecorations.Full, + bool extendClientArea = false) { var sizeTextBox = _session.FindElementByAccessibilityId("ShowWindowSize"); var modeComboBox = _session.FindElementByAccessibilityId("ShowWindowMode"); var locationComboBox = _session.FindElementByAccessibilityId("ShowWindowLocation"); var canResizeCheckBox = _session.FindElementByAccessibilityId("ShowWindowCanResize"); var showButton = _session.FindElementByAccessibilityId("ShowWindow"); + var systemDecorationsComboBox = _session.FindElementByAccessibilityId("ShowWindowSystemDecorations"); + var extendClientAreaCheckBox = _session.FindElementByAccessibilityId("ShowWindowExtendClientAreaToDecorationsHint"); if (size.HasValue) sizeTextBox.SendKeys($"{size.Value.Width}, {size.Value.Height}"); @@ -382,6 +450,15 @@ namespace Avalonia.IntegrationTests.Appium if (canResizeCheckBox.GetIsChecked() != canResize) canResizeCheckBox.Click(); + if (systemDecorationsComboBox.GetComboBoxValue() != systemDecorations.ToString()) + { + systemDecorationsComboBox.Click(); + _session.FindElementByName(systemDecorations.ToString()).SendClick(); + } + + if (extendClientAreaCheckBox.GetIsChecked() != extendClientArea) + extendClientAreaCheckBox.Click(); + return showButton.OpenWindowWithClick(); }