Introduce common base class for tests

This commit is contained in:
softworkz
2025-12-07 11:56:32 +01:00
parent 153625ba51
commit 95e02e2655
22 changed files with 184 additions and 179 deletions

View File

@@ -0,0 +1,23 @@
namespace ElectronNET.IntegrationTests.Common
{
using ElectronNET.API;
using ElectronNET.API.Entities;
// Base class for integration tests providing shared access to MainWindow and OS platform constants
public abstract class IntegrationTestBase
{
protected IntegrationTestBase(ElectronFixture fixture)
{
Fixture = fixture;
MainWindow = fixture.MainWindow;
}
protected ElectronFixture Fixture { get; }
protected BrowserWindow MainWindow { get; }
// Constants for SupportedOSPlatform attributes
public const string Windows = "Windows";
public const string MacOS = "macOS";
public const string Linux = "Linux";
}
}

View File

@@ -9,14 +9,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class AppTests
public class AppTests : IntegrationTestBase
{
// ReSharper disable once NotAccessedField.Local
private readonly ElectronFixture fx;
public AppTests(ElectronFixture fx)
public AppTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
@@ -64,8 +60,8 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(MacOS)]
[SupportedOSPlatform(Windows)]
public async Task Can_get_login_item_settings()
{
var settings = await Electron.App.GetLoginItemSettingsAsync();
@@ -82,8 +78,8 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(MacOS)]
[SupportedOSPlatform(Windows)]
public async Task Accessibility_support_toggle()
{
Electron.App.SetAccessibilitySupportEnabled(true);
@@ -103,8 +99,8 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform(Linux)]
[SupportedOSPlatform(MacOS)]
public async Task BadgeCount_set_and_reset_where_supported()
{
await Electron.App.SetBadgeCountAsync(2);

View File

@@ -6,13 +6,10 @@
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class AutoUpdaterTests
public class AutoUpdaterTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public AutoUpdaterTests(ElectronFixture fx)
public AutoUpdaterTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]

View File

