Skip to content

Commit fc69598

Browse files
authored
Merge pull request #913 from softworkz/submit_tests_fixes
Add 77 IntegrationTests and lots of fixes
2 parents 84989cd + 60a278c commit fc69598

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1599
-64
lines changed

src/ElectronNET.API/API/ApiBase.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
public abstract class ApiBase
1111
{
12+
protected enum SocketEventNameTypes
13+
{
14+
DashesLowerFirst,
15+
NoDashUpperFirst,
16+
}
17+
1218
internal const int PropertyTimeout = 1000;
1319

1420
private readonly string objectName;
@@ -31,7 +37,7 @@ protected set
3137
}
3238
}
3339

34-
protected abstract string SocketEventCompleteSuffix { get; }
40+
protected abstract SocketEventNameTypes SocketEventNameType { get; }
3541

3642
protected ApiBase()
3743
{
@@ -128,7 +134,20 @@ public PropertyGetter(ApiBase apiBase, string callerName, int timeoutMs)
128134
this.tcs = new TaskCompletionSource<T>(TaskCreationOptions.RunContinuationsAsynchronously);
129135
this.tcsTask = this.tcs.Task;
130136

131-
var eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}{apiBase.SocketEventCompleteSuffix}");
137+
string eventName;
138+
139+
switch (apiBase.SocketEventNameType)
140+
{
141+
case SocketEventNameTypes.DashesLowerFirst:
142+
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}-{s.StripAsync().LowerFirst()}-completed");
143+
break;
144+
case SocketEventNameTypes.NoDashUpperFirst:
145+
eventName = apiBase.propertyEventNames.GetOrAdd(callerName, s => $"{apiBase.objectName}{s.StripAsync()}Completed");
146+
break;
147+
default:
148+
throw new ArgumentOutOfRangeException();
149+
}
150+
132151
var messageName = apiBase.propertyMessageNames.GetOrAdd(callerName, s => apiBase.objectName + s.StripAsync());
133152

