Skip to content
4 changes: 2 additions & 2 deletions src/ElectronNET.API/API/WebContents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public bool IsDevToolsFocused()
/// Get system printers.
/// </summary>
/// <returns>printers</returns>
public Task<PrinterInfo[]> GetPrintersAsync() => this.InvokeAsyncWithTimeout<PrinterInfo[]>(5_000);
public Task<PrinterInfo[]> GetPrintersAsync() => this.InvokeAsyncWithTimeout<PrinterInfo[]>(8_000);

/// <summary>
/// Prints window's web page.
Expand Down Expand Up @@ -388,7 +388,7 @@ public void SetAudioMuted(bool muted)
/// Returns string - The user agent for this web page.
/// </summary>
/// <returns></returns>
public Task<string> GetUserAgentAsync() => InvokeAsync<string>();
public Task<string> GetUserAgentAsync() => InvokeAsyncWithTimeout<string>(3000);
Comment thread
FlorianRappl marked this conversation as resolved.
Outdated

/// <summary>
/// Overrides the user agent for this web page.
Expand Down
61 changes: 41 additions & 20 deletions src/ElectronNET.IntegrationTests/Tests/BrowserWindowTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace ElectronNET.IntegrationTests.Tests
{
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using ElectronNET.API;
using ElectronNET.API.Entities;
Expand Down Expand Up @@ -82,12 +81,28 @@ public async Task Can_set_and_get_content_bounds()
[Fact(Timeout = 20000)]
public async Task Show_hide_visibility_roundtrip()
{
this.fx.MainWindow.Show();
await Task.Delay(500);
(await this.fx.MainWindow.IsVisibleAsync()).Should().BeTrue();
this.fx.MainWindow.Hide();
await Task.Delay(500);
(await this.fx.MainWindow.IsVisibleAsync()).Should().BeFalse();
BrowserWindow window = null;

try
{
window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = true }, "about:blank");

await Task.Delay(100);

window.Show();

await Task.Delay(500);
(await window.IsVisibleAsync()).Should().BeTrue();

window.Hide();
await Task.Delay(500);

(await window.IsVisibleAsync()).Should().BeFalse();
}
finally
{
window?.Destroy();
}
}

[Fact(Timeout = 20000)]
Expand Down Expand Up @@ -120,22 +135,28 @@ public async Task MenuBar_auto_hide_and_visibility()
[Fact(Timeout = 20000)]
public async Task ReadyToShow_event_fires_after_content_ready()
{
var window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false }, "about:blank");
var tcs = new TaskCompletionSource();
window.OnReadyToShow += () => tcs.TrySetResult();
BrowserWindow window = null;

// Trigger a navigation and wait for DOM ready so the renderer paints, which emits ready-to-show
var domReadyTcs = new TaskCompletionSource();
window.WebContents.OnDomReady += () => domReadyTcs.TrySetResult();
await Task.Delay(500);
await window.WebContents.LoadURLAsync("about:blank");
await domReadyTcs.Task;
try
{
window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false }, "about:blank");
var tcs = new TaskCompletionSource();
window.OnReadyToShow += () => tcs.TrySetResult();

var completed = await Task.WhenAny(tcs.Task, Task.Delay(3000));
completed.Should().Be(tcs.Task);
// Trigger a navigation and wait for DOM ready so the renderer paints, which emits ready-to-show
var domReadyTcs = new TaskCompletionSource();
window.WebContents.OnDomReady += () => domReadyTcs.TrySetResult();
await Task.Delay(500);
await window.WebContents.LoadURLAsync("about:blank");
await domReadyTcs.Task;

// Typical usage is to show once ready
window.Show();
var completed = await Task.WhenAny(tcs.Task, Task.Delay(3000));
Comment thread
softworkz marked this conversation as resolved.
Outdated
completed.Should().Be(tcs.Task);
}
finally
{
window?.Destroy();
}
}

[Fact(Timeout = 20000)]
Comment thread
FlorianRappl marked this conversation as resolved.
Outdated
Expand Down
2 changes: 0 additions & 2 deletions src/ElectronNET.IntegrationTests/Tests/ScreenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public async Task GetCursorScreenPoint_check()
{
var point = await Electron.Screen.GetCursorScreenPointAsync();
point.Should().NotBeNull();
point.X.Should().BeGreaterThanOrEqualTo(0);
point.Y.Should().BeGreaterThanOrEqualTo(0);
}

