Skip to content

Commit 5c18841

Browse files
committed
[dotnet] [bidi] Separate empty and base result
1 parent 900bbaa commit 5c18841

25 files changed

+36
-34
lines changed

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,19 @@ public async Task ExecuteCommandAsync<TCommand>(TCommand command, CommandOptions
186186

187187
public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options)
188188
where TCommand : Command
189-
where TResult : EmptyResult
189+
where TResult : BiDiResult
190190
{
191191
var result = await ExecuteCommandCoreAsync(command, options).ConfigureAwait(false);
192192

193193
return (TResult)result;
194194
}
195195

196-
private async Task<EmptyResult> ExecuteCommandCoreAsync<TCommand>(TCommand command, CommandOptions? options)
196+
private async Task<BiDiResult> ExecuteCommandCoreAsync<TCommand>(TCommand command, CommandOptions? options)
197197
where TCommand : Command
198198
{
199199
command.Id = Interlocked.Increment(ref _currentCommandId);
200200

201-
var tcs = new TaskCompletionSource<EmptyResult>(TaskCreationOptions.RunContinuationsAsynchronously);
201+
var tcs = new TaskCompletionSource<BiDiResult>(TaskCreationOptions.RunContinuationsAsynchronously);
202202

203203
var timeout = options?.Timeout ?? TimeSpan.FromSeconds(30);
204204

@@ -380,7 +380,7 @@ private void ProcessReceivedMessage(byte[]? data)
380380

381381
var successCommand = _pendingCommands[id.Value];
382382
var messageSuccess = JsonSerializer.Deserialize(ref resultReader, successCommand.ResultType, _jsonSerializerContext)!;
383-
successCommand.TaskCompletionSource.SetResult((EmptyResult)messageSuccess);
383+
successCommand.TaskCompletionSource.SetResult((BiDiResult)messageSuccess);
384384
_pendingCommands.TryRemove(id.Value, out _);
385385
break;
386386

@@ -406,12 +406,12 @@ private void ProcessReceivedMessage(byte[]? data)
406406
}
407407
}
408408

409-
class CommandInfo(long id, Type resultType, TaskCompletionSource<EmptyResult> taskCompletionSource)
409+
class CommandInfo(long id, Type resultType, TaskCompletionSource<BiDiResult> taskCompletionSource)
410410
{
411411
public long Id { get; } = id;
412412

413413
public Type ResultType { get; } = resultType;
414414

415-
public TaskCompletionSource<EmptyResult> TaskCompletionSource { get; } = taskCompletionSource;
415+
public TaskCompletionSource<BiDiResult> TaskCompletionSource { get; } = taskCompletionSource;
416416
};
417417
}

dotnet/src/webdriver/BiDi/Communication/Command.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected Command(string method, Type resultType)
4242

4343
internal abstract class Command<TCommandParameters, TCommandResult>(TCommandParameters @params, string method) : Command(method, typeof(TCommandResult))
4444
where TCommandParameters : CommandParameters
45-
where TCommandResult : EmptyResult
45+
where TCommandResult : BiDiResult
4646
{
4747
[JsonPropertyOrder(2)]
4848
public TCommandParameters Params { get; } = @params;
@@ -53,4 +53,7 @@ internal record CommandParameters
5353
public static CommandParameters Empty { get; } = new CommandParameters();
5454
}
5555

56-
public record EmptyResult;
56+
public sealed record EmptyResult : BiDiResult;
57+
58+
public abstract record BiDiResult;
59+

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
6767
#endregion
6868

6969
[JsonSerializable(typeof(Command))]
70-
[JsonSerializable(typeof(EmptyResult))]
70+
[JsonSerializable(typeof(BiDiResult))]
7171

7272
[JsonSerializable(typeof(Modules.Session.StatusCommand))]
7373
[JsonSerializable(typeof(Modules.Session.StatusResult))]

dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using OpenQA.Selenium.BiDi.Communication.Json.Internal;
2021
using OpenQA.Selenium.BiDi.Modules.Input;
22+
using OpenQA.Selenium.BiDi.Modules.Script;
2123
using System;
22-
using System.Diagnostics.CodeAnalysis;
2324
using System.Text.Json;
2425
using System.Text.Json.Serialization;
2526

2627
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
2728

28-
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")]
29-
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")]
3029
internal class InputOriginConverter : JsonConverter<Origin>
3130
{
3231
public override Origin Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
@@ -49,7 +48,7 @@ public override void Write(Utf8JsonWriter writer, Origin value, JsonSerializerOp
4948
writer.WriteStartObject();
5049
writer.WriteString("type", "element");
5150
writer.WritePropertyName("element");
52-
JsonSerializer.Serialize(writer, element.Element, options);
51+
JsonSerializer.Serialize(writer, element.Element, options.GetTypeInfo<ISharedReference>());
5352
writer.WriteEndObject();
5453
}
5554
}

dotnet/src/webdriver/BiDi/Communication/Message.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi.Communication;
2121

2222
internal abstract record Message;
2323

24-
internal record MessageSuccess(long Id, EmptyResult Result) : Message;
24+
internal record MessageSuccess(long Id, BiDiResult Result) : Message;
2525

2626
internal record MessageError(long Id) : Message
2727
{

dotnet/src/webdriver/BiDi/Modules/Browser/GetClientWindowsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal class GetClientWindowsCommand()
2828

2929
public record GetClientWindowsOptions : CommandOptions;
3030

31-
public record GetClientWindowsResult : EmptyResult, IReadOnlyList<ClientWindowInfo>
31+
public record GetClientWindowsResult : BiDiResult, IReadOnlyList<ClientWindowInfo>
3232
{
3333
private readonly IReadOnlyList<ClientWindowInfo> _clientWindows;
3434

dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal class GetUserContextsCommand()
2828

2929
public record GetUserContextsOptions : CommandOptions;
3030

31-
public record GetUserContextsResult : EmptyResult, IReadOnlyList<UserContextInfo>
31+
public record GetUserContextsResult : BiDiResult, IReadOnlyList<UserContextInfo>
3232
{
3333
private readonly IReadOnlyList<UserContextInfo> _userContexts;
3434

dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121

2222
namespace OpenQA.Selenium.BiDi.Modules.Browser;
2323

24-
public record UserContextInfo(UserContext UserContext) : EmptyResult;
24+
public record UserContextInfo(UserContext UserContext) : BiDiResult;

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public record BoxClipRectangle(double X, double Y, double Width, double Height)
5656

5757
public record ElementClipRectangle([property: JsonPropertyName("element")] Script.ISharedReference SharedReference) : ClipRectangle;
5858

59-
public record CaptureScreenshotResult(string Data) : EmptyResult
59+
public record CaptureScreenshotResult(string Data) : BiDiResult
6060
{
6161
public byte[] ToByteArray() => System.Convert.FromBase64String(Data);
6262
}

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ public enum ContextType
4141
Window
4242
}
4343

44-
public record CreateResult(BrowsingContext Context) : EmptyResult;
44+
public record CreateResult(BrowsingContext Context) : BiDiResult;

0 commit comments

Comments
 (0)