diff --git a/samples/IntegrationTestApp/ShowWindowTest.axaml b/samples/IntegrationTestApp/ShowWindowTest.axaml index a263d8ab46..a861130cd0 100644 --- a/samples/IntegrationTestApp/ShowWindowTest.axaml +++ b/samples/IntegrationTestApp/ShowWindowTest.axaml @@ -3,15 +3,18 @@ x:Class="IntegrationTestApp.ShowWindowTest" Name="SecondaryWindow" Title="Show Window Test"> - + - + - + - + @@ -21,5 +24,13 @@ + + + + Normal + Minimized + Maximized + Fullscreen + diff --git a/samples/IntegrationTestApp/ShowWindowTest.axaml.cs b/samples/IntegrationTestApp/ShowWindowTest.axaml.cs index 720f7b1c12..69b6d64557 100644 --- a/samples/IntegrationTestApp/ShowWindowTest.axaml.cs +++ b/samples/IntegrationTestApp/ShowWindowTest.axaml.cs @@ -11,6 +11,7 @@ namespace IntegrationTestApp public ShowWindowTest() { InitializeComponent(); + DataContext = this; } private void InitializeComponent() @@ -21,9 +22,6 @@ namespace IntegrationTestApp protected override void OnOpened(EventArgs e) { base.OnOpened(e); - this.GetControl("ClientSize").Text = $"{Width}, {Height}"; - this.GetControl("FrameSize").Text = $"{FrameSize}"; - this.GetControl("Position").Text = $"{Position}"; this.GetControl("ScreenRect").Text = $"{Screens.ScreenFromVisual(this)?.WorkingArea}"; this.GetControl("Scaling").Text = $"{PlatformImpl?.DesktopScaling}"; diff --git a/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs b/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs index f1a625dbb4..727a0b5406 100644 --- a/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs +++ b/tests/Avalonia.IntegrationTests.Appium/WindowTests.cs @@ -26,28 +26,60 @@ namespace Avalonia.IntegrationTests.Appium public void StartupLocation(PixelSize? size, ShowWindowMode mode, WindowStartupLocation location) { using var window = OpenWindow(size, mode, location); - var clientSize = Size.Parse(_session.FindElementByAccessibilityId("ClientSize").Text); - var frameSize = Size.Parse(_session.FindElementByAccessibilityId("FrameSize").Text); - var position = PixelPoint.Parse(_session.FindElementByAccessibilityId("Position").Text); - var screenRect = PixelRect.Parse(_session.FindElementByAccessibilityId("ScreenRect").Text); - var scaling = double.Parse(_session.FindElementByAccessibilityId("Scaling").Text); + var info = GetWindowInfo(); - Assert.True(frameSize.Width >= clientSize.Width, "Expected frame width >= client width."); - Assert.True(frameSize.Height > clientSize.Height, "Expected frame height > client height."); + Assert.True(info.FrameSize.Width >= info.ClientSize.Width, "Expected frame width >= client width."); + Assert.True(info.FrameSize.Height > info.ClientSize.Height, "Expected frame height > client height."); - var frameRect = new PixelRect(position, PixelSize.FromSize(frameSize, scaling)); + var frameRect = new PixelRect(info.Position, PixelSize.FromSize(info.FrameSize, info.Scaling)); switch (location) { case WindowStartupLocation.CenterScreen: { - var expected = screenRect.CenterRect(frameRect); + var expected = info.ScreenRect.CenterRect(frameRect); AssertCloseEnough(expected.Position, frameRect.Position); break; } } } - + + + [Theory] + [InlineData(ShowWindowMode.NonOwned)] + [InlineData(ShowWindowMode.Owned)] + [InlineData(ShowWindowMode.Modal)] + public void WindowState(ShowWindowMode mode) + { + using var window = OpenWindow(null, mode, WindowStartupLocation.Manual); + var windowState = _session.FindElementByAccessibilityId("WindowState"); + var original = GetWindowInfo(); + + Assert.Equal("Normal", windowState.GetComboBoxValue()); + + windowState.Click(); + _session.FindElementByName("Maximized").SendClick(); + Assert.Equal("Maximized", windowState.GetComboBoxValue()); + + windowState.Click(); + _session.FindElementByName("Normal").SendClick(); + + var current = GetWindowInfo(); + Assert.Equal(original.Position, current.Position); + Assert.Equal(original.FrameSize, current.FrameSize); + + windowState.Click(); + _session.FindElementByName("Fullscreen").SendClick(); + Assert.Equal("Fullscreen", windowState.GetComboBoxValue()); + + windowState.Click(); + _session.FindElementByName("Normal").SendClick(); + + current = GetWindowInfo(); + Assert.Equal(original.Position, current.Position); + Assert.Equal(original.FrameSize, current.FrameSize); + } + public static TheoryData StartupLocationData() { var sizes = new PixelSize?[] { null, new PixelSize(400, 300) }; @@ -115,11 +147,29 @@ namespace Avalonia.IntegrationTests.Appium return showButton.OpenWindowWithClick(); } + private WindowInfo GetWindowInfo() + { + return new( + Size.Parse(_session.FindElementByAccessibilityId("ClientSize").Text), + Size.Parse(_session.FindElementByAccessibilityId("FrameSize").Text), + PixelPoint.Parse(_session.FindElementByAccessibilityId("Position").Text), + PixelRect.Parse(_session.FindElementByAccessibilityId("ScreenRect").Text), + double.Parse(_session.FindElementByAccessibilityId("Scaling").Text)); + + } + public enum ShowWindowMode { NonOwned, Owned, Modal } + + private record WindowInfo( + Size ClientSize, + Size FrameSize, + PixelPoint Position, + PixelRect ScreenRect, + double Scaling); } }