[SkippableFact(Timeout = 20000)]
Expand Down
102 changes: 75 additions & 27 deletions src/ElectronNET.IntegrationTests/Tests/WebContentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ElectronNET.IntegrationTests.Tests
{
using ElectronNET.API;
using ElectronNET.API.Entities;

[Collection("ElectronCollection")]
Expand Down Expand Up @@ -77,7 +78,7 @@ public async Task Can_basic_print()
[SkippableFact(Timeout = 20000)]
public async Task GetPrintersAsync_check()
{
Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null, "Skipping printer test in CI environment.");
////Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null, "Skipping printer test in CI environment.");
var info = await fx.MainWindow.WebContents.GetPrintersAsync();
info.Should().NotBeNull();
}
Expand All @@ -97,30 +98,61 @@ public async Task GetSetZoomFactor_check()
[SkippableFact(Timeout = 20000)]
public async Task GetSetZoomLevel_check()
{
Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipping test on Windows CI.");
await fx.MainWindow.WebContents.GetZoomLevelAsync();
var ok = await fx.MainWindow.WebContents.GetZoomLevelAsync();
ok.Should().Be(0);
fx.MainWindow.WebContents.SetZoomLevel(2);
await Task.Delay(500);
ok = await fx.MainWindow.WebContents.GetZoomLevelAsync();
ok.Should().Be(2);
BrowserWindow window = null;

try
{
////Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipping test on Windows CI.");

window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = true }, "about:blank");

await Task.Delay(100);

window.WebContents.SetZoomLevel(0);
await Task.Delay(500);

var ok = await window.WebContents.GetZoomLevelAsync();
ok.Should().Be(0);

window.WebContents.SetZoomLevel(2);
await Task.Delay(500);

ok = await window.WebContents.GetZoomLevelAsync();
ok.Should().Be(2);
}
finally
{
window?.Destroy();
}
}

[SkippableFact(Timeout = 20000)]
public async Task DevTools_check()
{
Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.OSX), "Skipping test on macOS CI.");
fx.MainWindow.WebContents.IsDevToolsOpened().Should().BeFalse();
fx.MainWindow.WebContents.OpenDevTools();
await Task.Delay(500);
fx.MainWindow.WebContents.IsDevToolsOpened().Should().BeTrue();
fx.MainWindow.WebContents.CloseDevTools();
await Task.Delay(500);
fx.MainWindow.WebContents.IsDevToolsOpened().Should().BeFalse();
fx.MainWindow.WebContents.ToggleDevTools();
await Task.Delay(500);
fx.MainWindow.WebContents.IsDevToolsOpened().Should().BeTrue();
BrowserWindow window = null;

try
{
////Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipping test on Windows CI.");

window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = true }, "about:blank");

await Task.Delay(3000);

window.WebContents.IsDevToolsOpened().Should().BeFalse();
window.WebContents.OpenDevTools();
await Task.Delay(5000);

window.WebContents.IsDevToolsOpened().Should().BeTrue();
window.WebContents.CloseDevTools();
await Task.Delay(2000);

window.WebContents.IsDevToolsOpened().Should().BeFalse();
}
finally
{
window?.Destroy();
}
}

[Fact(Timeout = 20000)]
Expand All @@ -144,13 +176,29 @@ public async Task GetSetAudioMuted_check()
[SkippableFact(Timeout = 20000)]
public async Task GetSetUserAgent_check()
{
Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipping test on Windows CI.");
var ok = await fx.MainWindow.WebContents.GetUserAgentAsync();
ok.Should().NotBeNullOrEmpty();
fx.MainWindow.WebContents.SetUserAgent("MyUserAgent/1.0");
await Task.Delay(1000);
ok = await fx.MainWindow.WebContents.GetUserAgentAsync();
ok.Should().Be("MyUserAgent/1.0");
////Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipping test on Windows CI.");

BrowserWindow window = null;

try
{
////Skip.If(Environment.GetEnvironmentVariable("GITHUB_RUN_ID") != null && RuntimeInformation.IsOSPlatform(OSPlatform.Windows), "Skipping test on Windows CI.");

window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = true }, "about:blank");

await Task.Delay(3000);

window.WebContents.SetUserAgent("MyUserAgent/1.0");

await Task.Delay(1000);

var ok = await window.WebContents.GetUserAgentAsync();
ok.Should().Be("MyUserAgent/1.0");
}
finally
{
window?.Destroy();
}
}

}
Expand Down