diff --git a/dotnet/src/webdriver/BiDi/Broker.cs b/dotnet/src/webdriver/BiDi/Broker.cs index 9611f3cadcec1..3e1b49783f16b 100644 --- a/dotnet/src/webdriver/BiDi/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Broker.cs @@ -114,8 +114,8 @@ public async ValueTask UnsubscribeAsync(Subscription subscription, CancellationT _eventDispatcher.RemoveHandler(subscription.EventName, subscription.Handler); } - public async Task ExecuteCommandAsync(TCommand command, CommandOptions? options, JsonTypeInfo jsonCommandTypeInfo, JsonTypeInfo jsonResultTypeInfo, CancellationToken cancellationToken) - where TCommand : Command + public async Task ExecuteAsync(Command descriptor, TParameters @params, CommandOptions? options, CancellationToken cancellationToken) + where TParameters : Parameters where TResult : EmptyResult { if (_terminalReceiveException is { } terminalException) @@ -123,7 +123,7 @@ public async Task ExecuteCommandAsync(TCommand comma throw new BiDiException("The broker is no longer processing messages due to a transport error.", terminalException); } - command.Id = Interlocked.Increment(ref _currentCommandId); + var id = Interlocked.Increment(ref _currentCommandId); var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); @@ -141,7 +141,12 @@ public async Task ExecuteCommandAsync(TCommand comma using (BiDiContext.Use(_bidi)) using (var writer = new Utf8JsonWriter(sendBuffer)) { - JsonSerializer.Serialize(writer, command, jsonCommandTypeInfo); + writer.WriteStartObject(); + writer.WriteNumber("id"u8, id); + writer.WriteString("method"u8, descriptor.Method); + writer.WritePropertyName("params"u8); + JsonSerializer.Serialize(writer, @params, descriptor.ParamsTypeInfo); + writer.WriteEndObject(); } } catch @@ -150,13 +155,13 @@ public async Task ExecuteCommandAsync(TCommand comma throw; } - var commandInfo = new CommandInfo(tcs, jsonResultTypeInfo); - _pendingCommands[command.Id] = commandInfo; + var commandInfo = new CommandInfo(tcs, descriptor.ResultTypeInfo); + _pendingCommands[id] = commandInfo; using var ctsRegistration = cts.Token.Register(() => { tcs.TrySetCanceled(cts.Token); - _pendingCommands.TryRemove(command.Id, out _); + _pendingCommands.TryRemove(id, out _); }); try @@ -174,7 +179,7 @@ public async Task ExecuteCommandAsync(TCommand comma } catch { - _pendingCommands.TryRemove(command.Id, out _); + _pendingCommands.TryRemove(id, out _); throw; } finally @@ -290,7 +295,7 @@ private void ProcessReceivedMessage(ReadOnlySpan data) case TypeSuccess: if (id is null) throw new BiDiException("The remote end responded with 'success' message type, but missed required 'id' property."); - if (_pendingCommands.TryGetValue(id.Value, out var command)) + if (_pendingCommands.TryRemove(id.Value, out var command)) { try { @@ -303,10 +308,6 @@ private void ProcessReceivedMessage(ReadOnlySpan data) { command.TaskCompletionSource.TrySetException(ex); } - finally - { - _pendingCommands.TryRemove(id.Value, out _); - } } else { @@ -342,10 +343,9 @@ private void ProcessReceivedMessage(ReadOnlySpan data) case TypeError: if (id is null) throw new BiDiException($"The remote end responded with 'error' message type, but missed required 'id' property. Message content: {System.Text.Encoding.UTF8.GetString(data.ToArray())}"); - if (_pendingCommands.TryGetValue(id.Value, out var errorCommand)) + if (_pendingCommands.TryRemove(id.Value, out var errorCommand)) { errorCommand.TaskCompletionSource.TrySetException(new BiDiException($"{error}: {message}")); - _pendingCommands.TryRemove(id.Value, out _); } else { diff --git a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs index 8db5e1a34d875..d0e847adaf826 100644 --- a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs @@ -18,75 +18,90 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Browser.BrowserJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Browser; -public sealed class BrowserModule : Module, IBrowserModule +internal sealed class BrowserModule : Module, IBrowserModule { - private static readonly BrowserJsonSerializerContext JsonContext = BrowserJsonSerializerContext.Default; + private static readonly Command CloseCommand = new( + "browser.close", Default.Parameters, Default.CloseResult); + + private static readonly Command CreateUserContextCommand = new( + "browser.createUserContext", Default.CreateUserContextParameters, Default.CreateUserContextResult); + + private static readonly Command GetUserContextsCommand = new( + "browser.getUserContexts", Default.Parameters, Default.GetUserContextsResult); + + private static readonly Command RemoveUserContextCommand = new( + "browser.removeUserContext", Default.RemoveUserContextParameters, Default.RemoveUserContextResult); + + private static readonly Command GetClientWindowsCommand = new( + "browser.getClientWindows", Default.Parameters, Default.GetClientWindowsResult); + + private static readonly Command SetDownloadBehaviorCommand = new( + "browser.setDownloadBehavior", Default.SetDownloadBehaviorParameters, Default.SetDownloadBehaviorResult); public async Task CloseAsync(CloseOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new CloseCommand(), options, JsonContext.CloseCommand, JsonContext.CloseResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(CloseCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } public async Task CreateUserContextAsync(CreateUserContextOptions? options = null, CancellationToken cancellationToken = default) { var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior); - return await ExecuteCommandAsync(new CreateUserContextCommand(@params), options, JsonContext.CreateUserContextCommand, JsonContext.CreateUserContextResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(CreateUserContextCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task GetUserContextsAsync(GetUserContextsOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new GetUserContextsCommand(), options, JsonContext.GetUserContextsCommand, JsonContext.GetUserContextsResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(GetUserContextsCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } public async Task RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null, CancellationToken cancellationToken = default) { var @params = new RemoveUserContextParameters(userContext); - return await ExecuteCommandAsync(new RemoveUserContextCommand(@params), options, JsonContext.RemoveUserContextCommand, JsonContext.RemoveUserContextResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(RemoveUserContextCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task GetClientWindowsAsync(GetClientWindowsOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new(), options, JsonContext.GetClientWindowsCommand, JsonContext.GetClientWindowsResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(GetClientWindowsCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } public async Task SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts); - return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.SetDownloadBehaviorResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts); - return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.SetDownloadBehaviorResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts); - return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, JsonContext.SetDownloadBehaviorCommand, JsonContext.SetDownloadBehaviorResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); } } -[JsonSerializable(typeof(CloseCommand))] +[JsonSerializable(typeof(Parameters))] [JsonSerializable(typeof(CloseResult))] -[JsonSerializable(typeof(CreateUserContextCommand))] +[JsonSerializable(typeof(CreateUserContextParameters))] [JsonSerializable(typeof(CreateUserContextResult))] -[JsonSerializable(typeof(GetUserContextsCommand))] [JsonSerializable(typeof(GetUserContextsResult))] -[JsonSerializable(typeof(RemoveUserContextCommand))] +[JsonSerializable(typeof(RemoveUserContextParameters))] [JsonSerializable(typeof(RemoveUserContextResult))] -[JsonSerializable(typeof(GetClientWindowsCommand))] [JsonSerializable(typeof(GetClientWindowsResult))] -[JsonSerializable(typeof(SetDownloadBehaviorCommand))] +[JsonSerializable(typeof(SetDownloadBehaviorParameters))] [JsonSerializable(typeof(SetDownloadBehaviorResult))] [JsonSourceGenerationOptions( diff --git a/dotnet/src/webdriver/BiDi/Browser/CloseCommand.cs b/dotnet/src/webdriver/BiDi/Browser/Close.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Browser/CloseCommand.cs rename to dotnet/src/webdriver/BiDi/Browser/Close.cs index 6b1e36e682c59..5efc9a1d676b8 100644 --- a/dotnet/src/webdriver/BiDi/Browser/CloseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/Close.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Browser; -internal sealed class CloseCommand() - : Command(Parameters.Empty, "browser.close"); - public sealed record CloseOptions : CommandOptions; public sealed record CloseResult : EmptyResult; diff --git a/dotnet/src/webdriver/BiDi/Browser/CreateUserContextCommand.cs b/dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Browser/CreateUserContextCommand.cs rename to dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs index db0795f62e126..b73759a0ac1f5 100644 --- a/dotnet/src/webdriver/BiDi/Browser/CreateUserContextCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/CreateUserContext.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Browser; -internal sealed class CreateUserContextCommand(CreateUserContextParameters @params) - : Command(@params, "browser.createUserContext"); - internal sealed record CreateUserContextParameters(bool? AcceptInsecureCerts, Session.ProxyConfiguration? Proxy, Session.UserPromptHandler? UnhandledPromptBehavior) : Parameters; public sealed record CreateUserContextOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs b/dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs similarity index 82% rename from dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs rename to dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs index f0967769c58b6..c64f92b2f7e4e 100644 --- a/dotnet/src/webdriver/BiDi/Browser/GetClientWindowsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/GetClientWindows.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Browser; -internal sealed class GetClientWindowsCommand() - : Command(Parameters.Empty, "browser.getClientWindows"); - public sealed record GetClientWindowsOptions : CommandOptions; public sealed record GetClientWindowsResult(IReadOnlyList ClientWindows) : EmptyResult; diff --git a/dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs b/dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs similarity index 82% rename from dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs rename to dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs index b7f287fa702ea..f8e9ca7dffcd7 100644 --- a/dotnet/src/webdriver/BiDi/Browser/GetUserContextsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/GetUserContexts.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Browser; -internal sealed class GetUserContextsCommand() - : Command(Parameters.Empty, "browser.getUserContexts"); - public record GetUserContextsOptions : CommandOptions; public sealed record GetUserContextsResult(IReadOnlyList UserContexts) : EmptyResult; diff --git a/dotnet/src/webdriver/BiDi/Browser/RemoveUserContextCommand.cs b/dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs similarity index 79% rename from dotnet/src/webdriver/BiDi/Browser/RemoveUserContextCommand.cs rename to dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs index 4ae2b1351e73d..fad7cf28f3358 100644 --- a/dotnet/src/webdriver/BiDi/Browser/RemoveUserContextCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/RemoveUserContext.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Browser; -internal sealed class RemoveUserContextCommand(RemoveUserContextParameters @params) - : Command(@params, "browser.removeUserContext"); - internal sealed record RemoveUserContextParameters(UserContext UserContext) : Parameters; public sealed record RemoveUserContextOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs rename to dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs index 2565c2ea9277d..aef71f681dc28 100644 --- a/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Browser; -internal sealed class SetDownloadBehaviorCommand(SetDownloadBehaviorParameters @params) - : Command(@params, "browser.setDownloadBehavior"); - internal sealed record SetDownloadBehaviorParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] DownloadBehavior? DownloadBehavior, IEnumerable? UserContexts) : Parameters; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/ActivateCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs similarity index 82% rename from dotnet/src/webdriver/BiDi/BrowsingContext/ActivateCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs index da3ac83cbee08..4e241347f41d2 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/ActivateCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Activate.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class ActivateCommand(ActivateParameters @params) - : Command(@params, "browsingContext.activate"); - internal sealed record ActivateParameters(BrowsingContext Context) : Parameters; public sealed record ActivateOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs index d57553a02d284..93ab39a381714 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextInputModule.cs @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContextInputModule(BrowsingContext context, IInputModule inputModule) : IBrowsingContextInputModule +internal sealed class BrowsingContextInputModule(BrowsingContext context, IInputModule inputModule) : IBrowsingContextInputModule { public Task PerformActionsAsync(IEnumerable actions, PerformActionsOptions? options = null, CancellationToken cancellationToken = default) { diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs index 9e29d351125e8..02314c3d5c7a1 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextLogModule.cs @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContextLogModule(BrowsingContext context, ILogModule logModule) : IBrowsingContextLogModule +internal sealed class BrowsingContextLogModule(BrowsingContext context, ILogModule logModule) : IBrowsingContextLogModule { public Task OnEntryAddedAsync(Func handler, ContextSubscriptionOptions? options = null, CancellationToken cancellationToken = default) { diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs index f9e8594995000..da8ddf663238a 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextModule.cs @@ -18,235 +18,270 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.BrowsingContext.BrowsingContextJsonSerializerContext; namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContextModule : Module, IBrowsingContextModule +internal sealed class BrowsingContextModule : Module, IBrowsingContextModule { - private static readonly BrowsingContextJsonSerializerContext JsonContext = BrowsingContextJsonSerializerContext.Default; + private static readonly Command CreateCommand = new( + "browsingContext.create", Default.CreateParameters, Default.CreateResult); + + private static readonly Command NavigateCommand = new( + "browsingContext.navigate", Default.NavigateParameters, Default.NavigateResult); + + private static readonly Command ActivateCommand = new( + "browsingContext.activate", Default.ActivateParameters, Default.ActivateResult); + + private static readonly Command LocateNodesCommand = new( + "browsingContext.locateNodes", Default.LocateNodesParameters, Default.LocateNodesResult); + + private static readonly Command CaptureScreenshotCommand = new( + "browsingContext.captureScreenshot", Default.CaptureScreenshotParameters, Default.CaptureScreenshotResult); + + private static readonly Command CloseCommand = new( + "browsingContext.close", Default.CloseParameters, Default.CloseResult); + + private static readonly Command TraverseHistoryCommand = new( + "browsingContext.traverseHistory", Default.TraverseHistoryParameters, Default.TraverseHistoryResult); + + private static readonly Command ReloadCommand = new( + "browsingContext.reload", Default.ReloadParameters, Default.ReloadResult); + + private static readonly Command SetViewportCommand = new( + "browsingContext.setViewport", Default.SetViewportParameters, Default.SetViewportResult); + + private static readonly Command GetTreeCommand = new( + "browsingContext.getTree", Default.GetTreeParameters, Default.GetTreeResult); + + private static readonly Command PrintCommand = new( + "browsingContext.print", Default.PrintParameters, Default.PrintResult); + + private static readonly Command HandleUserPromptCommand = new( + "browsingContext.handleUserPrompt", Default.HandleUserPromptParameters, Default.HandleUserPromptResult); public async Task CreateAsync(ContextType type, CreateOptions? options = null, CancellationToken cancellationToken = default) { var @params = new CreateParameters(type, options?.ReferenceContext, options?.Background, options?.UserContext); - return await ExecuteCommandAsync(new CreateCommand(@params), options, JsonContext.CreateCommand, JsonContext.CreateResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(CreateCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task NavigateAsync(BrowsingContext context, string url, NavigateOptions? options = null, CancellationToken cancellationToken = default) { var @params = new NavigateParameters(context, url, options?.Wait); - return await ExecuteCommandAsync(new NavigateCommand(@params), options, JsonContext.NavigateCommand, JsonContext.NavigateResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(NavigateCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task ActivateAsync(BrowsingContext context, ActivateOptions? options = null, CancellationToken cancellationToken = default) { var @params = new ActivateParameters(context); - return await ExecuteCommandAsync(new ActivateCommand(@params), options, JsonContext.ActivateCommand, JsonContext.ActivateResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ActivateCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task LocateNodesAsync(BrowsingContext context, Locator locator, LocateNodesOptions? options = null, CancellationToken cancellationToken = default) { var @params = new LocateNodesParameters(context, locator, options?.MaxNodeCount, options?.SerializationOptions, options?.StartNodes); - return await ExecuteCommandAsync(new LocateNodesCommand(@params), options, JsonContext.LocateNodesCommand, JsonContext.LocateNodesResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(LocateNodesCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task CaptureScreenshotAsync(BrowsingContext context, CaptureScreenshotOptions? options = null, CancellationToken cancellationToken = default) { var @params = new CaptureScreenshotParameters(context, options?.Origin, options?.Format, options?.Clip); - return await ExecuteCommandAsync(new CaptureScreenshotCommand(@params), options, JsonContext.CaptureScreenshotCommand, JsonContext.CaptureScreenshotResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(CaptureScreenshotCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task CloseAsync(BrowsingContext context, CloseOptions? options = null, CancellationToken cancellationToken = default) { var @params = new CloseParameters(context, options?.PromptUnload); - return await ExecuteCommandAsync(new CloseCommand(@params), options, JsonContext.CloseCommand, JsonContext.CloseResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(CloseCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task TraverseHistoryAsync(BrowsingContext context, int delta, TraverseHistoryOptions? options = null, CancellationToken cancellationToken = default) { var @params = new TraverseHistoryParameters(context, delta); - return await ExecuteCommandAsync(new TraverseHistoryCommand(@params), options, JsonContext.TraverseHistoryCommand, JsonContext.TraverseHistoryResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(TraverseHistoryCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task ReloadAsync(BrowsingContext context, ReloadOptions? options = null, CancellationToken cancellationToken = default) { var @params = new ReloadParameters(context, options?.IgnoreCache, options?.Wait); - return await ExecuteCommandAsync(new ReloadCommand(@params), options, JsonContext.ReloadCommand, JsonContext.ReloadResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ReloadCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetViewportAsync(SetViewportOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetViewportParameters(options?.Context, options?.Viewport, options?.DevicePixelRatio, options?.UserContexts); - return await ExecuteCommandAsync(new SetViewportCommand(@params), options, JsonContext.SetViewportCommand, JsonContext.SetViewportResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetViewportCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task GetTreeAsync(GetTreeOptions? options = null, CancellationToken cancellationToken = default) { var @params = new GetTreeParameters(options?.MaxDepth, options?.Root); - return await ExecuteCommandAsync(new GetTreeCommand(@params), options, JsonContext.GetTreeCommand, JsonContext.GetTreeResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(GetTreeCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task PrintAsync(BrowsingContext context, PrintOptions? options = null, CancellationToken cancellationToken = default) { var @params = new PrintParameters(context, options?.Background, options?.Margin, options?.Orientation, options?.Page, options?.PageRanges, options?.Scale, options?.ShrinkToFit); - return await ExecuteCommandAsync(new PrintCommand(@params), options, JsonContext.PrintCommand, JsonContext.PrintResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(PrintCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task HandleUserPromptAsync(BrowsingContext context, HandleUserPromptOptions? options = null, CancellationToken cancellationToken = default) { var @params = new HandleUserPromptParameters(context, options?.Accept, options?.UserText); - return await ExecuteCommandAsync(new HandleUserPromptCommand(@params), options, JsonContext.HandleUserPromptCommand, JsonContext.HandleUserPromptResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(HandleUserPromptCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationStartedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationStarted", handler, CreateNavigationStartedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationStarted", handler, CreateNavigationStartedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationStartedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationStarted", handler, CreateNavigationStartedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationStarted", handler, CreateNavigationStartedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnFragmentNavigatedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.fragmentNavigated", handler, CreateFragmentNavigatedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.fragmentNavigated", handler, CreateFragmentNavigatedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnFragmentNavigatedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.fragmentNavigated", handler, CreateFragmentNavigatedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.fragmentNavigated", handler, CreateFragmentNavigatedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnHistoryUpdatedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.historyUpdated", handler, CreateHistoryUpdatedEventArgs, options, JsonContext.HistoryUpdatedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.historyUpdated", handler, CreateHistoryUpdatedEventArgs, options, Default.HistoryUpdatedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnHistoryUpdatedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.historyUpdated", handler, CreateHistoryUpdatedEventArgs, options, JsonContext.HistoryUpdatedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.historyUpdated", handler, CreateHistoryUpdatedEventArgs, options, Default.HistoryUpdatedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnDomContentLoadedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.domContentLoaded", handler, CreateDomContentLoadedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.domContentLoaded", handler, CreateDomContentLoadedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnDomContentLoadedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.domContentLoaded", handler, CreateDomContentLoadedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.domContentLoaded", handler, CreateDomContentLoadedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnLoadAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.load", handler, CreateLoadEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.load", handler, CreateLoadEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnLoadAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.load", handler, CreateLoadEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.load", handler, CreateLoadEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnDownloadWillBeginAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.downloadWillBegin", handler, CreateDownloadWillBeginEventArgs, options, JsonContext.DownloadWillBeginParams, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.downloadWillBegin", handler, CreateDownloadWillBeginEventArgs, options, Default.DownloadWillBeginParams, cancellationToken).ConfigureAwait(false); } public async Task OnDownloadWillBeginAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.downloadWillBegin", handler, CreateDownloadWillBeginEventArgs, options, JsonContext.DownloadWillBeginParams, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.downloadWillBegin", handler, CreateDownloadWillBeginEventArgs, options, Default.DownloadWillBeginParams, cancellationToken).ConfigureAwait(false); } public async Task OnDownloadEndAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.downloadEnd", handler, CreateDownloadEndEventArgs, options, JsonContext.DownloadEndParams, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.downloadEnd", handler, CreateDownloadEndEventArgs, options, Default.DownloadEndParams, cancellationToken).ConfigureAwait(false); } public async Task OnDownloadEndAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.downloadEnd", handler, CreateDownloadEndEventArgs, options, JsonContext.DownloadEndParams, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.downloadEnd", handler, CreateDownloadEndEventArgs, options, Default.DownloadEndParams, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationAbortedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationAborted", handler, CreateNavigationAbortedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationAborted", handler, CreateNavigationAbortedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationAbortedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationAborted", handler, CreateNavigationAbortedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationAborted", handler, CreateNavigationAbortedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationFailedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationFailed", handler, CreateNavigationFailedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationFailed", handler, CreateNavigationFailedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationFailedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationFailed", handler, CreateNavigationFailedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationFailed", handler, CreateNavigationFailedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationCommittedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationCommitted", handler, CreateNavigationCommittedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationCommitted", handler, CreateNavigationCommittedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnNavigationCommittedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.navigationCommitted", handler, CreateNavigationCommittedEventArgs, options, JsonContext.NavigationInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.navigationCommitted", handler, CreateNavigationCommittedEventArgs, options, Default.NavigationInfo, cancellationToken).ConfigureAwait(false); } public async Task OnContextCreatedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.contextCreated", handler, CreateContextCreatedEventArgs, options, JsonContext.Info, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.contextCreated", handler, CreateContextCreatedEventArgs, options, Default.Info, cancellationToken).ConfigureAwait(false); } public async Task OnContextCreatedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.contextCreated", handler, CreateContextCreatedEventArgs, options, JsonContext.Info, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.contextCreated", handler, CreateContextCreatedEventArgs, options, Default.Info, cancellationToken).ConfigureAwait(false); } public async Task OnContextDestroyedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.contextDestroyed", handler, CreateContextDestroyedEventArgs, options, JsonContext.Info, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.contextDestroyed", handler, CreateContextDestroyedEventArgs, options, Default.Info, cancellationToken).ConfigureAwait(false); } public async Task OnContextDestroyedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.contextDestroyed", handler, CreateContextDestroyedEventArgs, options, JsonContext.Info, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.contextDestroyed", handler, CreateContextDestroyedEventArgs, options, Default.Info, cancellationToken).ConfigureAwait(false); } public async Task OnUserPromptOpenedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.userPromptOpened", handler, CreateUserPromptOpenedEventArgs, options, JsonContext.UserPromptOpenedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.userPromptOpened", handler, CreateUserPromptOpenedEventArgs, options, Default.UserPromptOpenedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnUserPromptOpenedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.userPromptOpened", handler, CreateUserPromptOpenedEventArgs, options, JsonContext.UserPromptOpenedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.userPromptOpened", handler, CreateUserPromptOpenedEventArgs, options, Default.UserPromptOpenedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnUserPromptClosedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.userPromptClosed", handler, CreateUserPromptClosedEventArgs, options, JsonContext.UserPromptClosedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.userPromptClosed", handler, CreateUserPromptClosedEventArgs, options, Default.UserPromptClosedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnUserPromptClosedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("browsingContext.userPromptClosed", handler, CreateUserPromptClosedEventArgs, options, JsonContext.UserPromptClosedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("browsingContext.userPromptClosed", handler, CreateUserPromptClosedEventArgs, options, Default.UserPromptClosedParameters, cancellationToken).ConfigureAwait(false); } private static NavigationStartedEventArgs CreateNavigationStartedEventArgs(IBiDi bidi, NavigationInfo p) => new(bidi, p.Context, p.Navigation, p.Timestamp, p.Url, p.UserContext); @@ -283,29 +318,29 @@ public async Task OnUserPromptClosedAsync(Action new(bidi, p.Context, p.Accepted, p.Type, p.UserContext, p.UserText); } -[JsonSerializable(typeof(ActivateCommand))] +[JsonSerializable(typeof(ActivateParameters))] [JsonSerializable(typeof(ActivateResult))] -[JsonSerializable(typeof(CaptureScreenshotCommand))] +[JsonSerializable(typeof(CaptureScreenshotParameters))] [JsonSerializable(typeof(CaptureScreenshotResult))] -[JsonSerializable(typeof(CloseCommand))] +[JsonSerializable(typeof(CloseParameters))] [JsonSerializable(typeof(CloseResult))] -[JsonSerializable(typeof(CreateCommand))] +[JsonSerializable(typeof(CreateParameters))] [JsonSerializable(typeof(CreateResult))] -[JsonSerializable(typeof(GetTreeCommand))] +[JsonSerializable(typeof(GetTreeParameters))] [JsonSerializable(typeof(GetTreeResult))] -[JsonSerializable(typeof(HandleUserPromptCommand))] +[JsonSerializable(typeof(HandleUserPromptParameters))] [JsonSerializable(typeof(HandleUserPromptResult))] -[JsonSerializable(typeof(LocateNodesCommand))] +[JsonSerializable(typeof(LocateNodesParameters))] [JsonSerializable(typeof(LocateNodesResult))] -[JsonSerializable(typeof(NavigateCommand))] +[JsonSerializable(typeof(NavigateParameters))] [JsonSerializable(typeof(NavigateResult))] -[JsonSerializable(typeof(PrintCommand))] +[JsonSerializable(typeof(PrintParameters))] [JsonSerializable(typeof(PrintResult))] -[JsonSerializable(typeof(ReloadCommand))] +[JsonSerializable(typeof(ReloadParameters))] [JsonSerializable(typeof(ReloadResult))] -[JsonSerializable(typeof(SetViewportCommand))] +[JsonSerializable(typeof(SetViewportParameters))] [JsonSerializable(typeof(SetViewportResult))] -[JsonSerializable(typeof(TraverseHistoryCommand))] +[JsonSerializable(typeof(TraverseHistoryParameters))] [JsonSerializable(typeof(TraverseHistoryResult))] [JsonSerializable(typeof(DownloadWillBeginParams))] diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs index 420cc6e6892b8..3e9c824a8488a 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContextNetworkModule(BrowsingContext context, INetworkModule networkModule) : IBrowsingContextNetworkModule +internal sealed class BrowsingContextNetworkModule(BrowsingContext context, INetworkModule networkModule) : IBrowsingContextNetworkModule { public Task AddDataCollectorAsync(IEnumerable dataTypes, int maxEncodedDataSize, ContextAddDataCollectorOptions? options = null, CancellationToken cancellationToken = default) { diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs index 233e60bd09d33..41138004d71ab 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs @@ -22,7 +22,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContextScriptModule(BrowsingContext context, IScriptModule scriptModule) : IBrowsingContextScriptModule +internal sealed class BrowsingContextScriptModule(BrowsingContext context, IScriptModule scriptModule) : IBrowsingContextScriptModule { public Task AddPreloadScriptAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string functionDeclaration, ContextAddPreloadScriptOptions? options = null, CancellationToken cancellationToken = default) { diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs index c88cd03ee9d09..989b864ed08d9 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextStorageModule.cs @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContextStorageModule(BrowsingContext context, IStorageModule storageModule) : IBrowsingContextStorageModule +internal sealed class BrowsingContextStorageModule(BrowsingContext context, IStorageModule storageModule) : IBrowsingContextStorageModule { public Task GetCookiesAsync(ContextGetCookiesOptions? options = null, CancellationToken cancellationToken = default) { diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshot.cs similarity index 88% rename from dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshot.cs index 3892d1dabad72..cadf54f01a793 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshot.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class CaptureScreenshotCommand(CaptureScreenshotParameters @params) - : Command(@params, "browsingContext.captureScreenshot"); - internal sealed record CaptureScreenshotParameters(BrowsingContext Context, ScreenshotOrigin? Origin, ImageFormat? Format, ClipRectangle? Clip) : Parameters; public sealed record CaptureScreenshotOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/CloseCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Close.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/BrowsingContext/CloseCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/Close.cs index 8283ff820594f..68217933227ca 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/CloseCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Close.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class CloseCommand(CloseParameters @params) - : Command(@params, "browsingContext.close"); - internal sealed record CloseParameters(BrowsingContext Context, bool? PromptUnload) : Parameters; public sealed record CloseOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/CreateCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Create.cs similarity index 87% rename from dotnet/src/webdriver/BiDi/BrowsingContext/CreateCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/Create.cs index 762b07f9e2296..bf3bbe6c9cfb8 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/CreateCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Create.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class CreateCommand(CreateParameters @params) - : Command(@params, "browsingContext.create"); - internal sealed record CreateParameters(ContextType Type, BrowsingContext? ReferenceContext, bool? Background, Browser.UserContext? UserContext) : Parameters; public sealed record CreateOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs similarity index 87% rename from dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs index c05cad1c33099..8c862bb368185 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/GetTreeCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/GetTree.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class GetTreeCommand(GetTreeParameters @params) - : Command(@params, "browsingContext.getTree"); - internal sealed record GetTreeParameters(long? MaxDepth, BrowsingContext? Root) : Parameters; public sealed record GetTreeOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPromptCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPrompt.cs similarity index 81% rename from dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPromptCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPrompt.cs index 3ed4c7f8ea1c0..0c0139cd8c450 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPromptCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/HandleUserPrompt.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class HandleUserPromptCommand(HandleUserPromptParameters @params) - : Command(@params, "browsingContext.handleUserPrompt"); - internal sealed record HandleUserPromptParameters(BrowsingContext Context, bool? Accept, string? UserText) : Parameters; public sealed record HandleUserPromptOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodes.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodes.cs index 1d0937863cf74..ba26c934d91cb 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/LocateNodes.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class LocateNodesCommand(LocateNodesParameters @params) - : Command(@params, "browsingContext.locateNodes"); - internal sealed record LocateNodesParameters(BrowsingContext Context, Locator Locator, long? MaxNodeCount, Script.SerializationOptions? SerializationOptions, IEnumerable? StartNodes) : Parameters; public sealed record LocateNodesOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/NavigateCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Navigate.cs similarity index 86% rename from dotnet/src/webdriver/BiDi/BrowsingContext/NavigateCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/Navigate.cs index 6f7d07f584c6c..5b84004a73941 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/NavigateCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Navigate.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class NavigateCommand(NavigateParameters @params) - : Command(@params, "browsingContext.navigate"); - internal sealed record NavigateParameters(BrowsingContext Context, string Url, ReadinessState? Wait) : Parameters; public sealed record NavigateOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Print.cs similarity index 94% rename from dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/Print.cs index c19a44a4d6711..886645743fb82 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Print.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class PrintCommand(PrintParameters @params) - : Command(@params, "browsingContext.print"); - internal sealed record PrintParameters(BrowsingContext Context, bool? Background, PrintMargin? Margin, PrintOrientation? Orientation, PrintPage? Page, IEnumerable? PageRanges, double? Scale, bool? ShrinkToFit) : Parameters; public sealed record PrintOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/ReloadCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/Reload.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/BrowsingContext/ReloadCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/Reload.cs index 8eba10f9718fe..a0d038ddaba36 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/ReloadCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/Reload.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class ReloadCommand(ReloadParameters @params) - : Command(@params, "browsingContext.reload"); - internal sealed record ReloadParameters(BrowsingContext Context, bool? IgnoreCache, ReadinessState? Wait) : Parameters; public sealed record ReloadOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/SetViewportCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs similarity index 90% rename from dotnet/src/webdriver/BiDi/BrowsingContext/SetViewportCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs index bc7d146ea4a4f..9df7438701872 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/SetViewportCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/SetViewport.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class SetViewportCommand(SetViewportParameters @params) - : Command(@params, "browsingContext.setViewport"); - internal sealed record SetViewportParameters( BrowsingContext? Context, [property: JsonConverter(typeof(OptionalConverter))] Optional? Viewport, diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistoryCommand.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistory.cs similarity index 80% rename from dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistoryCommand.cs rename to dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistory.cs index 2eaaf6bf3c0e2..f9c2196114ca9 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistoryCommand.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/TraverseHistory.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -internal sealed class TraverseHistoryCommand(TraverseHistoryParameters @params) - : Command(@params, "browsingContext.traverseHistory"); - internal sealed record TraverseHistoryParameters(BrowsingContext Context, long Delta) : Parameters; public sealed record TraverseHistoryOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Command.cs b/dotnet/src/webdriver/BiDi/Command.cs index edd887fdc6aaa..36e5ab460aed5 100644 --- a/dotnet/src/webdriver/BiDi/Command.cs +++ b/dotnet/src/webdriver/BiDi/Command.cs @@ -17,35 +17,25 @@ // under the License. // -using System.Text.Json.Serialization; +using System.Text.Json.Serialization.Metadata; namespace OpenQA.Selenium.BiDi; -public abstract class Command -{ - protected Command(string method) - { - Method = method; - } - - [JsonPropertyOrder(1)] - public string Method { get; } - - [JsonPropertyOrder(0)] - public long Id { get; internal set; } -} - -public abstract class Command(TParameters @params, string method) : Command(method) +public readonly record struct Command( + string Method, + JsonTypeInfo ParamsTypeInfo, + JsonTypeInfo ResultTypeInfo) where TParameters : Parameters - where TResult : EmptyResult -{ - [JsonPropertyOrder(2)] - public TParameters Params { get; } = @params; -} + where TResult : EmptyResult; public record Parameters { public static Parameters Empty { get; } = new Parameters(); } +public abstract record CommandOptions +{ + public TimeSpan? Timeout { get; init; } +} + public abstract record EmptyResult; diff --git a/dotnet/src/webdriver/BiDi/CommandOptions.cs b/dotnet/src/webdriver/BiDi/CommandOptions.cs deleted file mode 100644 index d79285ec8817b..0000000000000 --- a/dotnet/src/webdriver/BiDi/CommandOptions.cs +++ /dev/null @@ -1,25 +0,0 @@ -// -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -namespace OpenQA.Selenium.BiDi; - -public abstract record CommandOptions -{ - public TimeSpan? Timeout { get; init; } -} diff --git a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs index 62bf618ad1894..82fd31828e8a0 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs @@ -18,128 +18,146 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Emulation.EmulationJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Emulation; -public sealed class EmulationModule : Module, IEmulationModule +internal sealed class EmulationModule : Module, IEmulationModule { - private static readonly EmulationJsonSerializerContext JsonContext = EmulationJsonSerializerContext.Default; + private static readonly Command SetTimezoneOverrideCommand = new( + "emulation.setTimezoneOverride", Default.SetTimezoneOverrideParameters, Default.SetTimezoneOverrideResult); + + private static readonly Command SetUserAgentOverrideCommand = new( + "emulation.setUserAgentOverride", Default.SetUserAgentOverrideParameters, Default.SetUserAgentOverrideResult); + + private static readonly Command SetLocaleOverrideCommand = new( + "emulation.setLocaleOverride", Default.SetLocaleOverrideParameters, Default.SetLocaleOverrideResult); + + private static readonly Command SetForcedColorsModeThemeOverrideCommand = new( + "emulation.setForcedColorsModeThemeOverride", Default.SetForcedColorsModeThemeOverrideParameters, Default.SetForcedColorsModeThemeOverrideResult); + + private static readonly Command SetScriptingEnabledCommand = new( + "emulation.setScriptingEnabled", Default.SetScriptingEnabledParameters, Default.SetScriptingEnabledResult); + + private static readonly Command SetScreenOrientationOverrideCommand = new( + "emulation.setScreenOrientationOverride", Default.SetScreenOrientationOverrideParameters, Default.SetScreenOrientationOverrideResult); + + private static readonly Command SetScreenSettingsOverrideCommand = new( + "emulation.setScreenSettingsOverride", Default.SetScreenSettingsOverrideParameters, Default.SetScreenSettingsOverrideResult); + + private static readonly Command SetScrollbarTypeOverrideCommand = new( + "emulation.setScrollbarTypeOverride", Default.SetScrollbarTypeOverrideParameters, Default.SetScrollbarTypeOverrideResult); + + private static readonly Command SetGeolocationOverrideCommand = new( + "emulation.setGeolocationOverride", Default.SetGeolocationOverrideParameters, Default.SetGeolocationOverrideResult); + + private static readonly Command SetTouchOverrideCommand = new( + "emulation.setTouchOverride", Default.SetTouchOverrideParameters, Default.SetTouchOverrideResult); + + private static readonly Command SetNetworkConditionsCommand = new( + "emulation.setNetworkConditions", Default.SetNetworkConditionsParameters, Default.SetNetworkConditionsResult); public async Task SetTimezoneOverrideAsync(string? timezone, SetTimezoneOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetTimezoneOverrideParameters(timezone, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetTimezoneOverrideCommand(@params), options, JsonContext.SetTimezoneOverrideCommand, JsonContext.SetTimezoneOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetTimezoneOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetUserAgentOverrideAsync(string? userAgent, SetUserAgentOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetUserAgentOverrideParameters(userAgent, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetUserAgentOverrideCommand(@params), options, JsonContext.SetUserAgentOverrideCommand, JsonContext.SetUserAgentOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetUserAgentOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetLocaleOverrideAsync(string? locale, SetLocaleOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetLocaleOverrideParameters(locale, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetLocaleOverrideCommand(@params), options, JsonContext.SetLocaleOverrideCommand, JsonContext.SetLocaleOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetLocaleOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme? theme, SetForcedColorsModeThemeOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetForcedColorsModeThemeOverrideParameters(theme, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetForcedColorsModeThemeOverrideCommand(@params), options, JsonContext.SetForcedColorsModeThemeOverrideCommand, JsonContext.SetForcedColorsModeThemeOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetForcedColorsModeThemeOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetScriptingEnabledAsync(bool? enabled, SetScriptingEnabledOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetScriptingEnabledParameters(enabled, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetScriptingEnabledCommand(@params), options, JsonContext.SetScriptingEnabledCommand, JsonContext.SetScriptingEnabledResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetScriptingEnabledCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetScreenOrientationOverrideAsync(ScreenOrientation? screenOrientation, SetScreenOrientationOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetScreenOrientationOverrideParameters(screenOrientation, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetScreenOrientationOverrideCommand(@params), options, JsonContext.SetScreenOrientationOverrideCommand, JsonContext.SetScreenOrientationOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetScreenOrientationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetScreenSettingsOverrideAsync(ScreenArea? screenArea, SetScreenSettingsOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetScreenSettingsOverrideParameters(screenArea, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetScreenSettingsOverrideCommand(@params), options, JsonContext.SetScreenSettingsOverrideCommand, JsonContext.SetScreenSettingsOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetScreenSettingsOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetScrollbarTypeOverrideAsync(ScrollbarType? scrollbarType, SetScrollbarTypeOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetScrollbarTypeOverrideParameters(scrollbarType, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetScrollbarTypeOverrideCommand(@params), options, JsonContext.SetScrollbarTypeOverrideCommand, JsonContext.SetScrollbarTypeOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetScrollbarTypeOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null, CancellationToken cancellationToken = default) { var coordinates = new GeolocationCoordinates(latitude, longitude, options?.Accuracy, options?.Altitude, options?.AltitudeAccuracy, options?.Heading, options?.Speed); - var @params = new SetGeolocationOverrideCoordinatesParameters(coordinates, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options, JsonContext.SetGeolocationOverrideCommand, JsonContext.SetGeolocationOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetGeolocationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetGeolocationCoordinatesOverrideAsync(SetGeolocationOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetGeolocationOverrideCoordinatesParameters(null, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options, JsonContext.SetGeolocationOverrideCommand, JsonContext.SetGeolocationOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetGeolocationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetGeolocationPositionErrorOverrideAsync(SetGeolocationPositionErrorOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetGeolocationOverridePositionErrorParameters(new GeolocationPositionError(), options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options, JsonContext.SetGeolocationOverrideCommand, JsonContext.SetGeolocationOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetGeolocationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetTouchOverrideAsync(long? maxTouchPoints, SetTouchOverrideOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetTouchOverrideParameters(maxTouchPoints, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetTouchOverrideCommand(@params), options, JsonContext.SetTouchOverrideCommand, JsonContext.SetTouchOverrideResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetTouchOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetNetworkConditionsAsync(NetworkConditions? networkConditions, SetNetworkConditionsOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetNetworkConditionsParameters(networkConditions, options?.Contexts, options?.UserContexts); - - return await ExecuteCommandAsync(new SetNetworkConditionsCommand(@params), options, JsonContext.SetNetworkConditionsCommand, JsonContext.SetNetworkConditionsResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetNetworkConditionsCommand, @params, options, cancellationToken).ConfigureAwait(false); } } -[JsonSerializable(typeof(SetTimezoneOverrideCommand))] +[JsonSerializable(typeof(SetTimezoneOverrideParameters))] [JsonSerializable(typeof(SetTimezoneOverrideResult))] -[JsonSerializable(typeof(SetUserAgentOverrideCommand))] +[JsonSerializable(typeof(SetUserAgentOverrideParameters))] [JsonSerializable(typeof(SetUserAgentOverrideResult))] -[JsonSerializable(typeof(SetLocaleOverrideCommand))] +[JsonSerializable(typeof(SetLocaleOverrideParameters))] [JsonSerializable(typeof(SetLocaleOverrideResult))] -[JsonSerializable(typeof(SetForcedColorsModeThemeOverrideCommand))] +[JsonSerializable(typeof(SetForcedColorsModeThemeOverrideParameters))] [JsonSerializable(typeof(SetForcedColorsModeThemeOverrideResult))] -[JsonSerializable(typeof(SetScriptingEnabledCommand))] +[JsonSerializable(typeof(SetScriptingEnabledParameters))] [JsonSerializable(typeof(SetScriptingEnabledResult))] -[JsonSerializable(typeof(SetScreenOrientationOverrideCommand))] +[JsonSerializable(typeof(SetScreenOrientationOverrideParameters))] [JsonSerializable(typeof(SetScreenOrientationOverrideResult))] -[JsonSerializable(typeof(SetScreenSettingsOverrideCommand))] +[JsonSerializable(typeof(SetScreenSettingsOverrideParameters))] [JsonSerializable(typeof(SetScreenSettingsOverrideResult))] -[JsonSerializable(typeof(SetScrollbarTypeOverrideCommand))] +[JsonSerializable(typeof(SetScrollbarTypeOverrideParameters))] [JsonSerializable(typeof(SetScrollbarTypeOverrideResult))] -[JsonSerializable(typeof(SetGeolocationOverrideCommand))] +[JsonSerializable(typeof(SetGeolocationOverrideParameters))] [JsonSerializable(typeof(SetGeolocationOverrideResult))] -[JsonSerializable(typeof(SetTouchOverrideCommand))] +[JsonSerializable(typeof(SetTouchOverrideParameters))] [JsonSerializable(typeof(SetTouchOverrideResult))] -[JsonSerializable(typeof(SetNetworkConditionsCommand))] +[JsonSerializable(typeof(SetNetworkConditionsParameters))] [JsonSerializable(typeof(SetNetworkConditionsResult))] [JsonSourceGenerationOptions( diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverride.cs similarity index 82% rename from dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverride.cs index d743fce658ce3..4a47f47015ab4 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetForcedColorsModeThemeOverrideCommand(SetForcedColorsModeThemeOverrideParameters @params) - : Command(@params, "emulation.setForcedColorsModeThemeOverride"); - internal sealed record SetForcedColorsModeThemeOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ForcedColorsModeTheme? Theme, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetForcedColorsModeThemeOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverride.cs similarity index 90% rename from dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverride.cs index 153f291c9a5c2..3aef75e20846d 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetGeolocationOverrideCommand(SetGeolocationOverrideParameters @params) - : Command(@params, "emulation.setGeolocationOverride"); - [JsonDerivedType(typeof(SetGeolocationOverrideCoordinatesParameters))] [JsonDerivedType(typeof(SetGeolocationOverridePositionErrorParameters))] internal abstract record SetGeolocationOverrideParameters(IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverride.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverride.cs index 112fa0be6807c..e3c0338c1e167 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetLocaleOverrideCommand(SetLocaleOverrideParameters @params) - : Command(@params, "emulation.setLocaleOverride"); - internal sealed record SetLocaleOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? Locale, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetLocaleOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditionsCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditions.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditionsCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditions.cs index d29d16a670db3..cd16e78557ec3 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetNetworkConditions.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetNetworkConditionsCommand(SetNetworkConditionsParameters @params) - : Command(@params, "emulation.setNetworkConditions"); - internal sealed record SetNetworkConditionsParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] NetworkConditions? NetworkConditions, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverride.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverride.cs index e839b487d8fcc..b68b5b6dfe174 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetScreenOrientationOverrideCommand(SetScreenOrientationOverrideParameters @params) - : Command(@params, "emulation.setScreenOrientationOverride"); - internal sealed record SetScreenOrientationOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScreenOrientation? ScreenOrientation, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetScreenOrientationOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverride.cs similarity index 82% rename from dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverride.cs index 7e181c8f6881d..c2d2076608f3b 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScreenSettingsOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetScreenSettingsOverrideCommand(SetScreenSettingsOverrideParameters @params) - : Command(@params, "emulation.setScreenSettingsOverride"); - internal sealed record SetScreenSettingsOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScreenArea? ScreenArea, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetScreenSettingsOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabled.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabled.cs index f5255916b0264..d38e840659be7 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabled.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetScriptingEnabledCommand(SetScriptingEnabledParameters @params) - : Command(@params, "emulation.setScriptingEnabled"); - internal sealed record SetScriptingEnabledParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] bool? Enabled, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetScriptingEnabledOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverride.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverride.cs index 190d2411edbfc..9c700d2d1f016 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScrollbarTypeOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetScrollbarTypeOverrideCommand(SetScrollbarTypeOverrideParameters @params) - : Command(@params, "emulation.setScrollbarTypeOverride"); - internal sealed record SetScrollbarTypeOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScrollbarType? ScrollbarType, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetScrollbarTypeOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverride.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverride.cs index 8028b360bf552..f1e3854ad8e08 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetTimezoneOverrideCommand(SetTimezoneOverrideParameters @params) - : Command(@params, "emulation.setTimezoneOverride"); - internal sealed record SetTimezoneOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? Timezone, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetTimezoneOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetTouchOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetTouchOverride.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Emulation/SetTouchOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetTouchOverride.cs index 259579efc4954..aa1fcda9044df 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetTouchOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetTouchOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetTouchOverrideCommand(SetTouchOverrideParameters @params) - : Command(@params, "emulation.setTouchOverride"); - internal sealed record SetTouchOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] long? MaxTouchPoints, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetTouchOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverride.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs rename to dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverride.cs index a3164159843ee..8aafecd0fced5 100644 --- a/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs +++ b/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverride.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Emulation; -internal sealed class SetUserAgentOverrideCommand(SetUserAgentOverrideParameters @params) - : Command(@params, "emulation.setUserAgentOverride"); - internal sealed record SetUserAgentOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? UserAgent, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetUserAgentOverrideOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Input/InputModule.cs b/dotnet/src/webdriver/BiDi/Input/InputModule.cs index c484d8b2b7830..1673fa74ce5a1 100644 --- a/dotnet/src/webdriver/BiDi/Input/InputModule.cs +++ b/dotnet/src/webdriver/BiDi/Input/InputModule.cs @@ -18,42 +18,50 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Input.InputJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Input; -public sealed class InputModule : Module, IInputModule +internal sealed class InputModule : Module, IInputModule { - private static readonly InputJsonSerializerContext JsonContext = InputJsonSerializerContext.Default; + private static readonly Command PerformActionsCommand = new( + "input.performActions", Default.PerformActionsParameters, Default.PerformActionsResult); + + private static readonly Command ReleaseActionsCommand = new( + "input.releaseActions", Default.ReleaseActionsParameters, Default.ReleaseActionsResult); + + private static readonly Command SetFilesCommand = new( + "input.setFiles", Default.SetFilesParameters, Default.SetFilesResult); public async Task PerformActionsAsync(BrowsingContext.BrowsingContext context, IEnumerable actions, PerformActionsOptions? options = null, CancellationToken cancellationToken = default) { var @params = new PerformActionsParameters(context, actions); - return await ExecuteCommandAsync(new PerformActionsCommand(@params), options, JsonContext.PerformActionsCommand, JsonContext.PerformActionsResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(PerformActionsCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task ReleaseActionsAsync(BrowsingContext.BrowsingContext context, ReleaseActionsOptions? options = null, CancellationToken cancellationToken = default) { var @params = new ReleaseActionsParameters(context); - return await ExecuteCommandAsync(new ReleaseActionsCommand(@params), options, JsonContext.ReleaseActionsCommand, JsonContext.ReleaseActionsResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ReleaseActionsCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetFilesAsync(BrowsingContext.BrowsingContext context, Script.ISharedReference element, IEnumerable files, SetFilesOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetFilesParameters(context, element, files); - return await ExecuteCommandAsync(new SetFilesCommand(@params), options, JsonContext.SetFilesCommand, JsonContext.SetFilesResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetFilesCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task OnFileDialogOpenedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("input.fileDialogOpened", handler, CreateFileDialogOpenedEventArgs, options, JsonContext.FileDialogInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("input.fileDialogOpened", handler, CreateFileDialogOpenedEventArgs, options, Default.FileDialogInfo, cancellationToken).ConfigureAwait(false); } public async Task OnFileDialogOpenedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("input.fileDialogOpened", handler, CreateFileDialogOpenedEventArgs, options, JsonContext.FileDialogInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("input.fileDialogOpened", handler, CreateFileDialogOpenedEventArgs, options, Default.FileDialogInfo, cancellationToken).ConfigureAwait(false); } private static FileDialogOpenedEventArgs CreateFileDialogOpenedEventArgs(IBiDi bidi, FileDialogInfo p) @@ -62,11 +70,11 @@ private static FileDialogOpenedEventArgs CreateFileDialogOpenedEventArgs(IBiDi b } } -[JsonSerializable(typeof(PerformActionsCommand))] +[JsonSerializable(typeof(PerformActionsParameters))] [JsonSerializable(typeof(PerformActionsResult))] -[JsonSerializable(typeof(ReleaseActionsCommand))] +[JsonSerializable(typeof(ReleaseActionsParameters))] [JsonSerializable(typeof(ReleaseActionsResult))] -[JsonSerializable(typeof(SetFilesCommand))] +[JsonSerializable(typeof(SetFilesParameters))] [JsonSerializable(typeof(SetFilesResult))] [JsonSerializable(typeof(FileDialogInfo))] diff --git a/dotnet/src/webdriver/BiDi/Input/PerformActionsCommand.cs b/dotnet/src/webdriver/BiDi/Input/PerformActions.cs similarity index 81% rename from dotnet/src/webdriver/BiDi/Input/PerformActionsCommand.cs rename to dotnet/src/webdriver/BiDi/Input/PerformActions.cs index 33e6d27076930..4ec68d9608914 100644 --- a/dotnet/src/webdriver/BiDi/Input/PerformActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Input/PerformActions.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Input; -internal sealed class PerformActionsCommand(PerformActionsParameters @params) - : Command(@params, "input.performActions"); - internal sealed record PerformActionsParameters(BrowsingContext.BrowsingContext Context, IEnumerable Actions) : Parameters; public sealed record PerformActionsOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Input/ReleaseActionsCommand.cs b/dotnet/src/webdriver/BiDi/Input/ReleaseActions.cs similarity index 81% rename from dotnet/src/webdriver/BiDi/Input/ReleaseActionsCommand.cs rename to dotnet/src/webdriver/BiDi/Input/ReleaseActions.cs index b62ea69ccaa12..54ccb427cdc11 100644 --- a/dotnet/src/webdriver/BiDi/Input/ReleaseActionsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Input/ReleaseActions.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Input; -internal sealed class ReleaseActionsCommand(ReleaseActionsParameters @params) - : Command(@params, "input.releaseActions"); - internal sealed record ReleaseActionsParameters(BrowsingContext.BrowsingContext Context) : Parameters; public sealed record ReleaseActionsOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Input/SetFilesCommand.cs b/dotnet/src/webdriver/BiDi/Input/SetFiles.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Input/SetFilesCommand.cs rename to dotnet/src/webdriver/BiDi/Input/SetFiles.cs index a20c43556db08..5271088b4e784 100644 --- a/dotnet/src/webdriver/BiDi/Input/SetFilesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Input/SetFiles.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Input; -internal sealed class SetFilesCommand(SetFilesParameters @params) - : Command(@params, "input.setFiles"); - internal sealed record SetFilesParameters(BrowsingContext.BrowsingContext Context, Script.ISharedReference Element, IEnumerable Files) : Parameters; public sealed record SetFilesOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Log/LogModule.cs b/dotnet/src/webdriver/BiDi/Log/LogModule.cs index 1e0274317b6c4..342441fb2cdd9 100644 --- a/dotnet/src/webdriver/BiDi/Log/LogModule.cs +++ b/dotnet/src/webdriver/BiDi/Log/LogModule.cs @@ -18,21 +18,20 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Log.LogJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Log; -public sealed class LogModule : Module, ILogModule +internal sealed class LogModule : Module, ILogModule { - private static readonly LogJsonSerializerContext JsonContext = LogJsonSerializerContext.Default; - public async Task OnEntryAddedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("log.entryAdded", handler, CreateEntryAddedEventArgs, options, JsonContext.LogEntry, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("log.entryAdded", handler, CreateEntryAddedEventArgs, options, Default.LogEntry, cancellationToken).ConfigureAwait(false); } public async Task OnEntryAddedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("log.entryAdded", handler, CreateEntryAddedEventArgs, options, JsonContext.LogEntry, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("log.entryAdded", handler, CreateEntryAddedEventArgs, options, Default.LogEntry, cancellationToken).ConfigureAwait(false); } private static EntryAddedEventArgs CreateEntryAddedEventArgs(IBiDi bidi, LogEntry p) => p switch diff --git a/dotnet/src/webdriver/BiDi/Module.cs b/dotnet/src/webdriver/BiDi/Module.cs index 52da371035eaa..934406b253f0a 100644 --- a/dotnet/src/webdriver/BiDi/Module.cs +++ b/dotnet/src/webdriver/BiDi/Module.cs @@ -25,11 +25,11 @@ public abstract class Module { private Broker Broker { get; set; } = null!; - protected Task ExecuteCommandAsync(TCommand command, CommandOptions? options, JsonTypeInfo jsonCommandTypeInfo, JsonTypeInfo jsonResultTypeInfo, CancellationToken cancellationToken) - where TCommand : Command + protected Task ExecuteAsync(Command descriptor, TParameters @params, CommandOptions? options, CancellationToken cancellationToken) + where TParameters : Parameters where TResult : EmptyResult { - return Broker.ExecuteCommandAsync(command, options, jsonCommandTypeInfo, jsonResultTypeInfo, cancellationToken); + return Broker.ExecuteAsync(descriptor, @params, options, cancellationToken); } protected Task SubscribeAsync(string name, Action action, Func factory, SubscriptionOptions? options, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken) diff --git a/dotnet/src/webdriver/BiDi/Network/AddDataCollectorCommand.cs b/dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs similarity index 89% rename from dotnet/src/webdriver/BiDi/Network/AddDataCollectorCommand.cs rename to dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs index 67ab52c1aa405..a5db15c0843b5 100644 --- a/dotnet/src/webdriver/BiDi/Network/AddDataCollectorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/AddDataCollector.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class AddDataCollectorCommand(AddDataCollectorParameters @params) - : Command(@params, "network.addDataCollector"); - internal sealed record AddDataCollectorParameters(IEnumerable DataTypes, int MaxEncodedDataSize, CollectorType? CollectorType, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record AddDataCollectorOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/AddInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Network/AddIntercept.cs similarity index 88% rename from dotnet/src/webdriver/BiDi/Network/AddInterceptCommand.cs rename to dotnet/src/webdriver/BiDi/Network/AddIntercept.cs index d5dddb03b07dc..c8dbf1eca435d 100644 --- a/dotnet/src/webdriver/BiDi/Network/AddInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/AddIntercept.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class AddInterceptCommand(AddInterceptParameters @params) - : Command(@params, "network.addIntercept"); - internal sealed record AddInterceptParameters(IEnumerable Phases, IEnumerable? Contexts, IEnumerable? UrlPatterns) : Parameters; public record AddInterceptOptions() : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/ContinueRequestCommand.cs b/dotnet/src/webdriver/BiDi/Network/ContinueRequest.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Network/ContinueRequestCommand.cs rename to dotnet/src/webdriver/BiDi/Network/ContinueRequest.cs index 1fa5246363236..5515ed8bd50de 100644 --- a/dotnet/src/webdriver/BiDi/Network/ContinueRequestCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/ContinueRequest.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class ContinueRequestCommand(ContinueRequestParameters @params) - : Command(@params, "network.continueRequest"); - internal sealed record ContinueRequestParameters(Request Request, BytesValue? Body, IEnumerable? Cookies, IEnumerable
? Headers, string? Method, string? Url) : Parameters; public sealed record ContinueRequestOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/ContinueResponseCommand.cs b/dotnet/src/webdriver/BiDi/Network/ContinueResponse.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Network/ContinueResponseCommand.cs rename to dotnet/src/webdriver/BiDi/Network/ContinueResponse.cs index 797cdaeb012f9..fe2c73289f9bc 100644 --- a/dotnet/src/webdriver/BiDi/Network/ContinueResponseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/ContinueResponse.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class ContinueResponseCommand(ContinueResponseParameters @params) - : Command(@params, "network.continueResponse"); - internal sealed record ContinueResponseParameters(Request Request, IEnumerable? Cookies, IEnumerable? Credentials, IEnumerable
? Headers, string? ReasonPhrase, long? StatusCode) : Parameters; public sealed record ContinueResponseOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/ContinueWithAuthCommand.cs b/dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs similarity index 89% rename from dotnet/src/webdriver/BiDi/Network/ContinueWithAuthCommand.cs rename to dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs index b83a529ae26aa..a5805a9a6f33b 100644 --- a/dotnet/src/webdriver/BiDi/Network/ContinueWithAuthCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/ContinueWithAuth.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal class ContinueWithAuthCommand(ContinueWithAuthParameters @params) - : Command(@params, "network.continueWithAuth"); - [JsonPolymorphic(TypeDiscriminatorPropertyName = "action")] [JsonDerivedType(typeof(ContinueWithAuthCredentials), "provideCredentials")] [JsonDerivedType(typeof(ContinueWithAuthDefaultCredentials), "default")] diff --git a/dotnet/src/webdriver/BiDi/Network/FailRequestCommand.cs b/dotnet/src/webdriver/BiDi/Network/FailRequest.cs similarity index 81% rename from dotnet/src/webdriver/BiDi/Network/FailRequestCommand.cs rename to dotnet/src/webdriver/BiDi/Network/FailRequest.cs index 721c6135af0cd..3a8b03ae511b7 100644 --- a/dotnet/src/webdriver/BiDi/Network/FailRequestCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/FailRequest.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class FailRequestCommand(FailRequestParameters @params) - : Command(@params, "network.failRequest"); - internal sealed record FailRequestParameters(Request Request) : Parameters; public sealed record FailRequestOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Network/GetDataCommand.cs b/dotnet/src/webdriver/BiDi/Network/GetData.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/Network/GetDataCommand.cs rename to dotnet/src/webdriver/BiDi/Network/GetData.cs index 04aee9ef6b7fb..f8baf19ecf42b 100644 --- a/dotnet/src/webdriver/BiDi/Network/GetDataCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/GetData.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class GetDataCommand(GetDataParameters @params) - : Command(@params, "network.getData"); - internal sealed record GetDataParameters(DataType DataType, Request Request, Collector? Collector, bool? Disown) : Parameters; public sealed record GetDataOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs index 72c7a213b0ab3..6b2613ce25234 100644 --- a/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Network/NetworkModule.cs @@ -18,81 +18,117 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Network.NetworkJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Network; -public sealed partial class NetworkModule : Module, INetworkModule +internal sealed partial class NetworkModule : Module, INetworkModule { - private static readonly NetworkJsonSerializerContext JsonContext = NetworkJsonSerializerContext.Default; + + private static readonly Command AddDataCollectorCommand = new( + "network.addDataCollector", Default.AddDataCollectorParameters, Default.AddDataCollectorResult); + + private static readonly Command AddInterceptCommand = new( + "network.addIntercept", Default.AddInterceptParameters, Default.AddInterceptResult); + + private static readonly Command RemoveDataCollectorCommand = new( + "network.removeDataCollector", Default.RemoveDataCollectorParameters, Default.RemoveDataCollectorResult); + + private static readonly Command RemoveInterceptCommand = new( + "network.removeIntercept", Default.RemoveInterceptParameters, Default.RemoveInterceptResult); + + private static readonly Command SetCacheBehaviorCommand = new( + "network.setCacheBehavior", Default.SetCacheBehaviorParameters, Default.SetCacheBehaviorResult); + + private static readonly Command SetExtraHeadersCommand = new( + "network.setExtraHeaders", Default.SetExtraHeadersParameters, Default.SetExtraHeadersResult); + + private static readonly Command ContinueRequestCommand = new( + "network.continueRequest", Default.ContinueRequestParameters, Default.ContinueRequestResult); + + private static readonly Command ContinueResponseCommand = new( + "network.continueResponse", Default.ContinueResponseParameters, Default.ContinueResponseResult); + + private static readonly Command FailRequestCommand = new( + "network.failRequest", Default.FailRequestParameters, Default.FailRequestResult); + + private static readonly Command GetDataCommand = new( + "network.getData", Default.GetDataParameters, Default.GetDataResult); + + private static readonly Command ProvideResponseCommand = new( + "network.provideResponse", Default.ProvideResponseParameters, Default.ProvideResponseResult); + + private static readonly Command ContinueWithAuthCommand = new( + "network.continueWithAuth", Default.ContinueWithAuthParameters, Default.ContinueWithAuthResult); public async Task AddDataCollectorAsync(IEnumerable dataTypes, int maxEncodedDataSize, AddDataCollectorOptions? options = null, CancellationToken cancellationToken = default) { var @params = new AddDataCollectorParameters(dataTypes, maxEncodedDataSize, options?.CollectorType, options?.Contexts, options?.UserContexts); - return await ExecuteCommandAsync(new AddDataCollectorCommand(@params), options, JsonContext.AddDataCollectorCommand, JsonContext.AddDataCollectorResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(AddDataCollectorCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task AddInterceptAsync(IEnumerable phases, AddInterceptOptions? options = null, CancellationToken cancellationToken = default) { var @params = new AddInterceptParameters(phases, options?.Contexts, options?.UrlPatterns); - return await ExecuteCommandAsync(new AddInterceptCommand(@params), options, JsonContext.AddInterceptCommand, JsonContext.AddInterceptResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(AddInterceptCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task RemoveDataCollectorAsync(Collector collector, RemoveDataCollectorOptions? options = null, CancellationToken cancellationToken = default) { var @params = new RemoveDataCollectorParameters(collector); - return await ExecuteCommandAsync(new RemoveDataCollectorCommand(@params), options, JsonContext.RemoveDataCollectorCommand, JsonContext.RemoveDataCollectorResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(RemoveDataCollectorCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task RemoveInterceptAsync(Intercept intercept, RemoveInterceptOptions? options = null, CancellationToken cancellationToken = default) { var @params = new RemoveInterceptParameters(intercept); - return await ExecuteCommandAsync(new RemoveInterceptCommand(@params), options, JsonContext.RemoveInterceptCommand, JsonContext.RemoveInterceptResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(RemoveInterceptCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetCacheBehaviorAsync(CacheBehavior behavior, SetCacheBehaviorOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetCacheBehaviorParameters(behavior, options?.Contexts); - return await ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options, JsonContext.SetCacheBehaviorCommand, JsonContext.SetCacheBehaviorResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetCacheBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetExtraHeadersAsync(IEnumerable
headers, SetExtraHeadersOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetExtraHeadersParameters(headers, options?.Contexts, options?.UserContexts); - return await ExecuteCommandAsync(new SetExtraHeadersCommand(@params), options, JsonContext.SetExtraHeadersCommand, JsonContext.SetExtraHeadersResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetExtraHeadersCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task ContinueRequestAsync(Request request, ContinueRequestOptions? options = null, CancellationToken cancellationToken = default) { var @params = new ContinueRequestParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.Method, options?.Url); - return await ExecuteCommandAsync(new ContinueRequestCommand(@params), options, JsonContext.ContinueRequestCommand, JsonContext.ContinueRequestResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ContinueRequestCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task ContinueResponseAsync(Request request, ContinueResponseOptions? options = null, CancellationToken cancellationToken = default) { var @params = new ContinueResponseParameters(request, options?.Cookies, options?.Credentials, options?.Headers, options?.ReasonPhrase, options?.StatusCode); - return await ExecuteCommandAsync(new ContinueResponseCommand(@params), options, JsonContext.ContinueResponseCommand, JsonContext.ContinueResponseResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ContinueResponseCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task FailRequestAsync(Request request, FailRequestOptions? options = null, CancellationToken cancellationToken = default) { var @params = new FailRequestParameters(request); - return await ExecuteCommandAsync(new FailRequestCommand(@params), options, JsonContext.FailRequestCommand, JsonContext.FailRequestResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(FailRequestCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task GetDataAsync(DataType dataType, Request request, GetDataOptions? options = null, CancellationToken cancellationToken = default) { var @params = new GetDataParameters(dataType, request, options?.Collector, options?.Disown); - var result = await ExecuteCommandAsync(new GetDataCommand(@params), options, JsonContext.GetDataCommand, JsonContext.GetDataResult, cancellationToken).ConfigureAwait(false); + var result = await ExecuteAsync(GetDataCommand, @params, options, cancellationToken).ConfigureAwait(false); return result.Bytes; } @@ -101,72 +137,72 @@ public async Task ProvideResponseAsync(Request request, P { var @params = new ProvideResponseParameters(request, options?.Body, options?.Cookies, options?.Headers, options?.ReasonPhrase, options?.StatusCode); - return await ExecuteCommandAsync(new ProvideResponseCommand(@params), options, JsonContext.ProvideResponseCommand, JsonContext.ProvideResponseResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ProvideResponseCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task ContinueWithAuthAsync(Request request, AuthCredentials credentials, ContinueWithAuthCredentialsOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthCredentials(request, credentials)), options, JsonContext.ContinueWithAuthCommand, JsonContext.ContinueWithAuthResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ContinueWithAuthCommand, new ContinueWithAuthCredentials(request, credentials), options, cancellationToken).ConfigureAwait(false); } public async Task ContinueWithAuthAsync(Request request, ContinueWithAuthDefaultCredentialsOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthDefaultCredentials(request)), options, JsonContext.ContinueWithAuthCommand, JsonContext.ContinueWithAuthResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ContinueWithAuthCommand, new ContinueWithAuthDefaultCredentials(request), options, cancellationToken).ConfigureAwait(false); } public async Task ContinueWithAuthAsync(Request request, ContinueWithAuthCancelCredentialsOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new ContinueWithAuthCommand(new ContinueWithAuthCancelCredentials(request)), options, JsonContext.ContinueWithAuthCommand, JsonContext.ContinueWithAuthResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(ContinueWithAuthCommand, new ContinueWithAuthCancelCredentials(request), options, cancellationToken).ConfigureAwait(false); } public async Task OnBeforeRequestSentAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.beforeRequestSent", handler, CreateBeforeRequestSentEventArgs, options, JsonContext.BeforeRequestSentParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.beforeRequestSent", handler, CreateBeforeRequestSentEventArgs, options, Default.BeforeRequestSentParameters, cancellationToken).ConfigureAwait(false); } public async Task OnBeforeRequestSentAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.beforeRequestSent", handler, CreateBeforeRequestSentEventArgs, options, JsonContext.BeforeRequestSentParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.beforeRequestSent", handler, CreateBeforeRequestSentEventArgs, options, Default.BeforeRequestSentParameters, cancellationToken).ConfigureAwait(false); } public async Task OnResponseStartedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.responseStarted", handler, CreateResponseStartedEventArgs, options, JsonContext.ResponseStartedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.responseStarted", handler, CreateResponseStartedEventArgs, options, Default.ResponseStartedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnResponseStartedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.responseStarted", handler, CreateResponseStartedEventArgs, options, JsonContext.ResponseStartedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.responseStarted", handler, CreateResponseStartedEventArgs, options, Default.ResponseStartedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnResponseCompletedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.responseCompleted", handler, CreateResponseCompletedEventArgs, options, JsonContext.ResponseCompletedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.responseCompleted", handler, CreateResponseCompletedEventArgs, options, Default.ResponseCompletedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnResponseCompletedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.responseCompleted", handler, CreateResponseCompletedEventArgs, options, JsonContext.ResponseCompletedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.responseCompleted", handler, CreateResponseCompletedEventArgs, options, Default.ResponseCompletedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnFetchErrorAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.fetchError", handler, CreateFetchErrorEventArgs, options, JsonContext.FetchErrorParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.fetchError", handler, CreateFetchErrorEventArgs, options, Default.FetchErrorParameters, cancellationToken).ConfigureAwait(false); } public async Task OnFetchErrorAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.fetchError", handler, CreateFetchErrorEventArgs, options, JsonContext.FetchErrorParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.fetchError", handler, CreateFetchErrorEventArgs, options, Default.FetchErrorParameters, cancellationToken).ConfigureAwait(false); } public async Task OnAuthRequiredAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.authRequired", handler, CreateAuthRequiredEventArgs, options, JsonContext.AuthRequiredParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.authRequired", handler, CreateAuthRequiredEventArgs, options, Default.AuthRequiredParameters, cancellationToken).ConfigureAwait(false); } public async Task OnAuthRequiredAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("network.authRequired", handler, CreateAuthRequiredEventArgs, options, JsonContext.AuthRequiredParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("network.authRequired", handler, CreateAuthRequiredEventArgs, options, Default.AuthRequiredParameters, cancellationToken).ConfigureAwait(false); } private static BeforeRequestSentEventArgs CreateBeforeRequestSentEventArgs(IBiDi bidi, BeforeRequestSentParameters p) @@ -185,29 +221,29 @@ private static AuthRequiredEventArgs CreateAuthRequiredEventArgs(IBiDi bidi, Aut => new(bidi, p.Context, p.IsBlocked, p.Navigation, p.RedirectCount, p.Request, p.Timestamp, p.UserContext, p.Intercepts, p.Response); } -[JsonSerializable(typeof(AddDataCollectorCommand))] +[JsonSerializable(typeof(AddDataCollectorParameters))] [JsonSerializable(typeof(AddDataCollectorResult))] -[JsonSerializable(typeof(AddInterceptCommand))] +[JsonSerializable(typeof(AddInterceptParameters))] [JsonSerializable(typeof(AddInterceptResult))] -[JsonSerializable(typeof(ContinueRequestCommand))] +[JsonSerializable(typeof(ContinueRequestParameters))] [JsonSerializable(typeof(ContinueRequestResult))] -[JsonSerializable(typeof(ContinueResponseCommand))] +[JsonSerializable(typeof(ContinueResponseParameters))] [JsonSerializable(typeof(ContinueResponseResult))] -[JsonSerializable(typeof(ContinueWithAuthCommand))] +[JsonSerializable(typeof(ContinueWithAuthParameters))] [JsonSerializable(typeof(ContinueWithAuthResult))] -[JsonSerializable(typeof(FailRequestCommand))] +[JsonSerializable(typeof(FailRequestParameters))] [JsonSerializable(typeof(FailRequestResult))] -[JsonSerializable(typeof(GetDataCommand))] +[JsonSerializable(typeof(GetDataParameters))] [JsonSerializable(typeof(GetDataResult))] -[JsonSerializable(typeof(ProvideResponseCommand))] +[JsonSerializable(typeof(ProvideResponseParameters))] [JsonSerializable(typeof(ProvideResponseResult))] -[JsonSerializable(typeof(RemoveDataCollectorCommand))] +[JsonSerializable(typeof(RemoveDataCollectorParameters))] [JsonSerializable(typeof(RemoveDataCollectorResult))] -[JsonSerializable(typeof(RemoveInterceptCommand))] +[JsonSerializable(typeof(RemoveInterceptParameters))] [JsonSerializable(typeof(RemoveInterceptResult))] -[JsonSerializable(typeof(SetCacheBehaviorCommand))] +[JsonSerializable(typeof(SetCacheBehaviorParameters))] [JsonSerializable(typeof(SetCacheBehaviorResult))] -[JsonSerializable(typeof(SetExtraHeadersCommand))] +[JsonSerializable(typeof(SetExtraHeadersParameters))] [JsonSerializable(typeof(SetExtraHeadersResult))] [JsonSerializable(typeof(BeforeRequestSentParameters))] diff --git a/dotnet/src/webdriver/BiDi/Network/ProvideResponseCommand.cs b/dotnet/src/webdriver/BiDi/Network/ProvideResponse.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Network/ProvideResponseCommand.cs rename to dotnet/src/webdriver/BiDi/Network/ProvideResponse.cs index fabf681145a52..7564e5897ad2e 100644 --- a/dotnet/src/webdriver/BiDi/Network/ProvideResponseCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/ProvideResponse.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class ProvideResponseCommand(ProvideResponseParameters @params) - : Command(@params, "network.provideResponse"); - internal sealed record ProvideResponseParameters(Request Request, BytesValue? Body, IEnumerable? Cookies, IEnumerable
? Headers, string? ReasonPhrase, long? StatusCode) : Parameters; public sealed record ProvideResponseOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/RemoveDataCollectorCommand.cs b/dotnet/src/webdriver/BiDi/Network/RemoveDataCollector.cs similarity index 79% rename from dotnet/src/webdriver/BiDi/Network/RemoveDataCollectorCommand.cs rename to dotnet/src/webdriver/BiDi/Network/RemoveDataCollector.cs index 13540ad13af22..4ef49f4f10040 100644 --- a/dotnet/src/webdriver/BiDi/Network/RemoveDataCollectorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/RemoveDataCollector.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class RemoveDataCollectorCommand(RemoveDataCollectorParameters @params) - : Command(@params, "network.removeDataCollector"); - internal sealed record RemoveDataCollectorParameters(Collector Collector) : Parameters; public record RemoveDataCollectorOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Network/RemoveInterceptCommand.cs b/dotnet/src/webdriver/BiDi/Network/RemoveIntercept.cs similarity index 80% rename from dotnet/src/webdriver/BiDi/Network/RemoveInterceptCommand.cs rename to dotnet/src/webdriver/BiDi/Network/RemoveIntercept.cs index e2ce91fac6125..84b180508ad39 100644 --- a/dotnet/src/webdriver/BiDi/Network/RemoveInterceptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/RemoveIntercept.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class RemoveInterceptCommand(RemoveInterceptParameters @params) - : Command(@params, "network.removeIntercept"); - internal sealed record RemoveInterceptParameters(Intercept Intercept) : Parameters; public record RemoveInterceptOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs similarity index 86% rename from dotnet/src/webdriver/BiDi/Network/SetCacheBehaviorCommand.cs rename to dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs index d79c1ff40a088..7307aff1a72cc 100644 --- a/dotnet/src/webdriver/BiDi/Network/SetCacheBehaviorCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/SetCacheBehavior.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class SetCacheBehaviorCommand(SetCacheBehaviorParameters @params) - : Command(@params, "network.setCacheBehavior"); - internal sealed record SetCacheBehaviorParameters(CacheBehavior CacheBehavior, IEnumerable? Contexts) : Parameters; public sealed record SetCacheBehaviorOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs b/dotnet/src/webdriver/BiDi/Network/SetExtraHeaders.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs rename to dotnet/src/webdriver/BiDi/Network/SetExtraHeaders.cs index 70053a10f5b93..c3305301085dc 100644 --- a/dotnet/src/webdriver/BiDi/Network/SetExtraHeadersCommand.cs +++ b/dotnet/src/webdriver/BiDi/Network/SetExtraHeaders.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Network; -internal sealed class SetExtraHeadersCommand(SetExtraHeadersParameters @params) - : Command(@params, "network.setExtraHeaders"); - internal sealed record SetExtraHeadersParameters(IEnumerable
Headers, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; public sealed record SetExtraHeadersOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs b/dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs index a26813e13b30f..61031431f9457 100644 --- a/dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs +++ b/dotnet/src/webdriver/BiDi/Permissions/PermissionsModule.cs @@ -18,22 +18,24 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Permissions.PermissionsJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Permissions; -public sealed class PermissionsModule : Module, IPermissionsModule +internal sealed class PermissionsModule : Module, IPermissionsModule { - private static readonly PermissionsJsonSerializerContext JsonContext = PermissionsJsonSerializerContext.Default; + private static readonly Command SetPermissionCommand = new( + "permissions.setPermission", Default.SetPermissionCommandParameters, Default.SetPermissionResult); public async Task SetPermissionAsync(PermissionDescriptor descriptor, PermissionState state, string origin, SetPermissionOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetPermissionCommandParameters(descriptor, state, origin, options?.EmbeddedOrigin, options?.UserContext); - return await ExecuteCommandAsync(new SetPermissionCommand(@params), options, JsonContext.SetPermissionCommand, JsonContext.SetPermissionResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetPermissionCommand, @params, options, cancellationToken).ConfigureAwait(false); } } -[JsonSerializable(typeof(SetPermissionCommand))] +[JsonSerializable(typeof(SetPermissionCommandParameters))] [JsonSerializable(typeof(SetPermissionResult))] [JsonSourceGenerationOptions( diff --git a/dotnet/src/webdriver/BiDi/Permissions/SetPermissionCommand.cs b/dotnet/src/webdriver/BiDi/Permissions/SetPermission.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Permissions/SetPermissionCommand.cs rename to dotnet/src/webdriver/BiDi/Permissions/SetPermission.cs index 12d327449e639..3c4f5d607c105 100644 --- a/dotnet/src/webdriver/BiDi/Permissions/SetPermissionCommand.cs +++ b/dotnet/src/webdriver/BiDi/Permissions/SetPermission.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Permissions; -internal class SetPermissionCommand(SetPermissionCommandParameters @params) - : Command(@params, "permissions.setPermission"); - internal record SetPermissionCommandParameters(PermissionDescriptor Descriptor, PermissionState State, string Origin, string? EmbeddedOrigin, UserContext? UserContext) : Parameters; public record SetPermissionOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Script/AddPreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs similarity index 88% rename from dotnet/src/webdriver/BiDi/Script/AddPreloadScriptCommand.cs rename to dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs index 40c0f7d830a21..d4601cc730fc3 100644 --- a/dotnet/src/webdriver/BiDi/Script/AddPreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/AddPreloadScript.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Script; -internal sealed class AddPreloadScriptCommand(AddPreloadScriptParameters @params) - : Command(@params, "script.addPreloadScript"); - internal sealed record AddPreloadScriptParameters([StringSyntax(StringSyntaxConstants.JavaScript)] string FunctionDeclaration, IEnumerable? Arguments, IEnumerable? Contexts, IEnumerable? UserContexts, string? Sandbox) : Parameters; public sealed record AddPreloadScriptOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Script/CallFunctionCommand.cs b/dotnet/src/webdriver/BiDi/Script/CallFunction.cs similarity index 86% rename from dotnet/src/webdriver/BiDi/Script/CallFunctionCommand.cs rename to dotnet/src/webdriver/BiDi/Script/CallFunction.cs index 333e5aed00178..2adbc739ecc38 100644 --- a/dotnet/src/webdriver/BiDi/Script/CallFunctionCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/CallFunction.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.Script; -internal sealed class CallFunctionCommand(CallFunctionParameters @params) - : Command(@params, "script.callFunction"); - internal sealed record CallFunctionParameters([StringSyntax(StringSyntaxConstants.JavaScript)] string FunctionDeclaration, bool AwaitPromise, Target Target, IEnumerable? Arguments, ResultOwnership? ResultOwnership, SerializationOptions? SerializationOptions, LocalValue? This, bool? UserActivation) : Parameters; public sealed record CallFunctionOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Script/DisownCommand.cs b/dotnet/src/webdriver/BiDi/Script/Disown.cs similarity index 83% rename from dotnet/src/webdriver/BiDi/Script/DisownCommand.cs rename to dotnet/src/webdriver/BiDi/Script/Disown.cs index 3d3115eaa625a..cefd9d1bb520d 100644 --- a/dotnet/src/webdriver/BiDi/Script/DisownCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/Disown.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Script; -internal sealed class DisownCommand(DisownParameters @params) - : Command(@params, "script.disown"); - internal sealed record DisownParameters(IEnumerable Handles, Target Target) : Parameters; public sealed record DisownOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs b/dotnet/src/webdriver/BiDi/Script/Evaluate.cs similarity index 93% rename from dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs rename to dotnet/src/webdriver/BiDi/Script/Evaluate.cs index 0f7488eae03df..a2ff995e08a7f 100644 --- a/dotnet/src/webdriver/BiDi/Script/EvaluateCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/Evaluate.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -23,9 +23,6 @@ namespace OpenQA.Selenium.BiDi.Script; -internal sealed class EvaluateCommand(EvaluateParameters @params) - : Command(@params, "script.evaluate"); - internal sealed record EvaluateParameters( string Expression, Target Target, diff --git a/dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs b/dotnet/src/webdriver/BiDi/Script/GetRealms.cs similarity index 87% rename from dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs rename to dotnet/src/webdriver/BiDi/Script/GetRealms.cs index 859cb67af6257..8530150c508cc 100644 --- a/dotnet/src/webdriver/BiDi/Script/GetRealmsCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/GetRealms.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Script; -internal sealed class GetRealmsCommand(GetRealmsParameters @params) - : Command(@params, "script.getRealms"); - internal sealed record GetRealmsParameters(BrowsingContext.BrowsingContext? Context, RealmType? Type) : Parameters; public sealed record GetRealmsOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Script/RemovePreloadScriptCommand.cs b/dotnet/src/webdriver/BiDi/Script/RemovePreloadScript.cs similarity index 79% rename from dotnet/src/webdriver/BiDi/Script/RemovePreloadScriptCommand.cs rename to dotnet/src/webdriver/BiDi/Script/RemovePreloadScript.cs index 373dba23d22ac..aeee94d9aa3de 100644 --- a/dotnet/src/webdriver/BiDi/Script/RemovePreloadScriptCommand.cs +++ b/dotnet/src/webdriver/BiDi/Script/RemovePreloadScript.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Script; -internal sealed class RemovePreloadScriptCommand(RemovePreloadScriptParameters @params) - : Command(@params, "script.removePreloadScript"); - internal sealed record RemovePreloadScriptParameters(PreloadScript Script) : Parameters; public sealed record RemovePreloadScriptOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs b/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs index fc41339d25b4c..3f6353dd68c2b 100644 --- a/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs +++ b/dotnet/src/webdriver/BiDi/Script/ScriptModule.cs @@ -19,18 +19,35 @@ using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Script.ScriptJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Script; -public sealed class ScriptModule : Module, IScriptModule +internal sealed class ScriptModule : Module, IScriptModule { - private static readonly ScriptJsonSerializerContext JsonContext = ScriptJsonSerializerContext.Default; + private static readonly Command EvaluateCommand = new( + "script.evaluate", Default.EvaluateParameters, Default.EvaluateResult); + + private static readonly Command CallFunctionCommand = new( + "script.callFunction", Default.CallFunctionParameters, Default.EvaluateResult); + + private static readonly Command DisownCommand = new( + "script.disown", Default.DisownParameters, Default.DisownResult); + + private static readonly Command GetRealmsCommand = new( + "script.getRealms", Default.GetRealmsParameters, Default.GetRealmsResult); + + private static readonly Command AddPreloadScriptCommand = new( + "script.addPreloadScript", Default.AddPreloadScriptParameters, Default.AddPreloadScriptResult); + + private static readonly Command RemovePreloadScriptCommand = new( + "script.removePreloadScript", Default.RemovePreloadScriptParameters, Default.RemovePreloadScriptResult); public async Task EvaluateAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string expression, bool awaitPromise, Target target, EvaluateOptions? options = null, CancellationToken cancellationToken = default) { var @params = new EvaluateParameters(expression, target, awaitPromise, options?.ResultOwnership, options?.SerializationOptions, options?.UserActivation); - return await ExecuteCommandAsync(new EvaluateCommand(@params), options, JsonContext.EvaluateCommand, JsonContext.EvaluateResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(EvaluateCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task EvaluateAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string expression, bool awaitPromise, Target target, EvaluateOptions? options = null, CancellationToken cancellationToken = default) @@ -44,7 +61,7 @@ public async Task CallFunctionAsync([StringSyntax(StringSyntaxCo { var @params = new CallFunctionParameters(functionDeclaration, awaitPromise, target, options?.Arguments, options?.ResultOwnership, options?.SerializationOptions, options?.This, options?.UserActivation); - return await ExecuteCommandAsync(new CallFunctionCommand(@params), options, JsonContext.CallFunctionCommand, JsonContext.EvaluateResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(CallFunctionCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task CallFunctionAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string functionDeclaration, bool awaitPromise, Target target, CallFunctionOptions? options = null, CancellationToken cancellationToken = default) @@ -58,58 +75,58 @@ public async Task DisownAsync(IEnumerable handles, Target { var @params = new DisownParameters(handles, target); - return await ExecuteCommandAsync(new DisownCommand(@params), options, JsonContext.DisownCommand, JsonContext.DisownResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(DisownCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task GetRealmsAsync(GetRealmsOptions? options = null, CancellationToken cancellationToken = default) { var @params = new GetRealmsParameters(options?.Context, options?.Type); - return await ExecuteCommandAsync(new GetRealmsCommand(@params), options, JsonContext.GetRealmsCommand, JsonContext.GetRealmsResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(GetRealmsCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task AddPreloadScriptAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string functionDeclaration, AddPreloadScriptOptions? options = null, CancellationToken cancellationToken = default) { var @params = new AddPreloadScriptParameters(functionDeclaration, options?.Arguments, options?.Contexts, options?.UserContexts, options?.Sandbox); - return await ExecuteCommandAsync(new AddPreloadScriptCommand(@params), options, JsonContext.AddPreloadScriptCommand, JsonContext.AddPreloadScriptResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(AddPreloadScriptCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task RemovePreloadScriptAsync(PreloadScript script, RemovePreloadScriptOptions? options = null, CancellationToken cancellationToken = default) { var @params = new RemovePreloadScriptParameters(script); - return await ExecuteCommandAsync(new RemovePreloadScriptCommand(@params), options, JsonContext.RemovePreloadScriptCommand, JsonContext.RemovePreloadScriptResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(RemovePreloadScriptCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task OnMessageAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("script.message", handler, CreateMessageEventArgs, options, JsonContext.MessageParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("script.message", handler, CreateMessageEventArgs, options, Default.MessageParameters, cancellationToken).ConfigureAwait(false); } public async Task OnMessageAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("script.message", handler, CreateMessageEventArgs, options, JsonContext.MessageParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("script.message", handler, CreateMessageEventArgs, options, Default.MessageParameters, cancellationToken).ConfigureAwait(false); } public async Task OnRealmCreatedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("script.realmCreated", handler, CreateRealmCreatedEventArgs, options, JsonContext.RealmInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("script.realmCreated", handler, CreateRealmCreatedEventArgs, options, Default.RealmInfo, cancellationToken).ConfigureAwait(false); } public async Task OnRealmCreatedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("script.realmCreated", handler, CreateRealmCreatedEventArgs, options, JsonContext.RealmInfo, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("script.realmCreated", handler, CreateRealmCreatedEventArgs, options, Default.RealmInfo, cancellationToken).ConfigureAwait(false); } public async Task OnRealmDestroyedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("script.realmDestroyed", handler, CreateRealmDestroyedEventArgs, options, JsonContext.RealmDestroyedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("script.realmDestroyed", handler, CreateRealmDestroyedEventArgs, options, Default.RealmDestroyedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnRealmDestroyedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("script.realmDestroyed", handler, CreateRealmDestroyedEventArgs, options, JsonContext.RealmDestroyedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("script.realmDestroyed", handler, CreateRealmDestroyedEventArgs, options, Default.RealmDestroyedParameters, cancellationToken).ConfigureAwait(false); } private static MessageEventArgs CreateMessageEventArgs(IBiDi bidi, MessageParameters p) @@ -173,17 +190,17 @@ private static RealmDestroyedEventArgs CreateRealmDestroyedEventArgs(IBiDi bidi, [JsonSerializable(typeof(WorkletRealmInfo))] #endregion -[JsonSerializable(typeof(AddPreloadScriptCommand))] +[JsonSerializable(typeof(AddPreloadScriptParameters))] [JsonSerializable(typeof(AddPreloadScriptResult))] -[JsonSerializable(typeof(DisownCommand))] +[JsonSerializable(typeof(DisownParameters))] [JsonSerializable(typeof(DisownResult))] -[JsonSerializable(typeof(CallFunctionCommand))] +[JsonSerializable(typeof(CallFunctionParameters))] [JsonSerializable(typeof(EvaluateResult))] -[JsonSerializable(typeof(EvaluateCommand))] +[JsonSerializable(typeof(EvaluateParameters))] [JsonSerializable(typeof(EvaluateResult))] -[JsonSerializable(typeof(GetRealmsCommand))] +[JsonSerializable(typeof(GetRealmsParameters))] [JsonSerializable(typeof(GetRealmsResult))] -[JsonSerializable(typeof(RemovePreloadScriptCommand))] +[JsonSerializable(typeof(RemovePreloadScriptParameters))] [JsonSerializable(typeof(RemovePreloadScriptResult))] [JsonSerializable(typeof(MessageParameters))] diff --git a/dotnet/src/webdriver/BiDi/Session/EndCommand.cs b/dotnet/src/webdriver/BiDi/Session/End.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Session/EndCommand.cs rename to dotnet/src/webdriver/BiDi/Session/End.cs index a93434214db2c..374ae3e5aecad 100644 --- a/dotnet/src/webdriver/BiDi/Session/EndCommand.cs +++ b/dotnet/src/webdriver/BiDi/Session/End.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Session; -internal sealed class EndCommand() - : Command(Parameters.Empty, "session.end"); - public sealed record EndOptions : CommandOptions; public sealed record EndResult : EmptyResult; diff --git a/dotnet/src/webdriver/BiDi/Session/NewCommand.cs b/dotnet/src/webdriver/BiDi/Session/New.cs similarity index 88% rename from dotnet/src/webdriver/BiDi/Session/NewCommand.cs rename to dotnet/src/webdriver/BiDi/Session/New.cs index 68e445a475ee0..56f539bd388d3 100644 --- a/dotnet/src/webdriver/BiDi/Session/NewCommand.cs +++ b/dotnet/src/webdriver/BiDi/Session/New.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Session; -internal sealed class NewCommand(NewParameters @params) - : Command(@params, "session.new"); - internal sealed record NewParameters(CapabilitiesRequest Capabilities) : Parameters; public sealed record NewOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Session/SessionModule.cs b/dotnet/src/webdriver/BiDi/Session/SessionModule.cs index 9697ccbe91f07..f9234efae1ff9 100644 --- a/dotnet/src/webdriver/BiDi/Session/SessionModule.cs +++ b/dotnet/src/webdriver/BiDi/Session/SessionModule.cs @@ -18,54 +18,67 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Session.SessionJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Session; internal sealed class SessionModule : Module, ISessionModule { - private static readonly SessionJsonSerializerContext JsonContext = SessionJsonSerializerContext.Default; + private static readonly Command StatusCommand = new( + "session.status", Default.Parameters, Default.StatusResult); + + private static readonly Command NewCommand = new( + "session.new", Default.NewParameters, Default.NewResult); + + private static readonly Command EndCommand = new( + "session.end", Default.Parameters, Default.EndResult); + + private static readonly Command SubscribeCommand = new( + "session.subscribe", Default.SubscribeParameters, Default.SubscribeResult); + + private static readonly Command UnsubscribeByIdCommand = new( + "session.unsubscribe", Default.UnsubscribeByIdParameters, Default.UnsubscribeResult); public async Task StatusAsync(StatusOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new StatusCommand(), options, JsonContext.StatusCommand, JsonContext.StatusResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(StatusCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } public async Task SubscribeAsync(IEnumerable events, SubscribeOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SubscribeParameters(events, options?.Contexts); - return await ExecuteCommandAsync(new(@params), options, JsonContext.SubscribeCommand, JsonContext.SubscribeResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SubscribeCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task UnsubscribeAsync(IEnumerable subscriptions, UnsubscribeByIdOptions? options = null, CancellationToken cancellationToken = default) { var @params = new UnsubscribeByIdParameters(subscriptions); - return await ExecuteCommandAsync(new UnsubscribeByIdCommand(@params), options, JsonContext.UnsubscribeByIdCommand, JsonContext.UnsubscribeResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(UnsubscribeByIdCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task NewAsync(CapabilitiesRequest capabilities, NewOptions? options = null, CancellationToken cancellationToken = default) { var @params = new NewParameters(capabilities); - return await ExecuteCommandAsync(new NewCommand(@params), options, JsonContext.NewCommand, JsonContext.NewResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(NewCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task EndAsync(EndOptions? options = null, CancellationToken cancellationToken = default) { - return await ExecuteCommandAsync(new EndCommand(), options, JsonContext.EndCommand, JsonContext.EndResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(EndCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } } -[JsonSerializable(typeof(StatusCommand))] +[JsonSerializable(typeof(Parameters))] [JsonSerializable(typeof(StatusResult))] -[JsonSerializable(typeof(NewCommand))] +[JsonSerializable(typeof(NewParameters))] [JsonSerializable(typeof(NewResult))] -[JsonSerializable(typeof(EndCommand))] [JsonSerializable(typeof(EndResult))] -[JsonSerializable(typeof(SubscribeCommand))] +[JsonSerializable(typeof(SubscribeParameters))] [JsonSerializable(typeof(SubscribeResult))] -[JsonSerializable(typeof(UnsubscribeByIdCommand))] +[JsonSerializable(typeof(UnsubscribeByIdParameters))] [JsonSerializable(typeof(UnsubscribeResult))] [JsonSourceGenerationOptions( diff --git a/dotnet/src/webdriver/BiDi/Session/StatusCommand.cs b/dotnet/src/webdriver/BiDi/Session/Status.cs similarity index 84% rename from dotnet/src/webdriver/BiDi/Session/StatusCommand.cs rename to dotnet/src/webdriver/BiDi/Session/Status.cs index dfe95878ca124..6f5ef3ca5f7ae 100644 --- a/dotnet/src/webdriver/BiDi/Session/StatusCommand.cs +++ b/dotnet/src/webdriver/BiDi/Session/Status.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Session; -internal sealed class StatusCommand() - : Command(Parameters.Empty, "session.status"); - public sealed record StatusResult(bool Ready, string Message) : EmptyResult; public sealed record StatusOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Session/SubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Session/Subscribe.cs similarity index 85% rename from dotnet/src/webdriver/BiDi/Session/SubscribeCommand.cs rename to dotnet/src/webdriver/BiDi/Session/Subscribe.cs index f22e64227fab5..ac6031262efd3 100644 --- a/dotnet/src/webdriver/BiDi/Session/SubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Session/Subscribe.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Session; -internal sealed class SubscribeCommand(SubscribeParameters @params) - : Command(@params, "session.subscribe"); - internal sealed record SubscribeParameters(IEnumerable Events, IEnumerable? Contexts) : Parameters; public sealed record SubscribeOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Session/UnsubscribeCommand.cs b/dotnet/src/webdriver/BiDi/Session/Unsubscribe.cs similarity index 81% rename from dotnet/src/webdriver/BiDi/Session/UnsubscribeCommand.cs rename to dotnet/src/webdriver/BiDi/Session/Unsubscribe.cs index 821c7e0b49183..cd84ffab46346 100644 --- a/dotnet/src/webdriver/BiDi/Session/UnsubscribeCommand.cs +++ b/dotnet/src/webdriver/BiDi/Session/Unsubscribe.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Session; -internal sealed class UnsubscribeByIdCommand(UnsubscribeByIdParameters @params) - : Command(@params, "session.unsubscribe"); - internal sealed record UnsubscribeByIdParameters(IEnumerable Subscriptions) : Parameters; public sealed record UnsubscribeByIdOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs b/dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs index c1c2a46f46494..6243014142982 100644 --- a/dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs +++ b/dotnet/src/webdriver/BiDi/Speculation/SpeculationModule.cs @@ -18,21 +18,20 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Speculation.SpeculationJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Speculation; -public sealed class SpeculationModule : Module, ISpeculationModule +internal sealed class SpeculationModule : Module, ISpeculationModule { - private static readonly SpeculationJsonSerializerContext JsonContext = SpeculationJsonSerializerContext.Default; - public async Task OnPrefetchStatusUpdatedAsync(Func handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("speculation.prefetchStatusUpdated", handler, CreatePrefetchStatusUpdatedEventArgs, options, JsonContext.PrefetchStatusUpdatedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("speculation.prefetchStatusUpdated", handler, CreatePrefetchStatusUpdatedEventArgs, options, Default.PrefetchStatusUpdatedParameters, cancellationToken).ConfigureAwait(false); } public async Task OnPrefetchStatusUpdatedAsync(Action handler, SubscriptionOptions? options = null, CancellationToken cancellationToken = default) { - return await SubscribeAsync("speculation.prefetchStatusUpdated", handler, CreatePrefetchStatusUpdatedEventArgs, options, JsonContext.PrefetchStatusUpdatedParameters, cancellationToken).ConfigureAwait(false); + return await SubscribeAsync("speculation.prefetchStatusUpdated", handler, CreatePrefetchStatusUpdatedEventArgs, options, Default.PrefetchStatusUpdatedParameters, cancellationToken).ConfigureAwait(false); } private static PrefetchStatusUpdatedEventArgs CreatePrefetchStatusUpdatedEventArgs(IBiDi bidi, PrefetchStatusUpdatedParameters p) diff --git a/dotnet/src/webdriver/BiDi/Storage/DeleteCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs similarity index 86% rename from dotnet/src/webdriver/BiDi/Storage/DeleteCookiesCommand.cs rename to dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs index 9e170974149ee..e30fd6c0771ca 100644 --- a/dotnet/src/webdriver/BiDi/Storage/DeleteCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Storage/DeleteCookies.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.Storage; -internal sealed class DeleteCookiesCommand(DeleteCookiesParameters @params) - : Command(@params, "storage.deleteCookies"); - internal sealed record DeleteCookiesParameters(CookieFilter? Filter, PartitionDescriptor? Partition) : Parameters; public sealed record DeleteCookiesOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs b/dotnet/src/webdriver/BiDi/Storage/GetCookies.cs similarity index 92% rename from dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs rename to dotnet/src/webdriver/BiDi/Storage/GetCookies.cs index 83b3613ddc6bd..1518312ab8e38 100644 --- a/dotnet/src/webdriver/BiDi/Storage/GetCookiesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Storage/GetCookies.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Storage; -internal sealed class GetCookiesCommand(GetCookiesParameters @params) - : Command(@params, "storage.getCookies"); - internal sealed record GetCookiesParameters(CookieFilter? Filter, PartitionDescriptor? Partition) : Parameters; public sealed record GetCookiesOptions : CommandOptions diff --git a/dotnet/src/webdriver/BiDi/Storage/SetCookieCommand.cs b/dotnet/src/webdriver/BiDi/Storage/SetCookie.cs similarity index 89% rename from dotnet/src/webdriver/BiDi/Storage/SetCookieCommand.cs rename to dotnet/src/webdriver/BiDi/Storage/SetCookie.cs index b02932e5da575..2e26166ac8c51 100644 --- a/dotnet/src/webdriver/BiDi/Storage/SetCookieCommand.cs +++ b/dotnet/src/webdriver/BiDi/Storage/SetCookie.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -22,9 +22,6 @@ namespace OpenQA.Selenium.BiDi.Storage; -internal sealed class SetCookieCommand(SetCookieParameters @params) - : Command(@params, "storage.setCookie"); - internal sealed record SetCookieParameters(PartialCookie Cookie, PartitionDescriptor? Partition) : Parameters; public sealed record PartialCookie(string Name, Network.BytesValue Value, string Domain) diff --git a/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs b/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs index 5cd921b3f0165..a9339e890842d 100644 --- a/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs +++ b/dotnet/src/webdriver/BiDi/Storage/StorageModule.cs @@ -18,40 +18,48 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.Storage.StorageJsonSerializerContext; namespace OpenQA.Selenium.BiDi.Storage; -public sealed class StorageModule : Module, IStorageModule +internal sealed class StorageModule : Module, IStorageModule { - private static readonly StorageJsonSerializerContext JsonContext = StorageJsonSerializerContext.Default; + private static readonly Command GetCookiesCommand = new( + "storage.getCookies", Default.GetCookiesParameters, Default.GetCookiesResult); + + private static readonly Command DeleteCookiesCommand = new( + "storage.deleteCookies", Default.DeleteCookiesParameters, Default.DeleteCookiesResult); + + private static readonly Command SetCookieCommand = new( + "storage.setCookie", Default.SetCookieParameters, Default.SetCookieResult); public async Task GetCookiesAsync(GetCookiesOptions? options = null, CancellationToken cancellationToken = default) { var @params = new GetCookiesParameters(options?.Filter, options?.Partition); - return await ExecuteCommandAsync(new GetCookiesCommand(@params), options, JsonContext.GetCookiesCommand, JsonContext.GetCookiesResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(GetCookiesCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task DeleteCookiesAsync(DeleteCookiesOptions? options = null, CancellationToken cancellationToken = default) { var @params = new DeleteCookiesParameters(options?.Filter, options?.Partition); - return await ExecuteCommandAsync(new DeleteCookiesCommand(@params), options, JsonContext.DeleteCookiesCommand, JsonContext.DeleteCookiesResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(DeleteCookiesCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task SetCookieAsync(PartialCookie cookie, SetCookieOptions? options = null, CancellationToken cancellationToken = default) { var @params = new SetCookieParameters(cookie, options?.Partition); - return await ExecuteCommandAsync(new SetCookieCommand(@params), options, JsonContext.SetCookieCommand, JsonContext.SetCookieResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(SetCookieCommand, @params, options, cancellationToken).ConfigureAwait(false); } } -[JsonSerializable(typeof(GetCookiesCommand))] +[JsonSerializable(typeof(GetCookiesParameters))] [JsonSerializable(typeof(GetCookiesResult))] -[JsonSerializable(typeof(SetCookieCommand))] +[JsonSerializable(typeof(SetCookieParameters))] [JsonSerializable(typeof(SetCookieResult))] -[JsonSerializable(typeof(DeleteCookiesCommand))] +[JsonSerializable(typeof(DeleteCookiesParameters))] [JsonSerializable(typeof(DeleteCookiesResult))] [JsonSourceGenerationOptions( diff --git a/dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs b/dotnet/src/webdriver/BiDi/WebExtension/Install.cs similarity index 88% rename from dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs rename to dotnet/src/webdriver/BiDi/WebExtension/Install.cs index 983293ceaccd9..337af96b9e1e8 100644 --- a/dotnet/src/webdriver/BiDi/WebExtension/InstallCommand.cs +++ b/dotnet/src/webdriver/BiDi/WebExtension/Install.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -21,9 +21,6 @@ namespace OpenQA.Selenium.BiDi.WebExtension; -internal sealed class InstallCommand(InstallParameters @params) - : Command(@params, "webExtension.install"); - internal sealed record InstallParameters(ExtensionData ExtensionData) : Parameters; [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] diff --git a/dotnet/src/webdriver/BiDi/WebExtension/UninstallCommand.cs b/dotnet/src/webdriver/BiDi/WebExtension/Uninstall.cs similarity index 82% rename from dotnet/src/webdriver/BiDi/WebExtension/UninstallCommand.cs rename to dotnet/src/webdriver/BiDi/WebExtension/Uninstall.cs index 1b117a8fa39bc..e07b6fd221063 100644 --- a/dotnet/src/webdriver/BiDi/WebExtension/UninstallCommand.cs +++ b/dotnet/src/webdriver/BiDi/WebExtension/Uninstall.cs @@ -1,4 +1,4 @@ -// +// // Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information @@ -19,9 +19,6 @@ namespace OpenQA.Selenium.BiDi.WebExtension; -internal sealed class UninstallCommand(UninstallParameters @params) - : Command(@params, "webExtension.uninstall"); - internal sealed record UninstallParameters(Extension Extension) : Parameters; public sealed record UninstallOptions : CommandOptions; diff --git a/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs b/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs index e048dd7154317..baf108a201b99 100644 --- a/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs +++ b/dotnet/src/webdriver/BiDi/WebExtension/WebExtensionModule.cs @@ -18,31 +18,36 @@ // using System.Text.Json.Serialization; +using static OpenQA.Selenium.BiDi.WebExtension.WebExtensionJsonSerializerContext; namespace OpenQA.Selenium.BiDi.WebExtension; -public sealed class WebExtensionModule : Module, IWebExtensionModule +internal sealed class WebExtensionModule : Module, IWebExtensionModule { - private static readonly WebExtensionJsonSerializerContext JsonContext = WebExtensionJsonSerializerContext.Default; + private static readonly Command InstallCommand = new( + "webExtension.install", Default.InstallParameters, Default.InstallResult); + + private static readonly Command UninstallCommand = new( + "webExtension.uninstall", Default.UninstallParameters, Default.UninstallResult); public async Task InstallAsync(ExtensionData extensionData, InstallOptions? options = null, CancellationToken cancellationToken = default) { var @params = new InstallParameters(extensionData); - return await ExecuteCommandAsync(new InstallCommand(@params), options, JsonContext.InstallCommand, JsonContext.InstallResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(InstallCommand, @params, options, cancellationToken).ConfigureAwait(false); } public async Task UninstallAsync(Extension extension, UninstallOptions? options = null, CancellationToken cancellationToken = default) { var @params = new UninstallParameters(extension); - return await ExecuteCommandAsync(new UninstallCommand(@params), options, JsonContext.UninstallCommand, JsonContext.UninstallResult, cancellationToken).ConfigureAwait(false); + return await ExecuteAsync(UninstallCommand, @params, options, cancellationToken).ConfigureAwait(false); } } -[JsonSerializable(typeof(InstallCommand))] +[JsonSerializable(typeof(InstallParameters))] [JsonSerializable(typeof(InstallResult))] -[JsonSerializable(typeof(UninstallCommand))] +[JsonSerializable(typeof(UninstallParameters))] [JsonSerializable(typeof(UninstallResult))] [JsonSourceGenerationOptions( diff --git a/dotnet/test/webdriver/BiDi/Session/SessionTests.cs b/dotnet/test/webdriver/BiDi/Session/SessionTests.cs index bd3d9f023788a..8a3aa7f62ede2 100644 --- a/dotnet/test/webdriver/BiDi/Session/SessionTests.cs +++ b/dotnet/test/webdriver/BiDi/Session/SessionTests.cs @@ -79,22 +79,22 @@ class CustomModule : Module { private static readonly CustomModuleJsonSerializerContext JsonContext = CustomModuleJsonSerializerContext.Default; + private static readonly Command DoSomethingCommand = + new("session.status", JsonContext.Parameters, JsonContext.DoSomethingResult); + public async Task DoSomethingAsync(DoSomethingOptions options = null) { - return await ExecuteCommandAsync(new DoSomethingCommand(), options, JsonContext.DoSomethingCommand, JsonContext.DoSomethingResult, CancellationToken.None); + return await ExecuteAsync(DoSomethingCommand, Parameters.Empty, options, CancellationToken.None); } } [JsonSourceGenerationOptions( PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] -[JsonSerializable(typeof(DoSomethingCommand))] +[JsonSerializable(typeof(Parameters))] [JsonSerializable(typeof(DoSomethingResult))] partial class CustomModuleJsonSerializerContext : JsonSerializerContext; -class DoSomethingCommand() - : Command(Parameters.Empty, "session.status"); - record DoSomethingResult : EmptyResult; record DoSomethingOptions : CommandOptions;