mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-07-21 08:05:57 +00:00
refactor: Migrated from Newtonsoft.Json to System.Text.Json, missing one test passing
This commit is contained in:
@@ -48,7 +48,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
this.fx.MainWindow.SetPosition(134, 246);
|
||||
await Task.Delay(500);
|
||||
var pos = await this.fx.MainWindow.GetPositionAsync();
|
||||
pos.Should().BeEquivalentTo(new[] { 134, 246 });
|
||||
pos.Should().BeEquivalentTo([134, 246]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -134,7 +134,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
window.WebContents.OnDomReady += () => domReadyTcs.TrySetResult();
|
||||
await window.WebContents.LoadURLAsync("about:blank");
|
||||
await domReadyTcs.Task;
|
||||
await window.WebContents.ExecuteJavaScriptAsync("document.title='NewTitle';");
|
||||
await window.WebContents.ExecuteJavaScriptAsync<string>("document.title='NewTitle';");
|
||||
|
||||
// Wait for event up to a short timeout
|
||||
var completed2 = await Task.WhenAny(tcs.Task, Task.Delay(3000));
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
// Navigate to example.com so cookie domain matches
|
||||
await this.fx.MainWindow.WebContents.LoadURLAsync("https://example.com");
|
||||
// Set via renderer for now
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("document.cookie='integration_cookie=1;path=/';");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("document.cookie='integration_cookie=1;path=/';");
|
||||
await Task.Delay(500);
|
||||
changed.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
await Electron.IpcMain.On("ipc-on-test", obj => tcs.TrySetResult(obj?.ToString() ?? string.Empty));
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-on-test','payload123')");
|
||||
var result = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
result.Should().Be("payload123");
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
var count = 0;
|
||||
Electron.IpcMain.Once("ipc-once-test", _ => count++);
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("const {ipcRenderer}=require('electron'); ipcRenderer.send('ipc-once-test','a'); ipcRenderer.send('ipc-once-test','b');");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("const {ipcRenderer}=require('electron'); ipcRenderer.send('ipc-once-test','a'); ipcRenderer.send('ipc-once-test','b');");
|
||||
await Task.Delay(500);
|
||||
count.Should().Be(1);
|
||||
}
|
||||
@@ -37,7 +37,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("require('electron').ipcRenderer.send('ipc-remove-test','x')");
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.send('ipc-remove-test','x')");
|
||||
await Task.Delay(400);
|
||||
fired.Should().BeFalse();
|
||||
}
|
||||
@@ -45,12 +45,12 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
[Fact]
|
||||
public async Task Ipc_OnSync_returns_value()
|
||||
{
|
||||
Electron.IpcMain.OnSync("ipc-sync-test", obj =>
|
||||
Electron.IpcMain.OnSync("ipc-sync-test", (obj) =>
|
||||
{
|
||||
obj.Should().NotBeNull();
|
||||
return "pong";
|
||||
});
|
||||
var ret = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
|
||||
var ret = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("require('electron').ipcRenderer.sendSync('ipc-sync-test','ping')");
|
||||
ret.Should().Be("pong");
|
||||
}
|
||||
|
||||
@@ -58,12 +58,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(@"(function(){ const {ipcRenderer}=require('electron'); ipcRenderer.once('main-to-render',(e,arg)=>{ globalThis.__mainToRender = arg;}); return 'ready'; })();");
|
||||
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");
|
||||
string value = "";
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
var jsVal = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync("globalThis.__mainToRender === undefined ? '' : (typeof globalThis.__mainToRender === 'string' ? globalThis.__mainToRender : JSON.stringify(globalThis.__mainToRender))");
|
||||
var jsVal = await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync<string>("globalThis.__mainToRender === undefined ? '' : (typeof globalThis.__mainToRender === 'string' ? globalThis.__mainToRender : JSON.stringify(globalThis.__mainToRender))");
|
||||
value = jsVal?.ToString() ?? "";
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
};
|
||||
Electron.Menu.SetApplicationMenu(items);
|
||||
var targetId = items[0].Submenu[0].Id;
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync($"require('electron').ipcRenderer.send('integration-click-application-menu','{targetId}')");
|
||||
await this.fx.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);
|
||||
@@ -48,7 +48,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
var ctxId = ctxItems[0].Id;
|
||||
// simulate popup then click
|
||||
Electron.Menu.ContextMenuPopup(win);
|
||||
await this.fx.MainWindow.WebContents.ExecuteJavaScriptAsync($"require('electron').ipcRenderer.send('integration-click-context-menu',{win.Id},'{ctxId}')");
|
||||
await this.fx.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);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
// Use renderer to fetch process info and round-trip
|
||||
var execPath = await Electron.WindowManager.CreateWindowAsync(new API.Entities.BrowserWindowOptions { Show = false });
|
||||
var result = await execPath.WebContents.ExecuteJavaScriptAsync("process.execPath && process.platform ? 'ok' : 'fail'");
|
||||
var result = await execPath.WebContents.ExecuteJavaScriptAsync<string>("process.execPath && process.platform ? 'ok' : 'fail'");
|
||||
result.Should().Be("ok");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace ElectronNET.IntegrationTests.Tests
|
||||
{
|
||||
var wc = this.fx.MainWindow.WebContents;
|
||||
await wc.LoadURLAsync("https://example.com");
|
||||
var title = await wc.ExecuteJavaScriptAsync("document.title");
|
||||
var title = await wc.ExecuteJavaScriptAsync<string>("document.title");
|
||||
title.Should().NotBeNull();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user