|
|
|
@ -3,17 +3,17 @@ using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Avalonia.Automation; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Interactivity; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Xunit; |
|
|
|
using static Avalonia.IntegrationTests.Win32.UnmanagedMethods; |
|
|
|
|
|
|
|
namespace Avalonia.IntegrationTests.Win32; |
|
|
|
|
|
|
|
public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
{ |
|
|
|
private const double ClientWidth = 200; |
|
|
|
private const double ClientHeight = 200; |
|
|
|
private const int ClientWidth = 200; |
|
|
|
private const int ClientHeight = 200; |
|
|
|
|
|
|
|
private Window? _window; |
|
|
|
|
|
|
|
@ -28,10 +28,13 @@ public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
|
|
|
|
protected abstract WindowDecorations Decorations { get; } |
|
|
|
|
|
|
|
public static MatrixTheoryData<bool, WindowState> States |
|
|
|
=> new([true, false], Enum.GetValues<WindowState>()); |
|
|
|
public static MatrixTheoryData<int, WindowState, bool> States |
|
|
|
=> new( |
|
|
|
Enumerable.Range(0, GetSystemMetrics(SM_CMONITORS)), |
|
|
|
Enum.GetValues<WindowState>(), |
|
|
|
[true, false]); |
|
|
|
|
|
|
|
private async Task InitWindowAsync(WindowState state, bool canResize) |
|
|
|
private async Task InitWindowAsync(int screenIndex, WindowState state, bool canResize) |
|
|
|
{ |
|
|
|
Assert.Null(_window); |
|
|
|
|
|
|
|
@ -44,7 +47,6 @@ public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
Width = ClientWidth, |
|
|
|
Height = ClientHeight, |
|
|
|
WindowStartupLocation = WindowStartupLocation.Manual, |
|
|
|
Position = new PixelPoint(50, 50), |
|
|
|
Content = new Border |
|
|
|
{ |
|
|
|
Background = Brushes.DodgerBlue, |
|
|
|
@ -53,6 +55,9 @@ public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
var screenCenter = _window.Screens.All[screenIndex].Bounds.Center; |
|
|
|
_window.Position = new PixelPoint(screenCenter.X - ClientWidth / 2, screenCenter.Y - ClientHeight / 2); |
|
|
|
|
|
|
|
_window.Show(); |
|
|
|
|
|
|
|
await Window.WhenLoadedAsync(); |
|
|
|
@ -60,9 +65,9 @@ public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(States))] |
|
|
|
public async Task Normal_State_Respects_Client_Size(bool canResize, WindowState initialState) |
|
|
|
public async Task Normal_State_Respects_Client_Size(int screenIndex, WindowState initialState, bool canResize) |
|
|
|
{ |
|
|
|
await InitWindowAsync(initialState, canResize); |
|
|
|
await InitWindowAsync(screenIndex, initialState, canResize); |
|
|
|
|
|
|
|
if (initialState != WindowState.Normal) |
|
|
|
Window.WindowState = WindowState.Normal; |
|
|
|
@ -79,16 +84,16 @@ public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(States))] |
|
|
|
public async Task Maximized_State_Fills_Screen_Working_Area(bool canResize, WindowState initialState) |
|
|
|
public async Task Maximized_State_Fills_Screen_Working_Area(int screenIndex, WindowState initialState, bool canResize) |
|
|
|
{ |
|
|
|
await InitWindowAsync(initialState, canResize); |
|
|
|
await InitWindowAsync(screenIndex, initialState, canResize); |
|
|
|
|
|
|
|
if (initialState != WindowState.Maximized) |
|
|
|
Window.WindowState = WindowState.Maximized; |
|
|
|
|
|
|
|
// The client size should match the screen working area
|
|
|
|
var clientSize = Window.GetWin32ClientSize(); |
|
|
|
var screenWorkingArea = Window.GetScreen().WorkingArea; |
|
|
|
var screenWorkingArea = Window.GetScreenAtIndex(screenIndex).WorkingArea; |
|
|
|
Assert.Equal(screenWorkingArea.Size, clientSize); |
|
|
|
|
|
|
|
VerifyMaximizedState(); |
|
|
|
@ -98,16 +103,16 @@ public abstract class ExtendClientAreaWindowTests : IDisposable |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[MemberData(nameof(States))] |
|
|
|
public async Task FullScreen_State_Fills_Screen(bool canResize, WindowState initialState) |
|
|
|
public async Task FullScreen_State_Fills_Screen(int screenIndex, WindowState initialState, bool canResize) |
|
|
|
{ |
|
|
|
await InitWindowAsync(initialState, canResize); |
|
|
|
await InitWindowAsync(screenIndex, initialState, canResize); |
|
|
|
|
|
|
|
if (initialState != WindowState.FullScreen) |
|
|
|
Window.WindowState = WindowState.FullScreen; |
|
|
|
|
|
|
|
// The client size should match the screen bounds
|
|
|
|
var clientSize = Window.GetWin32ClientSize(); |
|
|
|
var screenBounds = Window.GetScreen().Bounds; |
|
|
|
var screenBounds = Window.GetScreenAtIndex(screenIndex).Bounds; |
|
|
|
Assert.Equal(screenBounds.Width, clientSize.Width); |
|
|
|
Assert.Equal(screenBounds.Height, clientSize.Height); |
|
|
|
|
|
|
|
|