Skip to content

[dotnet] [bidi] Separate empty and base result #15593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dotnet/src/webdriver/BiDi/Communication/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,19 @@ public async Task ExecuteCommandAsync<TCommand>(TCommand command, CommandOptions

public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options)
where TCommand : Command
where TResult : EmptyResult
where TResult : BiDiResult
{
var result = await ExecuteCommandCoreAsync(command, options).ConfigureAwait(false);

return (TResult)result;
}

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

var tcs = new TaskCompletionSource<EmptyResult>(TaskCreationOptions.RunContinuationsAsynchronously);
var tcs = new TaskCompletionSource<BiDiResult>(TaskCreationOptions.RunContinuationsAsynchronously);

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

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

var successCommand = _pendingCommands[id.Value];
var messageSuccess = JsonSerializer.Deserialize(ref resultReader, successCommand.ResultType, _jsonSerializerContext)!;
successCommand.TaskCompletionSource.SetResult((EmptyResult)messageSuccess);
successCommand.TaskCompletionSource.SetResult((BiDiResult)messageSuccess);
_pendingCommands.TryRemove(id.Value, out _);
break;

Expand All @@ -406,12 +406,12 @@ private void ProcessReceivedMessage(byte[]? data)
}
}

class CommandInfo(long id, Type resultType, TaskCompletionSource<EmptyResult> taskCompletionSource)
class CommandInfo(long id, Type resultType, TaskCompletionSource<BiDiResult> taskCompletionSource)
{
public long Id { get; } = id;

public Type ResultType { get; } = resultType;

public TaskCompletionSource<EmptyResult> TaskCompletionSource { get; } = taskCompletionSource;
public TaskCompletionSource<BiDiResult> TaskCompletionSource { get; } = taskCompletionSource;
};
}
7 changes: 5 additions & 2 deletions dotnet/src/webdriver/BiDi/Communication/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected Command(string method, Type resultType)

internal abstract class Command<TCommandParameters, TCommandResult>(TCommandParameters @params, string method) : Command(method, typeof(TCommandResult))
where TCommandParameters : CommandParameters
where TCommandResult : EmptyResult
where TCommandResult : BiDiResult
{
[JsonPropertyOrder(2)]
public TCommandParameters Params { get; } = @params;
Expand All @@ -53,4 +53,7 @@ internal record CommandParameters
public static CommandParameters Empty { get; } = new CommandParameters();
}

public record EmptyResult;
public sealed record EmptyResult : BiDiResult;

public abstract record BiDiResult;

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
#endregion

[JsonSerializable(typeof(Command))]
[JsonSerializable(typeof(EmptyResult))]
[JsonSerializable(typeof(BiDiResult))]

[JsonSerializable(typeof(Modules.Session.StatusCommand))]
[JsonSerializable(typeof(Modules.Session.StatusResult))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
// under the License.
// </copyright>

using OpenQA.Selenium.BiDi.Communication.Json.Internal;
using OpenQA.Selenium.BiDi.Modules.Input;
using OpenQA.Selenium.BiDi.Modules.Script;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;

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

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Json serializer options should have AOT-safe type resolution")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Json serializer options should have AOT-safe type resolution")]
internal class InputOriginConverter : JsonConverter<Origin>
{
public override Origin Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
Expand All @@ -49,7 +48,7 @@ public override void Write(Utf8JsonWriter writer, Origin value, JsonSerializerOp
writer.WriteStartObject();
writer.WriteString("type", "element");
writer.WritePropertyName("element");
JsonSerializer.Serialize(writer, element.Element, options);
JsonSerializer.Serialize(writer, element.Element, options.GetTypeInfo<ISharedReference>());
writer.WriteEndObject();
}
}
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Communication/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi.Communication;

internal abstract record Message;

internal record MessageSuccess(long Id, EmptyResult Result) : Message;
internal record MessageSuccess(long Id, BiDiResult Result) : Message;

internal record MessageError(long Id) : Message
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class GetClientWindowsCommand()

public record GetClientWindowsOptions : CommandOptions;

