Skip to content

Commit 4a9fa75

Browse files
committed
Tighten flow for JSON configuration
1 parent 283376e commit 4a9fa75

File tree

11 files changed

+141
-145
lines changed

11 files changed

+141
-145
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,60 +27,59 @@ namespace OpenQA.Selenium.BiDi.Browser;
2727

2828
public sealed class BrowserModule : Module
2929
{
30-
private BrowserModuleJsonSerializerContext _context = null!;
3130
public async Task<EmptyResult> CloseAsync(CloseOptions? options = null)
3231
{
33-
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, _context).ConfigureAwait(false);
32+
return await Broker.ExecuteCommandAsync<CloseCommand, EmptyResult>(new CloseCommand(), options, JsonContext).ConfigureAwait(false);
3433
}
3534

3635
public async Task<UserContextInfo> CreateUserContextAsync(CreateUserContextOptions? options = null)
3736
{
3837
var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior);
3938

40-
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, _context).ConfigureAwait(false);
39+
return await Broker.ExecuteCommandAsync<CreateUserContextCommand, UserContextInfo>(new CreateUserContextCommand(@params), options, JsonContext).ConfigureAwait(false);
4140
}
4241

4342
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
4443
{
45-
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, _context).ConfigureAwait(false);
44+
return await Broker.ExecuteCommandAsync<GetUserContextsCommand, GetUserContextsResult>(new GetUserContextsCommand(), options, JsonContext).ConfigureAwait(false);
4645
}
4746

4847
public async Task<EmptyResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null)
4948
{
5049
var @params = new RemoveUserContextParameters(userContext);
5150

52-
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, _context).ConfigureAwait(false);
51+
return await Broker.ExecuteCommandAsync<RemoveUserContextCommand, EmptyResult>(new RemoveUserContextCommand(@params), options, JsonContext).ConfigureAwait(false);
5352
}
5453

5554
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
5655
{
57-
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, _context).ConfigureAwait(false);
56+
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options, JsonContext).ConfigureAwait(false);
5857
}
5958

6059
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
6160
{
6261
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
6362

64-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
63+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
6564
}
6665

6766
public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
6867
{
6968
var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);
7069

71-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
70+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
7271
}
7372

7473
public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
7574
{
7675
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);
7776

78-
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, _context).ConfigureAwait(false);
77+
return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options, JsonContext).ConfigureAwait(false);
7978
}
8079

81-
protected internal override void Initialize(JsonSerializerOptions options)
80+
protected internal override JsonSerializerContext ConfigureJson(JsonSerializerOptions options)
8281
{
83-
_context = new BrowserModuleJsonSerializerContext(options);
82+
return new BrowserModuleJsonSerializerContext(options);
8483
}
8584
}
8685

0 commit comments

Comments
 (0)