@@ -5,20 +5,17 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class BrowserViewTests
public class BrowserViewTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public BrowserViewTests(ElectronFixture fx)
public BrowserViewTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
public async Task Create_browser_view_and_adjust_bounds()
{
var view = await Electron.WindowManager.CreateBrowserViewAsync(new BrowserViewConstructorOptions());
this.fx.MainWindow.SetBrowserView(view);
this.MainWindow.SetBrowserView(view);
view.Bounds = new Rectangle { X = 0, Y = 0, Width = 300, Height = 200 };
// Access bounds again (synchronous property fetch)
var current = view.Bounds;

View File

@@ -7,31 +7,28 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class BrowserWindowTests
public class BrowserWindowTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public BrowserWindowTests(ElectronFixture fx)
public BrowserWindowTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
public async Task Can_set_and_get_title()
{
const string title = "Integration Test Title";
this.fx.MainWindow.SetTitle(title);
this.MainWindow.SetTitle(title);
await Task.Delay(500.ms());
var roundTrip = await this.fx.MainWindow.GetTitleAsync();
var roundTrip = await this.MainWindow.GetTitleAsync();
roundTrip.Should().Be(title);
}
[IntegrationFact]
public async Task Can_resize_and_get_size()
{
this.fx.MainWindow.SetSize(643, 482);
this.MainWindow.SetSize(643, 482);
await Task.Delay(500.ms());
var size = await this.fx.MainWindow.GetSizeAsync();
var size = await this.MainWindow.GetSizeAsync();
size.Should().HaveCount(2);
size[0].Should().Be(643);
size[1].Should().Be(482);
@@ -40,18 +37,18 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Can_set_progress_bar_and_clear()
{
this.fx.MainWindow.SetProgressBar(0.5);
this.MainWindow.SetProgressBar(0.5);
// No direct getter; rely on absence of error. Try changing again.
this.fx.MainWindow.SetProgressBar(-1); // clears
this.MainWindow.SetProgressBar(-1); // clears
await Task.Delay(50.ms());
}
[IntegrationFact(SkipOnWsl = true)]
public async Task Can_set_and_get_position()
{
this.fx.MainWindow.SetPosition(134, 246);
this.MainWindow.SetPosition(134, 246);
await Task.Delay(500.ms());
var pos = await this.fx.MainWindow.GetPositionAsync();
var pos = await this.MainWindow.GetPositionAsync();
pos.Should().BeEquivalentTo([134, 246]);
}
@@ -59,9 +56,9 @@ namespace ElectronNET.IntegrationTests.Tests
public async Task Can_set_and_get_bounds()
{
var bounds = new Rectangle { X = 10, Y = 20, Width = 400, Height = 300 };
this.fx.MainWindow.SetBounds(bounds);
this.MainWindow.SetBounds(bounds);
await Task.Delay(500.ms());
var round = await this.fx.MainWindow.GetBoundsAsync();
var round = await this.MainWindow.GetBoundsAsync();
round.Should().BeEquivalentTo(bounds);
round.Width.Should().Be(400);
@@ -72,9 +69,9 @@ namespace ElectronNET.IntegrationTests.Tests
public async Task Can_set_and_get_content_bounds()
{
var bounds = new Rectangle { X = 0, Y = 0, Width = 300, Height = 200 };
this.fx.MainWindow.SetContentBounds(bounds);
this.MainWindow.SetContentBounds(bounds);
await Task.Delay(500.ms());
var round = await this.fx.MainWindow.GetContentBoundsAsync();
var round = await this.MainWindow.GetContentBoundsAsync();
round.Width.Should().BeGreaterThan(0);
round.Height.Should().BeGreaterThan(0);
}
@@ -109,28 +106,28 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task AlwaysOnTop_toggle_and_query()
{
this.fx.MainWindow.SetAlwaysOnTop(true);
this.MainWindow.SetAlwaysOnTop(true);
await Task.Delay(500.ms());
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeTrue();
this.fx.MainWindow.SetAlwaysOnTop(false);
(await this.MainWindow.IsAlwaysOnTopAsync()).Should().BeTrue();
this.MainWindow.SetAlwaysOnTop(false);
await Task.Delay(500.ms());
(await this.fx.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
(await this.MainWindow.IsAlwaysOnTopAsync()).Should().BeFalse();
}
[IntegrationFact]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(Linux)]
[SupportedOSPlatform(Windows)]
public async Task MenuBar_auto_hide_and_visibility()
{
this.fx.MainWindow.SetAutoHideMenuBar(true);
this.MainWindow.SetAutoHideMenuBar(true);
await Task.Delay(500.ms());
(await this.fx.MainWindow.IsMenuBarAutoHideAsync()).Should().BeTrue();
this.fx.MainWindow.SetMenuBarVisibility(false);
(await this.MainWindow.IsMenuBarAutoHideAsync()).Should().BeTrue();
this.MainWindow.SetMenuBarVisibility(false);
await Task.Delay(500.ms());
(await this.fx.MainWindow.IsMenuBarVisibleAsync()).Should().BeFalse();
this.fx.MainWindow.SetMenuBarVisibility(true);
(await this.MainWindow.IsMenuBarVisibleAsync()).Should().BeFalse();
this.MainWindow.SetMenuBarVisibility(true);
await Task.Delay(500.ms());
(await this.fx.MainWindow.IsMenuBarVisibleAsync()).Should().BeTrue();
(await this.MainWindow.IsMenuBarVisibleAsync()).Should().BeTrue();
}
[IntegrationFact]
@@ -196,7 +193,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Progress_bar_and_always_on_top_toggle()
{
var win = this.fx.MainWindow;
var win = this.MainWindow;
win.SetProgressBar(0.5);
await Task.Delay(50.ms());
win.SetProgressBar(0.8, new ProgressBarOptions());
@@ -210,11 +207,11 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("Linux")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(Linux)]
[SupportedOSPlatform(Windows)]
public async Task Menu_bar_visibility_and_auto_hide()
{
var win = this.fx.MainWindow;
var win = this.MainWindow;
win.SetAutoHideMenuBar(true);
await Task.Delay(500.ms());
(await win.IsMenuBarAutoHideAsync()).Should().BeTrue();
@@ -227,21 +224,21 @@ namespace ElectronNET.IntegrationTests.Tests
public async Task Parent_child_relationship_roundtrip()
{
var child = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false, Width = 300, Height = 200 }, "about:blank");
this.fx.MainWindow.SetParentWindow(null); // ensure top-level
child.SetParentWindow(this.fx.MainWindow);
this.MainWindow.SetParentWindow(null); // ensure top-level
child.SetParentWindow(this.MainWindow);
await Task.Delay(500.ms());
var parent = await child.GetParentWindowAsync();
parent.Id.Should().Be(this.fx.MainWindow.Id);
var kids = await this.fx.MainWindow.GetChildWindowsAsync();
parent.Id.Should().Be(this.MainWindow.Id);
var kids = await this.MainWindow.GetChildWindowsAsync();
kids.Select(k => k.Id).Should().Contain(child.Id);
child.Destroy();
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform(MacOS)]
public async Task Represented_filename_and_edited_flags()
{
var win = this.fx.MainWindow;
var win = this.MainWindow;
var temp = Path.Combine(Path.GetTempPath(), "electronnet_test.txt");
File.WriteAllText(temp, "test");
win.SetRepresentedFilename(temp);

View File

@@ -5,14 +5,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class ClipboardTests
public class ClipboardTests : IntegrationTestBase
{
// ReSharper disable once NotAccessedField.Local
private readonly ElectronFixture fx;
public ClipboardTests(ElectronFixture fx)
public ClipboardTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
@@ -34,8 +30,8 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(MacOS)]
[SupportedOSPlatform(Windows)]
public async Task Bookmark_write_and_read()
{
var url = "https://electron-test.com";

View File

@@ -4,25 +4,22 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class CookiesTests
public class CookiesTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public CookiesTests(ElectronFixture fx)
public CookiesTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact(Skip = "Cookie set/get requires navigation to domain; skipping until test harness serves page")]
public async Task Cookie_set_get_remove_sequence()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
var changed = false;
session.Cookies.OnChanged += (cookie, cause, removed) => changed = true;
// Navigate to example.com so cookie domain matches
await this.fx.MainWindow.WebContents.LoadURLAsync("https://example.com");
await this.MainWindow.WebContents.LoadURLAsync("https://example.com");
// Set via renderer for now
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
await Task.Delay(500.ms());
changed.Should().BeTrue();
}

View File

@@ -5,8 +5,12 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class GlobalShortcutTests
public class GlobalShortcutTests : IntegrationTestBase
{
public GlobalShortcutTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact]
public async Task Can_register_and_unregister()
{

View File

@@ -4,8 +4,12 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class HostHookTests
public class HostHookTests : IntegrationTestBase
{
public HostHookTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact(Skip = "Requires HostHook setup; skipping")]
public async Task HostHook_call_returns_value()
{

View File

@@ -5,13 +5,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class IpcMainTests
public class IpcMainTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public IpcMainTests(ElectronFixture fx)
public IpcMainTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
@@ -26,7 +23,7 @@ namespace ElectronNET.IntegrationTests.Tests
tcs.TrySetResult(obj as string);
});
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
var result = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));
@@ -40,7 +37,7 @@ namespace ElectronNET.IntegrationTests.Tests
{
var count = 0;
Electron.IpcMain.Once("ipc-once-test", _ => count++);
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("const {ipcRenderer}=require('electron'); ipcRenderer.send('ipc-once-test','a'); ipcRenderer.send('ipc-once-test','b');");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("const {ipcRenderer}=require('electron'); ipcRenderer.send('ipc-once-test','a'); ipcRenderer.send('ipc-once-test','b');");
await Task.Delay(500.ms());
count.Should().Be(1);
}
@@ -51,7 +48,7 @@ namespace ElectronNET.IntegrationTests.Tests
var fired = false;
await Electron.IpcMain.On("ipc-remove-test", _ => fired = true);
Electron.IpcMain.RemoveAllListeners("ipc-remove-test");
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-remove-test','x')");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-remove-test','x')");
await Task.Delay(400.ms());
fired.Should().BeFalse();
}
@@ -66,7 +63,7 @@ namespace ElectronNET.IntegrationTests.Tests
received = obj;
return "pong";
});
var ret = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
var ret = await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
received.Should().BeOfType<string>();
received.Should().Be("ping");
@@ -78,12 +75,12 @@ namespace ElectronNET.IntegrationTests.Tests
public async Task Ipc_Send_from_main_reaches_renderer()
{
// Listener: store raw arg; if Electron packs differently we will normalize later
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>(@"(function(){ const {ipcRenderer}=require('electron'); ipcRenderer.once('main-to-render',(e,arg)=>{ globalThis.__mainToRender = arg;}); return 'ready'; })();");
Electron.IpcMain.Send(this.fx.MainWindow, "main-to-render", "hello-msg");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>(@"(function(){ const {ipcRenderer}=require('electron'); ipcRenderer.once('main-to-render',(e,arg)=>{ globalThis.__mainToRender = arg;}); return 'ready'; })();");
Electron.IpcMain.Send(this.MainWindow, "main-to-render", "hello-msg");
string value = "";
for (int i = 0; i < 20; i++)
{
var jsVal = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("globalThis.__mainToRender === undefined ? '' : (typeof globalThis.__mainToRender === 'string' ? globalThis.__mainToRender : JSON.stringify(globalThis.__mainToRender))");
var jsVal = await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("globalThis.__mainToRender === undefined ? '' : (typeof globalThis.__mainToRender === 'string' ? globalThis.__mainToRender : JSON.stringify(globalThis.__mainToRender))");
value = jsVal?.ToString() ?? "";
if (!string.IsNullOrEmpty(value))
{

View File

@@ -6,13 +6,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class MenuTests
public class MenuTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public MenuTests(ElectronFixture fx)
public MenuTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
@@ -32,7 +29,7 @@ namespace ElectronNET.IntegrationTests.Tests
};
Electron.Menu.SetApplicationMenu(items);
var targetId = items[0].Submenu[0].Id;
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>($"require('electron').ipcRenderer.send('integration-click-application-menu','{targetId}')");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>($"require('electron').ipcRenderer.send('integration-click-application-menu','{targetId}')");
for (int i = 0; i < 20 && !clicked; i++)
{
await Task.Delay(100.ms());
@@ -44,14 +41,14 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task ContextMenu_popup_registers_items()
{
var win = this.fx.MainWindow;
var win = this.MainWindow;
var ctxClicked = false;
var ctxItems = new[] { new MenuItem { Label = "Ctx", Click = () => ctxClicked = true } };
Electron.Menu.SetContextMenu(win, ctxItems);
var ctxId = ctxItems[0].Id;
// simulate popup then click
Electron.Menu.ContextMenuPopup(win);
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>($"require('electron').ipcRenderer.send('integration-click-context-menu',{win.Id},'{ctxId}')");
await this.MainWindow.WebContents.ExecuteJavaScriptAsync<string>($"require('electron').ipcRenderer.send('integration-click-context-menu',{win.Id},'{ctxId}')");
for (int i = 0; i < 20 && !ctxClicked; i++)
{
await Task.Delay(100.ms());

View File

@@ -3,13 +3,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class MultiEventRegistrationTests
public class MultiEventRegistrationTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public MultiEventRegistrationTests(ElectronFixture fx)
public MultiEventRegistrationTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
private static async Task<bool> WaitAllOrTimeout(TimeSpan timeout, params Task[] tasks)
@@ -22,7 +19,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task BrowserWindow_OnResize_multiple_handlers_called()
{
var win = this.fx.MainWindow;
var win = this.MainWindow;
var h1 = new TaskCompletionSource();
var h2 = new TaskCompletionSource();
var h3 = new TaskCompletionSource();
@@ -46,7 +43,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task WebContents_OnDomReady_multiple_handlers_called()
{
var wc = this.fx.MainWindow.WebContents;
var wc = this.MainWindow.WebContents;
var r1 = new TaskCompletionSource();
var r2 = new TaskCompletionSource();

View File

@@ -1,15 +1,19 @@
using System.Drawing;
using ElectronNET.API.Entities;
using ElectronNET.IntegrationTests.Common;
using System.Runtime.Versioning;
using RectangleEntity = ElectronNET.API.Entities.Rectangle;
namespace ElectronNET.IntegrationTests.Tests
{
using System.Drawing;
using ElectronNET.API.Entities;
using ElectronNET.IntegrationTests.Common;
[SupportedOSPlatform("Windows")]
public class NativeImageTests
[Collection("ElectronCollection")]
[SupportedOSPlatform(Windows)]
public class NativeImageTests : IntegrationTestBase
{
public NativeImageTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact]
public async Task Create_from_bitmap_and_to_png()
{

View File

@@ -7,8 +7,12 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class NativeThemeTests
public class NativeThemeTests : IntegrationTestBase
{
public NativeThemeTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact]
public async Task ThemeSource_roundtrip()
{
@@ -54,8 +58,8 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(MacOS)]
[SupportedOSPlatform(Windows)]
public async Task Should_use_high_contrast_colors_check()
{
var metrics = await Electron.NativeTheme.ShouldUseHighContrastColorsAsync();
@@ -63,8 +67,8 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(MacOS)]
[SupportedOSPlatform(Windows)]
public async Task Should_use_inverted_colors_check()
{
var metrics = await Electron.NativeTheme.ShouldUseInvertedColorSchemeAsync();

View File

@@ -7,8 +7,12 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class NotificationTests
public class NotificationTests : IntegrationTestBase
{
public NotificationTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact]
public async Task Notification_create_check()
{

View File

@@ -4,8 +4,12 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class ProcessTests
public class ProcessTests : IntegrationTestBase
{
public ProcessTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact]
public async Task Process_info_is_accessible()
{

View File

@@ -6,14 +6,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class ScreenTests
public class ScreenTests : IntegrationTestBase
{
// ReSharper disable once NotAccessedField.Local
private readonly ElectronFixture fx;
public ScreenTests(ElectronFixture fx)
public ScreenTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact(SkipOnWsl = true)]
@@ -40,7 +36,7 @@ namespace ElectronNET.IntegrationTests.Tests
}
[IntegrationFact]
[SupportedOSPlatform("macOS")]
[SupportedOSPlatform(MacOS)]
public async Task GetMenuBarWorkArea_check()
{
var area = await Electron.Screen.GetMenuBarWorkAreaAsync();

View File

@@ -4,19 +4,16 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class SessionTests
public class SessionTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public SessionTests(ElectronFixture fx)
public SessionTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
public async Task Session_preloads_roundtrip()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
_ = await session.GetPreloadsAsync();
// Use a dummy path; API should store value
session.SetPreloads(new[] { "/tmp/preload_dummy.js" });
@@ -27,7 +24,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Session_proxy_set_and_resolve()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
// Provide all ctor args (pacScript empty to ignore, proxyRules direct, bypass empty)
await session.SetProxyAsync(new ProxyConfig("", "direct://", ""));
var proxy = await session.ResolveProxyAsync("https://example.com");
@@ -38,7 +35,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Session_clear_cache_and_storage_completes()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
await session.ClearCacheAsync();
await session.ClearStorageDataAsync();
await session.ClearHostResolverCacheAsync();
@@ -50,7 +47,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Session_preloads_set_multiple_and_clear()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
session.SetPreloads(new[] { "/tmp/a.js", "/tmp/b.js" });
var after = await session.GetPreloadsAsync();
after.Should().Contain("/tmp/a.js").And.Contain("/tmp/b.js");
@@ -63,7 +60,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Clear_auth_cache_overloads()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
await session.ClearAuthCacheAsync();
await session.ClearAuthCacheAsync(new RemovePassword("password") { Origin = "https://example.com", Username = "user", Password = "pw", Realm = "realm", Scheme = Scheme.basic });
}
@@ -71,14 +68,14 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Clear_storage_with_options()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
await session.ClearStorageDataAsync(new ClearStorageDataOptions { Storages = new[] { "cookies" }, Quotas = new[] { "temporary" } });
}
[IntegrationFact]
public async Task Enable_disable_network_emulation()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
session.EnableNetworkEmulation(new EnableNetworkEmulationOptions { Offline = false, Latency = 10, DownloadThroughput = 50000, UploadThroughput = 20000 });
session.DisableNetworkEmulation();
}
@@ -86,14 +83,14 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task Flush_storage_data_does_not_throw()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
session.FlushStorageData();
}
[IntegrationFact]
public async Task Set_user_agent_affects_new_navigation()
{
var session = this.fx.MainWindow.WebContents.Session;
var session = this.MainWindow.WebContents.Session;
// Set UA and verify via session API (navigator.userAgent on existing WebContents may not reflect the override)
session.SetUserAgent("IntegrationAgent/1.0");
var ua = await session.GetUserAgent();

View File

@@ -4,8 +4,12 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class ShellTests
public class ShellTests : IntegrationTestBase
{
public ShellTests(ElectronFixture fx) : base(fx)
{
}
[IntegrationFact(Skip = "This can keep the test process hanging until the e-mail window is closed")]
public async Task OpenExternal_invalid_scheme_returns_error_or_empty()
{

View File

@@ -5,26 +5,23 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class ThumbarButtonTests
public class ThumbarButtonTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public ThumbarButtonTests(ElectronFixture fx)
public ThumbarButtonTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(Windows)]
public async Task SetThumbarButtons_returns_success()
{
var btn = new ThumbarButton("icon.png") { Tooltip = "Test" };
var success = await this.fx.MainWindow.SetThumbarButtonsAsync(new[] { btn });
var success = await this.MainWindow.SetThumbarButtonsAsync(new[] { btn });
success.Should().BeTrue();
}
[IntegrationFact]
[SupportedOSPlatform("Windows")]
[SupportedOSPlatform(Windows)]
public async Task Thumbar_button_click_invokes_callback()
{
var icon = Path.Combine(Directory.GetCurrentDirectory(), "ElectronNET.WebApp", "wwwroot", "icon.png");
@@ -35,7 +32,7 @@ namespace ElectronNET.IntegrationTests.Tests
var tcs = new TaskCompletionSource<bool>();
var btn = new ThumbarButton(icon) { Tooltip = "Test", Flags = new[] { ThumbarButtonFlag.enabled }, Click = () => tcs.TrySetResult(true) };
var ok = await this.fx.MainWindow.SetThumbarButtonsAsync(new[] { btn });
var ok = await this.MainWindow.SetThumbarButtonsAsync(new[] { btn });
ok.Should().BeTrue();
}
}

View File

@@ -4,14 +4,10 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class TrayTests
public class TrayTests : IntegrationTestBase
{
// ReSharper disable once NotAccessedField.Local
private readonly ElectronFixture fx;
public TrayTests(ElectronFixture fx)
public TrayTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]

View File

@@ -8,19 +8,16 @@ namespace ElectronNET.IntegrationTests.Tests
using ElectronNET.IntegrationTests.Common;
[Collection("ElectronCollection")]
public class WebContentsTests
public class WebContentsTests : IntegrationTestBase
{
private readonly ElectronFixture fx;
public WebContentsTests(ElectronFixture fx)
public WebContentsTests(ElectronFixture fx) : base(fx)
{
this.fx = fx;
}
[IntegrationFact]
public async Task Can_get_url_after_navigation()
{
var wc = this.fx.MainWindow.WebContents;
var wc = this.MainWindow.WebContents;
await wc.LoadURLAsync("https://example.com");
var url = await wc.GetUrl();
url.Should().Contain("example.com");
@@ -29,7 +26,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task ExecuteJavaScript_returns_title()
{
var wc = this.fx.MainWindow.WebContents;
var wc = this.MainWindow.WebContents;
await wc.LoadURLAsync("https://example.com");
var title = await wc.ExecuteJavaScriptAsync<string>("document.title");
title.Should().NotBeNull();
@@ -38,7 +35,7 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task DomReady_event_fires()
{
var wc = this.fx.MainWindow.WebContents;
var wc = this.MainWindow.WebContents;
var fired = false;
wc.OnDomReady += () => fired = true;
await wc.LoadURLAsync("https://example.com");
@@ -50,11 +47,11 @@ namespace ElectronNET.IntegrationTests.Tests
public async Task Can_print_to_pdf()
{
var html = "data:text/html,<html><body><h1>PDF Test</h1><p>Electron.NET</p></body></html>";
await this.fx.MainWindow.WebContents.LoadURLAsync(html);
await this.MainWindow.WebContents.LoadURLAsync(html);
var tmp = Path.Combine(Path.GetTempPath(), $"electronnet_pdf_{Guid.NewGuid():N}.pdf");
try
{
var ok = await this.fx.MainWindow.WebContents.PrintToPDFAsync(tmp);
var ok = await this.MainWindow.WebContents.PrintToPDFAsync(tmp);
ok.Should().BeTrue();
File.Exists(tmp).Should().BeTrue();
new FileInfo(tmp).Length.Should().BeGreaterThan(0);
@@ -72,27 +69,27 @@ namespace ElectronNET.IntegrationTests.Tests
public async Task Can_basic_print()
{
var html = "data:text/html,<html><body><h2>Print Test</h2></body></html>";
await this.fx.MainWindow.WebContents.LoadURLAsync(html);
var ok = await this.fx.MainWindow.WebContents.PrintAsync(new PrintOptions { Silent = true, PrintBackground = true });
await this.MainWindow.WebContents.LoadURLAsync(html);
var ok = await this.MainWindow.WebContents.PrintAsync(new PrintOptions { Silent = true, PrintBackground = true });
ok.Should().BeTrue();
}
[IntegrationFact]
public async Task GetPrintersAsync_check()
{
var info = await fx.MainWindow.WebContents.GetPrintersAsync();
var info = await this.MainWindow.WebContents.GetPrintersAsync();
info.Should().NotBeNull();
}
[IntegrationFact]
public async Task GetSetZoomFactor_check()
{
await fx.MainWindow.WebContents.GetZoomFactorAsync();
var ok = await fx.MainWindow.WebContents.GetZoomFactorAsync();
await this.MainWindow.WebContents.GetZoomFactorAsync();
var ok = await this.MainWindow.WebContents.GetZoomFactorAsync();
ok.Should().BeGreaterThan(0.0);
fx.MainWindow.WebContents.SetZoomFactor(2.0);
this.MainWindow.WebContents.SetZoomFactor(2.0);
await Task.Delay(500.ms());
ok = await fx.MainWindow.WebContents.GetZoomFactorAsync();
ok = await this.MainWindow.WebContents.GetZoomFactorAsync();
ok.Should().Be(2.0);
}
@@ -155,18 +152,18 @@ namespace ElectronNET.IntegrationTests.Tests
[IntegrationFact]
public async Task GetSetAudioMuted_check()
{
fx.MainWindow.WebContents.SetAudioMuted(true);
this.MainWindow.WebContents.SetAudioMuted(true);
await Task.Delay(500.ms());
var ok = await fx.MainWindow.WebContents.IsAudioMutedAsync();
var ok = await this.MainWindow.WebContents.IsAudioMutedAsync();
ok.Should().BeTrue();
fx.MainWindow.WebContents.SetAudioMuted(false);
this.MainWindow.WebContents.SetAudioMuted(false);
await Task.Delay(500.ms());
ok = await fx.MainWindow.WebContents.IsAudioMutedAsync();
ok = await this.MainWindow.WebContents.IsAudioMutedAsync();
ok.Should().BeFalse();
// Assuming no audio is playing, IsCurrentlyAudibleAsync should return false
// there is no way to play audio in this test
ok = await fx.MainWindow.WebContents.IsCurrentlyAudibleAsync();
ok = await this.MainWindow.WebContents.IsCurrentlyAudibleAsync();
ok.Should().BeFalse();
}