diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 9dba18f3c2628..bb7512b98523d 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -186,19 +186,19 @@ public async Task ExecuteCommandAsync(TCommand command, CommandOptions public async Task ExecuteCommandAsync(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 ExecuteCommandCoreAsync(TCommand command, CommandOptions? options) + private async Task ExecuteCommandCoreAsync(TCommand command, CommandOptions? options) where TCommand : Command { command.Id = Interlocked.Increment(ref _currentCommandId); - var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); + var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var timeout = options?.Timeout ?? TimeSpan.FromSeconds(30); @@ -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; @@ -406,12 +406,12 @@ private void ProcessReceivedMessage(byte[]? data) } } - class CommandInfo(long id, Type resultType, TaskCompletionSource taskCompletionSource) + class CommandInfo(long id, Type resultType, TaskCompletionSource taskCompletionSource) { public long Id { get; } = id; public Type ResultType { get; } = resultType; - public TaskCompletionSource TaskCompletionSource { get; } = taskCompletionSource; + public TaskCompletionSource TaskCompletionSource { get; } = taskCompletionSource; }; } diff --git a/dotnet/src/webdriver/BiDi/Communication/Command.cs b/dotnet/src/webdriver/BiDi/Communication/Command.cs index ce12b125e08a2..7d63364cae4bf 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Command.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Command.cs @@ -42,7 +42,7 @@ protected Command(string method, Type resultType) internal abstract class Command(TCommandParameters @params, string method) : Command(method, typeof(TCommandResult)) where TCommandParameters : CommandParameters - where TCommandResult : EmptyResult + where TCommandResult : BiDiResult { [JsonPropertyOrder(2)] public TCommandParameters Params { get; } = @params; @@ -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; + diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index ceb42345e9840..0f9fea2dde796 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -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))] diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs index 9ff3a88973670..f4d22eba1bb47 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/InputOriginConverter.cs @@ -17,16 +17,15 @@ // under the License. // +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 { public override Origin Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) @@ -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()); writer.WriteEndObject(); } } diff --git a/dotnet/src/webdriver/BiDi/Communication/Message.cs b/dotnet/src/webdriver/BiDi/Communication/Message.cs index 03f948cc18873..eb7670ed9dbca 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Message.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Message.cs @@ -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 { diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/GetClientWindowsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/GetClientWindowsCommand.cs index 5e6f4f2b65d30..c084c45a512d6 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/GetClientWindowsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/GetClientWindowsCommand.cs @@ -28,7 +28,7 @@ internal class GetClientWindowsCommand() public record GetClientWindowsOptions : CommandOptions; -public record GetClientWindowsResult : EmptyResult, IReadOnlyList +public record GetClientWindowsResult : BiDiResult, IReadOnlyList { private readonly IReadOnlyList _clientWindows; diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs index 42891aa3664ba..8363b12b7fe36 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/GetUserContextsCommand.cs @@ -28,7 +28,7 @@ internal class GetUserContextsCommand() public record GetUserContextsOptions : CommandOptions; -public record GetUserContextsResult : EmptyResult, IReadOnlyList +public record GetUserContextsResult : BiDiResult, IReadOnlyList { private readonly IReadOnlyList _userContexts; diff --git a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs index f439f678b3f64..ef0a068417f37 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Browser/UserContextInfo.cs @@ -21,4 +21,4 @@ namespace OpenQA.Selenium.BiDi.Modules.Browser; -public record UserContextInfo(UserContext UserContext) : EmptyResult; +public record UserContextInfo(UserContext UserContext) : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs index 51be0130a92ad..dc9b926a38ca3 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CaptureScreenshotCommand.cs @@ -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); } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs index 58900de151e51..60bf15d1cb182 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/CreateCommand.cs @@ -41,4 +41,4 @@ public enum ContextType Window } -public record CreateResult(BrowsingContext Context) : EmptyResult; +public record CreateResult(BrowsingContext Context) : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs index 0c6e0d7dd777a..39f8df378a0ec 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/GetTreeCommand.cs @@ -46,4 +46,4 @@ public record BrowsingContextGetTreeOptions public long? MaxDepth { get; set; } } -public record GetTreeResult(IReadOnlyList Contexts) : EmptyResult; +public record GetTreeResult(IReadOnlyList Contexts) : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs index 393cdff1c9e22..14b74877c621e 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs @@ -37,7 +37,7 @@ public record LocateNodesOptions : CommandOptions public IEnumerable? StartNodes { get; set; } } -public record LocateNodesResult : EmptyResult, IReadOnlyList +public record LocateNodesResult : BiDiResult, IReadOnlyList { private readonly IReadOnlyList _nodes; diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs index 1ca3c3b19a598..8de624d904c66 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/NavigateCommand.cs @@ -38,4 +38,4 @@ public enum ReadinessState Complete } -public record NavigateResult(Navigation Navigation, string Url) : EmptyResult; +public record NavigateResult(Navigation Navigation, string Url) : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs index 0e68022eb3f6a..d4ba2fc4f8037 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/PrintCommand.cs @@ -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); } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs index ed166ad0beae4..77d8998298b03 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/TraverseHistoryCommand.cs @@ -28,4 +28,4 @@ internal record TraverseHistoryCommandParameters(BrowsingContext Context, long D public record TraverseHistoryOptions : CommandOptions; -public record TraverseHistoryResult : EmptyResult; +public record TraverseHistoryResult : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs index e4237b26bc6e4..54c64fe07a783 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/AddInterceptCommand.cs @@ -46,7 +46,7 @@ public record BrowsingContextAddInterceptOptions public IEnumerable? UrlPatterns { get; set; } } -public record AddInterceptResult(Intercept Intercept) : EmptyResult; +public record AddInterceptResult(Intercept Intercept) : BiDiResult; public enum InterceptPhase { diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs index 68ddc27170de3..ec9e7313ca91a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/AddPreloadScriptCommand.cs @@ -51,4 +51,4 @@ public record BrowsingContextAddPreloadScriptOptions public string? Sandbox { get; set; } } -internal record AddPreloadScriptResult(PreloadScript Script) : EmptyResult; +internal record AddPreloadScriptResult(PreloadScript Script) : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs index 45317ddeb1e94..26be70d2e5945 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/EvaluateCommand.cs @@ -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 { diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs index 641602e4c6ee5..b4e46cb632034 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/GetRealmsCommand.cs @@ -35,7 +35,7 @@ public record GetRealmsOptions : CommandOptions public RealmType? Type { get; set; } } -public record GetRealmsResult : EmptyResult, IReadOnlyList +public record GetRealmsResult : BiDiResult, IReadOnlyList { private readonly IReadOnlyList _realms; diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs index 4490d51207cc8..494703a238162 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/NewCommand.cs @@ -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) { diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs index d8bf6035ec272..afdccfaf27076 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/StatusCommand.cs @@ -24,6 +24,6 @@ namespace OpenQA.Selenium.BiDi.Modules.Session; internal class StatusCommand() : Command(CommandParameters.Empty, "session.status"); -public record StatusResult(bool Ready, string Message) : EmptyResult; +public record StatusResult(bool Ready, string Message) : BiDiResult; public record StatusOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs index 7b0413c2b3445..2edea1f5c12a9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Session/SubscribeCommand.cs @@ -32,4 +32,4 @@ public record SubscribeOptions : CommandOptions public IEnumerable? Contexts { get; set; } } -internal record SubscribeResult(Subscription Subscription) : EmptyResult; +internal record SubscribeResult(Subscription Subscription) : BiDiResult; diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs index 1b7a7534754ed..00c0674f8903a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/DeleteCookiesCommand.cs @@ -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; diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs index 5d409c639e64a..f3f627a812c1c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/GetCookiesCommand.cs @@ -37,7 +37,7 @@ public record GetCookiesOptions : CommandOptions public PartitionDescriptor? Partition { get; set; } } -public record GetCookiesResult : EmptyResult, IReadOnlyList +public record GetCookiesResult : BiDiResult, IReadOnlyList { private readonly IReadOnlyList _cookies; diff --git a/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs index c34196abff93d..c1fcfd7378933 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Storage/SetCookieCommand.cs @@ -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;