public record GetClientWindowsResult : EmptyResult, IReadOnlyList<ClientWindowInfo>
public record GetClientWindowsResult : BiDiResult, IReadOnlyList<ClientWindowInfo>
{
private readonly IReadOnlyList<ClientWindowInfo> _clientWindows;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class GetUserContextsCommand()

public record GetUserContextsOptions : CommandOptions;

public record GetUserContextsResult : EmptyResult, IReadOnlyList<UserContextInfo>
public record GetUserContextsResult : BiDiResult, IReadOnlyList<UserContextInfo>
{
private readonly IReadOnlyList<UserContextInfo> _userContexts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

namespace OpenQA.Selenium.BiDi.Modules.Browser;

public record UserContextInfo(UserContext UserContext) : EmptyResult;
public record UserContextInfo(UserContext UserContext) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public record BoxClipRectangle(double X, double Y, double Width, double Height)

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

public record CaptureScreenshotResult(string Data) : EmptyResult
public record CaptureScreenshotResult(string Data) : BiDiResult
{
public byte[] ToByteArray() => System.Convert.FromBase64String(Data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ public enum ContextType
Window
}

public record CreateResult(BrowsingContext Context) : EmptyResult;
public record CreateResult(BrowsingContext Context) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public record BrowsingContextGetTreeOptions
public long? MaxDepth { get; set; }
}

public record GetTreeResult(IReadOnlyList<BrowsingContextInfo> Contexts) : EmptyResult;
public record GetTreeResult(IReadOnlyList<BrowsingContextInfo> Contexts) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public record LocateNodesOptions : CommandOptions
public IEnumerable<Script.ISharedReference>? StartNodes { get; set; }
}

public record LocateNodesResult : EmptyResult, IReadOnlyList<Script.NodeRemoteValue>
public record LocateNodesResult : BiDiResult, IReadOnlyList<Script.NodeRemoteValue>
{
private readonly IReadOnlyList<Script.NodeRemoteValue> _nodes;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public enum ReadinessState
Complete
}

public record NavigateResult(Navigation Navigation, string Url) : EmptyResult;
public record NavigateResult(Navigation Navigation, string Url) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static implicit operator PrintPageRange(Range range)
#endif
}

public record PrintResult(string Data) : EmptyResult
public record PrintResult(string Data) : BiDiResult
{
public byte[] ToByteArray() => Convert.FromBase64String(Data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ internal record TraverseHistoryCommandParameters(BrowsingContext Context, long D

public record TraverseHistoryOptions : CommandOptions;

public record TraverseHistoryResult : EmptyResult;
public record TraverseHistoryResult : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public record BrowsingContextAddInterceptOptions
public IEnumerable<UrlPattern>? UrlPatterns { get; set; }
}

public record AddInterceptResult(Intercept Intercept) : EmptyResult;
public record AddInterceptResult(Intercept Intercept) : BiDiResult;

public enum InterceptPhase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ public record BrowsingContextAddPreloadScriptOptions
public string? Sandbox { get; set; }
}

internal record AddPreloadScriptResult(PreloadScript Script) : EmptyResult;
internal record AddPreloadScriptResult(PreloadScript Script) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public record EvaluateOptions : CommandOptions
//[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
//[JsonDerivedType(typeof(EvaluateResultSuccess), "success")]
//[JsonDerivedType(typeof(EvaluateResultException), "exception")]
public abstract record EvaluateResult : EmptyResult;
public abstract record EvaluateResult : BiDiResult;

public record EvaluateResultSuccess(RemoteValue Result, Realm Realm) : EvaluateResult
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public record GetRealmsOptions : CommandOptions
public RealmType? Type { get; set; }
}

public record GetRealmsResult : EmptyResult, IReadOnlyList<RealmInfo>
public record GetRealmsResult : BiDiResult, IReadOnlyList<RealmInfo>
{
private readonly IReadOnlyList<RealmInfo> _realms;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal record NewCommandParameters(CapabilitiesRequest Capabilities) : Command

public record NewOptions : CommandOptions;

public record NewResult(string SessionId, Capability Capability) : EmptyResult;
public record NewResult(string SessionId, Capability Capability) : BiDiResult;

public record Capability(bool AcceptInsecureCerts, string BrowserName, string BrowserVersion, string PlatformName, bool SetWindowRect, string UserAgent)
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace OpenQA.Selenium.BiDi.Modules.Session;
internal class StatusCommand()
: Command<CommandParameters, StatusResult>(CommandParameters.Empty, "session.status");

public record StatusResult(bool Ready, string Message) : EmptyResult;
public record StatusResult(bool Ready, string Message) : BiDiResult;

public record StatusOptions : CommandOptions;
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public record SubscribeOptions : CommandOptions
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
}

internal record SubscribeResult(Subscription Subscription) : EmptyResult;
internal record SubscribeResult(Subscription Subscription) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ internal record DeleteCookiesCommandParameters(CookieFilter? Filter, PartitionDe

public record DeleteCookiesOptions : GetCookiesOptions;

public record DeleteCookiesResult(PartitionKey PartitionKey) : EmptyResult;
public record DeleteCookiesResult(PartitionKey PartitionKey) : BiDiResult;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public record GetCookiesOptions : CommandOptions
public PartitionDescriptor? Partition { get; set; }
}

public record GetCookiesResult : EmptyResult, IReadOnlyList<Network.Cookie>
public record GetCookiesResult : BiDiResult, IReadOnlyList<Network.Cookie>
{
private readonly IReadOnlyList<Network.Cookie> _cookies;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ public record SetCookieOptions : CommandOptions
public PartitionDescriptor? Partition { get; set; }
}

public record SetCookieResult(PartitionKey PartitionKey) : EmptyResult;
public record SetCookieResult(PartitionKey PartitionKey) : BiDiResult;
Loading