Skip to content

Commit 7d7ceae

Browse files
authored
[dotnet] [bidi] Fully immutable commands and events (#17077)
1 parent 5bf0c7d commit 7d7ceae

85 files changed

Lines changed: 373 additions & 377 deletions

File tree

Some content is hidden

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

dotnet/src/webdriver/BiDi/Browser/CloseCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ namespace OpenQA.Selenium.BiDi.Browser;
2222
internal sealed class CloseCommand()
2323
: Command<Parameters, CloseResult>(Parameters.Empty, "browser.close");
2424

25-
public sealed class CloseOptions : CommandOptions;
25+
public sealed record CloseOptions : CommandOptions;
2626

2727
public sealed record CloseResult : EmptyResult;

dotnet/src/webdriver/BiDi/Browser/CreateUserContextCommand.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ internal sealed class CreateUserContextCommand(CreateUserContextParameters @para
2424

2525
internal sealed record CreateUserContextParameters(bool? AcceptInsecureCerts, Session.ProxyConfiguration? Proxy, Session.UserPromptHandler? UnhandledPromptBehavior) : Parameters;
2626

27-
public sealed class CreateUserContextOptions : CommandOptions
27+
public sealed record CreateUserContextOptions : CommandOptions
2828
{
29-
public bool? AcceptInsecureCerts { get; set; }
29+
public bool? AcceptInsecureCerts { get; init; }
3030

31-
public Session.ProxyConfiguration? Proxy { get; set; }
31+
public Session.ProxyConfiguration? Proxy { get; init; }
3232

33-
public Session.UserPromptHandler? UnhandledPromptBehavior { get; set; }
33+
public Session.UserPromptHandler? UnhandledPromptBehavior { get; init; }
3434
}
3535

3636
public sealed record CreateUserContextResult(UserContext UserContext) : UserContextInfo(UserContext);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ namespace OpenQA.Selenium.BiDi.Browser;
2424
internal sealed class GetClientWindowsCommand()
2525
: Command<Parameters, GetClientWindowsResult>(Parameters.Empty, "browser.getClientWindows");
2626

27-
public sealed class GetClientWindowsOptions : CommandOptions;
27+
public sealed record GetClientWindowsOptions : CommandOptions;
2828

2929
public sealed record GetClientWindowsResult(IReadOnlyList<ClientWindowInfo> ClientWindows) : EmptyResult;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ namespace OpenQA.Selenium.BiDi.Browser;
2424
internal sealed class GetUserContextsCommand()
2525
: Command<Parameters, GetUserContextsResult>(Parameters.Empty, "browser.getUserContexts");
2626

27-
public class GetUserContextsOptions : CommandOptions;
27+
public record GetUserContextsOptions : CommandOptions;
2828

2929
public sealed record GetUserContextsResult(IReadOnlyList<UserContextInfo> UserContexts) : EmptyResult;

dotnet/src/webdriver/BiDi/Browser/RemoveUserContextCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ internal sealed class RemoveUserContextCommand(RemoveUserContextParameters @para
2424

2525
internal sealed record RemoveUserContextParameters(UserContext UserContext) : Parameters;
2626

27-
public sealed class RemoveUserContextOptions : CommandOptions;
27+
public sealed record RemoveUserContextOptions : CommandOptions;
2828

2929
public sealed record RemoveUserContextResult : EmptyResult;

dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ internal sealed record DownloadBehaviorAllowed(string DestinationFolder) : Downl
3636

3737
internal sealed record DownloadBehaviorDenied : DownloadBehavior;
3838

39-
public sealed class SetDownloadBehaviorOptions : CommandOptions
39+
public sealed record SetDownloadBehaviorOptions : CommandOptions
4040
{
41-
public IEnumerable<UserContext>? UserContexts { get; set; }
41+
public IEnumerable<UserContext>? UserContexts { get; init; }
4242
}
4343

4444
public sealed record SetDownloadBehaviorResult : EmptyResult;

dotnet/src/webdriver/BiDi/BrowsingContext/ActivateCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ internal sealed class ActivateCommand(ActivateParameters @params)
2424

2525
internal sealed record ActivateParameters(BrowsingContext Context) : Parameters;
2626

27-
public sealed class ActivateOptions : CommandOptions;
27+
public sealed record ActivateOptions : CommandOptions;
2828

2929
public sealed record ActivateResult : EmptyResult;

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextNetworkModule.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ private void HandleAuthRequired(AuthRequiredEventArgs e, Action<AuthRequiredEven
272272
}
273273
}
274274

275-
public sealed class InterceptRequestOptions : ContextAddInterceptOptions;
275+
public sealed record InterceptRequestOptions : ContextAddInterceptOptions;
276276

277-
public sealed class InterceptResponseOptions : ContextAddInterceptOptions;
277+
public sealed record InterceptResponseOptions : ContextAddInterceptOptions;
278278

279-
public sealed class InterceptAuthOptions : ContextAddInterceptOptions;
279+
public sealed record InterceptAuthOptions : ContextAddInterceptOptions;

dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContextScriptModule.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ public Task<GetRealmsResult> GetRealmsAsync(ContextGetRealmsOptions? options = n
3838

3939
public Task<EvaluateResult> EvaluateAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string expression, bool awaitPromise, EvaluateOptions? options = null, ContextTargetOptions? targetOptions = null, CancellationToken cancellationToken = default)
4040
{
41-
var contextTarget = new ContextTarget(context);
42-
43-
if (targetOptions is not null)
41+
var contextTarget = new ContextTarget(context)
4442
{
45-
contextTarget.Sandbox = targetOptions.Sandbox;
46-
}
43+
Sandbox = targetOptions?.Sandbox
44+
};
4745

4846
return scriptModule.EvaluateAsync(expression, awaitPromise, contextTarget, options, cancellationToken);
4947
}
@@ -57,12 +55,10 @@ public Task<EvaluateResult> EvaluateAsync([StringSyntax(StringSyntaxConstants.Ja
5755

5856
public Task<EvaluateResult> CallFunctionAsync([StringSyntax(StringSyntaxConstants.JavaScript)] string functionDeclaration, bool awaitPromise, CallFunctionOptions? options = null, ContextTargetOptions? targetOptions = null, CancellationToken cancellationToken = default)
5957
{
60-
var contextTarget = new ContextTarget(context);
61-
62-
if (targetOptions is not null)
58+
var contextTarget = new ContextTarget(context)
6359
{
64-
contextTarget.Sandbox = targetOptions.Sandbox;
65-
}
60+
Sandbox = targetOptions?.Sandbox
61+
};
6662

6763
return scriptModule.CallFunctionAsync(functionDeclaration, awaitPromise, contextTarget, options, cancellationToken);
6864
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ internal sealed class CaptureScreenshotCommand(CaptureScreenshotParameters @para
2828

2929
internal sealed record CaptureScreenshotParameters(BrowsingContext Context, ScreenshotOrigin? Origin, ImageFormat? Format, ClipRectangle? Clip) : Parameters;
3030

31-
public sealed class CaptureScreenshotOptions : CommandOptions
31+
public sealed record CaptureScreenshotOptions : CommandOptions
3232
{
33-
public ScreenshotOrigin? Origin { get; set; }
33+
public ScreenshotOrigin? Origin { get; init; }
3434

35-
public ImageFormat? Format { get; set; }
35+
public ImageFormat? Format { get; init; }
3636

37-
public ClipRectangle? Clip { get; set; }
37+
public ClipRectangle? Clip { get; init; }
3838
}
3939

4040
[JsonConverter(typeof(CamelCaseEnumConverter<ScreenshotOrigin>))]
@@ -46,7 +46,7 @@ public enum ScreenshotOrigin
4646

4747
public record struct ImageFormat(string Type)
4848
{
49-
public double? Quality { get; set; }
49+
public double? Quality { get; init; }
5050
}
5151

5252
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]

0 commit comments

Comments
 (0)