Browse Source

Added failing tests for WindowState on mac.

pull/8405/head
Steven Kirk 4 years ago
parent
commit
328aef882b
  1. 19
      samples/IntegrationTestApp/ShowWindowTest.axaml
  2. 4
      samples/IntegrationTestApp/ShowWindowTest.axaml.cs
  3. 70
      tests/Avalonia.IntegrationTests.Appium/WindowTests.cs

19
samples/IntegrationTestApp/ShowWindowTest.axaml

@ -3,15 +3,18 @@
x:Class="IntegrationTestApp.ShowWindowTest"
Name="SecondaryWindow"
Title="Show Window Test">
<Grid ColumnDefinitions="Auto,Auto" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<Grid ColumnDefinitions="Auto,Auto" RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<Label Grid.Column="0" Grid.Row="1">Client Size</Label>
<TextBox Name="ClientSize" Grid.Column="1" Grid.Row="1" IsReadOnly="True"/>
<TextBox Name="ClientSize" Grid.Column="1" Grid.Row="1" IsReadOnly="True"
Text="{Binding ClientSize, Mode=OneWay}"/>
<Label Grid.Column="0" Grid.Row="2">Frame Size</Label>
<TextBox Name="FrameSize" Grid.Column="1" Grid.Row="2" IsReadOnly="True"/>
<TextBox Name="FrameSize" Grid.Column="1" Grid.Row="2" IsReadOnly="True"
Text="{Binding FrameSize, Mode=OneWay}"/>
<Label Grid.Column="0" Grid.Row="3">Position</Label>
<TextBox Name="Position" Grid.Column="1" Grid.Row="3" IsReadOnly="True"/>
<TextBox Name="Position" Grid.Column="1" Grid.Row="3" IsReadOnly="True"
Text="{Binding Position, Mode=OneWay}"/>
<Label Grid.Column="0" Grid.Row="4">Owner Rect</Label>
<TextBox Name="OwnerRect" Grid.Column="1" Grid.Row="4" IsReadOnly="True"/>
@ -21,5 +24,13 @@
<Label Grid.Column="0" Grid.Row="6">Scaling</Label>
<TextBox Name="Scaling" Grid.Column="1" Grid.Row="6" IsReadOnly="True"/>
<Label Grid.Column="0" Grid.Row="7">WindowState</Label>
<ComboBox Name="WindowState" Grid.Column="1" Grid.Row="7" SelectedIndex="{Binding WindowState}">
<ComboBoxItem>Normal</ComboBoxItem>
<ComboBoxItem>Minimized</ComboBoxItem>
<ComboBoxItem>Maximized</ComboBoxItem>
<ComboBoxItem>Fullscreen</ComboBoxItem>
</ComboBox>
</Grid>
</Window>

4
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<TextBox>("ClientSize").Text = $"{Width}, {Height}";
this.GetControl<TextBox>("FrameSize").Text = $"{FrameSize}";
this.GetControl<TextBox>("Position").Text = $"{Position}";
this.GetControl<TextBox>("ScreenRect").Text = $"{Screens.ScreenFromVisual(this)?.WorkingArea}";
this.GetControl<TextBox>("Scaling").Text = $"{PlatformImpl?.DesktopScaling}";

70
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<PixelSize?, ShowWindowMode, WindowStartupLocation> 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);
}
}

Loading…
Cancel
Save