134153
BridgeConnector.Socket.On<T>(eventName, (result) =>

src/ElectronNET.API/API/App.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace ElectronNET.API
1818
/// </summary>
1919
public sealed class App : ApiBase
2020
{
21-
protected override string SocketEventCompleteSuffix => "Completed";
21+
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.NoDashUpperFirst;
2222

2323
/// <summary>
2424
/// Emitted when all windows have been closed.
@@ -1306,7 +1306,20 @@ public Task<string> UserAgentFallbackAsync
13061306
{
13071307
get
13081308
{
1309-
return this.GetPropertyAsync<string>();
1309+
return Task.Run<string>(() =>
1310+
{
1311+
var taskCompletionSource = new TaskCompletionSource<string>();
1312+
1313+
BridgeConnector.Socket.On("appGetUserAgentFallbackCompleted", (result) =>
1314+
{
1315+
BridgeConnector.Socket.Off("appGetUserAgentFallbackCompleted");
1316+
taskCompletionSource.SetResult((string)result);
1317+
});
1318+
1319+
BridgeConnector.Socket.Emit("appGetUserAgentFallback");
1320+
1321+
return taskCompletionSource.Task;
1322+
});
13101323
}
13111324
}
13121325

src/ElectronNET.API/API/BrowserView.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ public Rectangle Bounds
3535
{
3636
get
3737
{
38-
return Task.Run<Rectangle>(() =>
39-
{
40-
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
38+
var taskCompletionSource = new TaskCompletionSource<Rectangle>();
4139

42-
BridgeConnector.Socket.On("browserView-getBounds-reply", (result) =>
40+
Task.Run(() =>
41+
{
42+
BridgeConnector.Socket.On<Rectangle>("browserView-getBounds-reply", (result) =>
4343
{
4444
BridgeConnector.Socket.Off("browserView-getBounds-reply");
45-
taskCompletionSource.SetResult((Rectangle)result);
45+
taskCompletionSource.SetResult(result);
4646
});
4747

4848
BridgeConnector.Socket.Emit("browserView-getBounds", Id);
49+
});
4950

50-
return taskCompletionSource.Task;
51-
}).Result;
51+
return taskCompletionSource.Task.GetAwaiter().GetResult();
5252
}
5353
set
5454
{

src/ElectronNET.API/API/BrowserWindow.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace ElectronNET.API;
2424
/// </summary>
2525
public class BrowserWindow : ApiBase
2626
{
27-
protected override string SocketEventCompleteSuffix => "-completed";
27+
protected override SocketEventNameTypes SocketEventNameType => SocketEventNameTypes.DashesLowerFirst;
2828

2929
/// <summary>
3030
/// Gets the identifier.
@@ -749,11 +749,10 @@ public void SetPosition(int x, int y)
749749
{
750750
// Workaround Windows 10 / Electron Bug
751751
// https://github.com/electron/electron/issues/4045
752-
if (isWindows10())
753-
{
754-
x = x - 7;
755-
}
756-
752+
////if (isWindows10())
753+
////{
754+
//// x = x - 7;
755+
////}
757756
this.CallMethod2(x, y);
758757
}
759758

@@ -767,11 +766,10 @@ public void SetPosition(int x, int y, bool animate)
767766
{
768767
// Workaround Windows 10 / Electron Bug
769768
// https://github.com/electron/electron/issues/4045
770-
if (isWindows10())
771-
{
772-
x = x - 7;
773-
}
774-
769+
////if (isWindows10())
770+
////{
771+
//// x = x - 7;
772+
////}
775773
this.CallMethod3(x, y, animate);
776774
}
777775

@@ -1140,7 +1138,17 @@ public Task<bool> SetThumbarButtonsAsync(ThumbarButton[] thumbarButtons)
11401138
/// passing null will turn current window into a top-level window.
11411139
/// </summary>
11421140
/// <param name="parent"></param>
1143-
public void SetParentWindow(BrowserWindow parent) => this.CallMethod1(JObject.FromObject(parent, _jsonSerializer));
1141+
public void SetParentWindow(BrowserWindow parent)
1142+
{
1143+
if (parent == null)
1144+
{
1145+
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, null);
1146+
}
1147+
else
1148+
{
1149+
BridgeConnector.Socket.Emit("browserWindowSetParentWindow", Id, JObject.FromObject(parent, _jsonSerializer));
1150+
}
1151+
}
11441152

11451153
/// <summary>
11461154
/// The parent window.

src/ElectronNET.API/API/Entities/Cookie.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
namespace ElectronNET.API.Entities {
1+
namespace ElectronNET.API.Entities
2+
{
23
/// <summary>
34
///
45
/// </summary>
5-
public class Cookie {
6+
public class Cookie
7+
{
68
/// <summary>
79
/// The name of the cookie.
810
/// </summary>
9-
public string Name { get; set;}
11+
public string Name { get; set; }
1012

1113
/// <summary>
1214
/// The value of the cookie.
@@ -26,7 +28,7 @@ public class Cookie {
2628
/// <summary>
2729
/// (optional) - The path of the cookie.
2830
/// </summary>
29-
public string Path { get; set; }
31+
public string Path { get; set; }
3032

3133
/// <summary>
3234
/// (optional) - Whether the cookie is marked as secure.
@@ -36,7 +38,7 @@ public class Cookie {
3638
/// <summary>
3739
/// (optional) - Whether the cookie is marked as HTTP only.
3840
/// </summary>
39-
public bool HttpOnly { get; set; }
41+
public bool HttpOnly { get; set; }
4042

4143
/// <summary>
4244
/// (optional) - Whether the cookie is a session cookie or a persistent cookie with an expiration date.
@@ -48,4 +50,4 @@ public class Cookie {
4850
/// </summary>
4951
public long ExpirationDate { get; set; }
5052
}
51-
}
53+
}

src/ElectronNET.API/API/Entities/ProcessMetric.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ElectronNET.API.Entities
22
{
33
/// <summary>
4-
///
4+
/// Process metrics information.
55
/// </summary>
66
public class ProcessMetric
77
{
@@ -21,11 +21,9 @@ public class ProcessMetric
2121
public CPUUsage Cpu { get; set; }
2222

2323
/// <summary>
24-
/// Creation time for this process. The time is represented as number of milliseconds since epoch.
25-
/// Since the <see cref="PId"/> can be reused after a process dies, it is useful to use both the <see cref="PId"/>
26-
/// and the <see cref="CreationTime"/> to uniquely identify a process.
24+
/// Creation time for this process in milliseconds since Unix epoch. Can exceed Int32 range and may contain fractional milliseconds.
2725
/// </summary>
28-
public int CreationTime { get; set; }
26+
public double CreationTime { get; set; }
2927

3028
/// <summary>
3129
/// Memory information for the process.

src/ElectronNET.API/Runtime/Services/SocketBridge/SocketBridgeService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ protected override Task StopCore()
4040
private void Connect()
4141
{
4242
this.socket.Connect();
43-
this.TransitionState(LifetimeState.Started);
43+
if (this.State < LifetimeState.Started)
44+
{
45+
this.TransitionState(LifetimeState.Started);
46+
}
4447
}
4548

4649
private void Socket_BridgeDisconnected(object sender, EventArgs e)

src/ElectronNET.API/Runtime/StartupManager.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,21 @@ private BuildInfo GatherBuildInfo()
128128
{
129129
var buildInfo = new BuildInfo();
130130

131-
var attributes = Assembly.GetEntryAssembly()?.GetCustomAttributes<AssemblyMetadataAttribute>().ToList();
131+
var electronAssembly = Assembly.GetEntryAssembly();
132132

133-
if (attributes?.Count > 0)
133+
if (electronAssembly == null)
134+
{
135+
return buildInfo;
136+
}
137+
138+
if (electronAssembly.GetName().Name == "testhost")
139+
{
140+
electronAssembly = AppDomain.CurrentDomain.GetData("ElectronTestAssembly") as Assembly ?? electronAssembly;
141+
}
142+
143+
var attributes = electronAssembly.GetCustomAttributes<AssemblyMetadataAttribute>().ToList();
144+
145+
if (attributes.Count > 0)
134146
{
135147
buildInfo.ElectronExecutable = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronExecutable))?.Value;
136148
buildInfo.ElectronVersion = attributes.FirstOrDefault(e => e.Key == nameof(buildInfo.ElectronVersion))?.Value;

src/ElectronNET.Host/api/browserWindows.js

Lines changed: 41 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/browserWindows.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)