Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Test that quitting and Windows signing out remember the main window (#586)

cre8ive-marketing777da408dedc
diff --git a/tests/Filee.App.Tests/MainWindowPlacementTests.cs b/tests/Filee.App.Tests/MainWindowPlacementTests.cs
index 4299d2e9..049a1d0e 100644
--- a/tests/Filee.App.Tests/MainWindowPlacementTests.cs
+++ b/tests/Filee.App.Tests/MainWindowPlacementTests.cs
@@ -1,7 +1,9 @@
// The main window opens where it was, also after Filee restarts (#586), and always fits the screen it opens on: a
// small or scaled screen gets a window that fits instead of one that runs off its bottom.
+using System.Reflection;
using Avalonia;
+using Avalonia.Controls;
using Avalonia.Headless.XUnit;
using Avalonia.Threading;
using Filee.App.Services;
@@ -119,6 +121,44 @@ public class MainWindowPlacementTests
}
}
+ [AvaloniaTheory]
+ [InlineData(WindowCloseReason.ApplicationShutdown, true)] // Quit from the tray (lifetime.Shutdown())
+ [InlineData(WindowCloseReason.OSShutdown, false)] // Windows signing out or shutting down
+ public void Quitting_while_the_window_is_open_remembers_it_too(WindowCloseReason reason, bool programmatic)
+ {
+ TestServices.EnsureInitialized("en");
+ var store = AppHost.Get<UserDataStore>();
+ var before = store.Settings.MainWindow;
+ var service = ActivatorUtilities.CreateInstance<WindowService>(AppHost.Services);
+ try
+ {
+ store.Settings.MainWindow = null;
+ service.ShowMain();
+ var main = service.Main!;
+ main.Width = 940;
+ main.Height = 620;
+ Pump();
+
+ // What ClassicDesktopStyleApplicationLifetime does to every window when Filee quits or Windows ends the
+ // session: Window.CloseCore with that reason (Avalonia 12, DoShutdown).
+ typeof(Window).GetMethod("CloseCore", BindingFlags.Instance | BindingFlags.NonPublic, [typeof(WindowCloseReason), typeof(bool), typeof(bool)])!
+ .Invoke(main, [reason, programmatic, false]);
+ Pump();
+
+ Assert.False(main.IsVisible);
+ Assert.True(main.IsReleased); // closed for good, not to the tray
+ var reloaded = new UserDataStore(store.Directory);
+ reloaded.Load();
+ var saved = Assert.IsType<WindowBounds>(reloaded.Settings.MainWindow);
+ Assert.Equal((940.0, 620.0, false), (saved.Width, saved.Height, saved.Maximized));
+ }
+ finally
+ {
+ store.Settings.MainWindow = before;
+ store.SaveSettings();
+ }
+ }
+
private static void Pump()
{
for (var i = 0; i < 10; i++)