Browse Source

Add WindowOrder_Owned_Window_Stays_InFront_Of_Topmost_Owner integration test

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
pull/22221/head
Max Katz 3 weeks ago
parent
commit
39baee97de
  1. 6
      samples/IntegrationTestApp/TopmostWindowTest.axaml
  2. 23
      samples/IntegrationTestApp/TopmostWindowTest.axaml.cs
  3. 30
      tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs

6
samples/IntegrationTestApp/TopmostWindowTest.axaml

@ -9,8 +9,10 @@
Height="480"> Height="480">
<Grid> <Grid>
<TextBox Name="CurrentPosition" <TextBox Name="CurrentPosition"
Grid.Column="1" VerticalAlignment="Top"
Grid.Row="3" IsReadOnly="True" />
<TextBox Name="CurrentOrder"
VerticalAlignment="Bottom"
IsReadOnly="True" /> IsReadOnly="True" />
<Button HorizontalAlignment="Center" Name="MoveButton" VerticalAlignment="Center" Click="Button_OnClick">Move</Button> <Button HorizontalAlignment="Center" Name="MoveButton" VerticalAlignment="Center" Click="Button_OnClick">Move</Button>
</Grid> </Grid>

23
samples/IntegrationTestApp/TopmostWindowTest.axaml.cs

@ -1,16 +1,39 @@
using System;
using System.Runtime.InteropServices;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading;
namespace IntegrationTestApp; namespace IntegrationTestApp;
public partial class TopmostWindowTest : Window public partial class TopmostWindowTest : Window
{ {
private readonly DispatcherTimer? _timer;
public TopmostWindowTest(string name) public TopmostWindowTest(string name)
{ {
Name = name; Name = name;
InitializeComponent(); InitializeComponent();
PositionChanged += (s, e) => CurrentPosition.Text = $"{Position}"; PositionChanged += (s, e) => CurrentPosition.Text = $"{Position}";
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
_timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(250) };
_timer.Tick += TimerOnTick;
_timer.Start();
}
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_timer?.Stop();
}
private void TimerOnTick(object? sender, EventArgs e)
{
CurrentOrder.Text = MacOSIntegration.GetOrderedIndex(this).ToString();
} }
private void Button_OnClick(object? sender, RoutedEventArgs e) private void Button_OnClick(object? sender, RoutedEventArgs e)

30
tests/Avalonia.IntegrationTests.Appium/WindowTests_MacOS.cs

@ -202,6 +202,30 @@ namespace Avalonia.IntegrationTests.Appium
} }
} }
[PlatformFact(TestPlatforms.MacOS)]
public void WindowOrder_Owned_Window_Stays_InFront_Of_Topmost_Owner()
{
Session.FindElementByAccessibilityId("ShowTopmostWindow").Click();
try
{
Thread.Sleep(1000);
var ownerWindowIndex = GetWindowOrder("OwnerWindow");
var ownedWindowIndex = GetWindowOrder("OwnedWindow");
// orderedIndex counts from the front, so the owned window needs the lower index.
Assert.True(ownedWindowIndex < ownerWindowIndex,
$"Expected the owned window in front of its topmost owner, but the owner was at " +
$"{ownerWindowIndex} and the owned window at {ownedWindowIndex}.");
}
finally
{
CloseWindow("OwnedWindow");
CloseWindow("OwnerWindow");
}
}
[PlatformFact(TestPlatforms.MacOS)] [PlatformFact(TestPlatforms.MacOS)]
public void WindowOrder_Owned_Is_Correct_After_Closing_Window() public void WindowOrder_Owned_Is_Correct_After_Closing_Window()
{ {
@ -441,6 +465,12 @@ namespace Avalonia.IntegrationTests.Appium
return int.Parse(order.Text); return int.Parse(order.Text);
} }
private void CloseWindow(string identifier)
{
GetWindow(identifier).FindElementByAccessibilityId("_XCUI:CloseWindow").Click();
Thread.Sleep(1000);
}
public enum ShowWindowMode public enum ShowWindowMode
{ {
NonOwned, NonOwned,

Loading…
Cancel
Save