Skip to content

Commit

Permalink
Added failing tests for #10650.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokys committed Mar 15, 2023
1 parent 0a653b9 commit d87e7fa
Showing 1 changed file with 81 additions and 4 deletions.
85 changes: 81 additions & 4 deletions tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,85 @@ public void Window_Has_Disabled_Zoom_Button_When_CanResize_Is_False(ShowWindowMo
}
}

[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}");
Expand All @@ -382,6 +450,15 @@ private IDisposable OpenWindow(
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();
}

Expand Down

0 comments on commit d87e7fa

Please sign in to comment.