Skip to content

Commit 89b629b

Browse files
authored
Merge branch 'trunk' into final-python-pagesize-support
2 parents 30dc92d + 43c6e35 commit 89b629b

File tree

10 files changed

+113
-44
lines changed

10 files changed

+113
-44
lines changed

dotnet/src/webdriver/BiDi/Communication/Command.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ namespace OpenQA.Selenium.BiDi.Communication;
5656
[JsonDerivedType(typeof(Modules.Network.ProvideResponseCommand), "network.provideResponse")]
5757
[JsonDerivedType(typeof(Modules.Network.ContinueWithAuthCommand), "network.continueWithAuth")]
5858
[JsonDerivedType(typeof(Modules.Network.RemoveInterceptCommand), "network.removeIntercept")]
59+
[JsonDerivedType(typeof(Modules.Network.SetCacheBehaviorCommand), "network.setCacheBehavior")]
5960

6061
[JsonDerivedType(typeof(Modules.Script.AddPreloadScriptCommand), "script.addPreloadScript")]
6162
[JsonDerivedType(typeof(Modules.Script.RemovePreloadScriptCommand), "script.removePreloadScript")]

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task
6969
return intercept;
7070
}
7171

72+
public Task SetCacheBehaviorAsync(CacheBehavior behavior, BrowsingContextSetCacheBehaviorOptions? options = null)
73+
{
74+
SetCacheBehaviorOptions setCacheBehaviorOptions = new(options)
75+
{
76+
Contexts = [context]
77+
};
78+
79+
return networkModule.SetCacheBehaviorAsync(behavior, setCacheBehaviorOptions);
80+
}
81+
7282
public Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, SubscriptionOptions? options = null)
7383
{
7484
return networkModule.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] });

dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArg
6868
return intercept;
6969
}
7070

71+
public async Task SetCacheBehaviorAsync(CacheBehavior behavior, SetCacheBehaviorOptions? options = null)
72+
{
73+
var @params = new SetCacheBehaviorCommandParameters(behavior);
74+
75+
if (options is not null)
76+
{
77+
@params.Contexts = options.Contexts;
78+
}
79+
80+
await Broker.ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false);
81+
}
82+
7183
public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task> handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
7284
{
7385
var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// <copyright file="SetCacheBehaviorCommand.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System.Collections.Generic;
21+
using OpenQA.Selenium.BiDi.Communication;
22+
23+
#nullable enable
24+
25+
namespace OpenQA.Selenium.BiDi.Modules.Network;
26+
27+
internal class SetCacheBehaviorCommand(SetCacheBehaviorCommandParameters @params) : Command<SetCacheBehaviorCommandParameters>(@params);
28+
29+
internal record SetCacheBehaviorCommandParameters(CacheBehavior CacheBehavior) : CommandParameters
30+
{
31+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
32+
}
33+
34+
public record SetCacheBehaviorOptions : CommandOptions
35+
{
36+
public SetCacheBehaviorOptions()
37+
{
38+
39+
}
40+
41+
internal SetCacheBehaviorOptions(BrowsingContextSetCacheBehaviorOptions? options)
42+
{
43+
44+
}
45+
46+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
47+
}
48+
49+
public record BrowsingContextSetCacheBehaviorOptions
50+
{
51+
52+
}
53+
54+
public enum CacheBehavior
55+
{
56+
Default,
57+
Bypass
58+
}

dotnet/test/common/BiDi/Network/NetworkTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,11 @@ public async Task CanFailRequest()
211211

212212
Assert.That(action, Throws.TypeOf<BiDiException>().With.Message.Contain("net::ERR_FAILED").Or.Message.Contain("NS_ERROR_ABORT"));
213213
}
214+
215+
[Test]
216+
public void CanSetCacheBehavior()
217+
{
218+
Assert.That(async () => await bidi.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
219+
Assert.That(async () => await context.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
220+
}
214221
}

third_party/dotnet/devtools/src/generator/Templates/command.hbs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ namespace {{rootNamespace}}.{{domain.Name}}
1414
/// Gets the name of the command.
1515
/// </summary>
1616
[JsonIgnore]
17-
public string CommandName
18-
{
19-
get { return DevToolsRemoteInterface_CommandName; }
20-
}
17+
public string CommandName => DevToolsRemoteInterface_CommandName;
2118

2219
{{#each command.Parameters}}
2320
{{#if Description}}
@@ -31,11 +28,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
3128
{{/if}}
3229
[JsonPropertyName("{{Name}}")]
3330
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
34-
public {{typemap ../context}} {{dehumanize Name}}
35-
{
36-
get;
37-
set;
38-
}
31+
public {{typemap ../context}} {{dehumanize Name}} { get; set; }
32+
3933
{{/each}}
4034
}
4135

@@ -56,11 +50,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
5650
{{/if}}
5751
[JsonPropertyName("{{Name}}")]
5852
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
59-
public {{typemap ../context}} {{dehumanize Name}}
60-
{
61-
get;
62-
set;
63-
}
53+
public {{typemap ../context}} {{dehumanize Name}} { get; set; }
54+
6455
{{/each}}
6556
}
6657
}

third_party/dotnet/devtools/src/generator/Templates/domain.hbs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ namespace {{rootNamespace}}.{{domain.Name}}
1212
/// </summary>
1313
public class {{dehumanize domain.Name}}Adapter
1414
{
15-
private readonly IDevToolsSession m_session;
1615
private readonly string m_domainName = "{{dehumanize domain.Name}}";
1716
private Dictionary<string, DevToolsEventData> m_eventMap = new Dictionary<string, DevToolsEventData>();
1817

1918
/// <summary>
2019
/// Initializes a new instance of the {{dehumanize domain.Name}}Adapter class.
2120
/// </summary>
2221
/// <param name="session">The IDevToolsSession to be used with this adapter.</param>
22+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
2323
public {{dehumanize domain.Name}}Adapter(IDevToolsSession session)
2424
{
25-
m_session = session ?? throw new ArgumentNullException(nameof(session));
26-
m_session.DevToolsEventReceived += OnDevToolsEventReceived;
25+
Session = session ?? throw new ArgumentNullException(nameof(session));
26+
Session.DevToolsEventReceived += OnDevToolsEventReceived;
2727
{{#each domain.Events}}
2828
m_eventMap["{{Name}}"] = new DevToolsEventData(typeof({{dehumanize Name}}EventArgs), On{{dehumanize Name}});
2929
{{/each}}
@@ -32,16 +32,14 @@ namespace {{rootNamespace}}.{{domain.Name}}
3232
/// <summary>
3333
/// Gets the DevToolsSession associated with the adapter.
3434
/// </summary>
35-
public IDevToolsSession Session
36-
{
37-
get { return m_session; }
38-
}
35+
public IDevToolsSession Session { get; }
3936

4037
{{#each domain.Events}}
4138
/// <summary>
4239
/// {{xml-code-comment Description 2}}
4340
/// </summary>
4441
public event EventHandler<{{dehumanize Name}}EventArgs> {{dehumanize Name}};
42+
4543
{{/each}}
4644

4745
{{#each domain.Commands}}
@@ -50,8 +48,9 @@ namespace {{rootNamespace}}.{{domain.Name}}
5048
/// </summary>
5149
public Task<{{dehumanize Name}}CommandResponse> {{dehumanize Name}}({{dehumanize Name}}CommandSettings command{{#if NoParameters}} = null{{/if}}, CancellationToken cancellationToken = default(CancellationToken), int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
5250
{
53-
return m_session.SendCommand<{{dehumanize Name}}CommandSettings, {{dehumanize Name}}CommandResponse>(command{{#if NoParameters}} ?? new {{dehumanize Name}}CommandSettings(){{/if}}, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
51+
return Session.SendCommand<{{dehumanize Name}}CommandSettings, {{dehumanize Name}}CommandResponse>(command{{#if NoParameters}} ?? new {{dehumanize Name}}CommandSettings(){{/if}}, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
5452
}
53+
5554
{{/each}}
5655

5756
private void OnDevToolsEventReceived(object sender, DevToolsEventReceivedEventArgs e)
@@ -70,12 +69,12 @@ namespace {{rootNamespace}}.{{domain.Name}}
7069
{{#each domain.Events}}
7170
private void On{{dehumanize Name}}(object rawEventArgs)
7271
{
73-
{{dehumanize Name}}EventArgs e = rawEventArgs as {{dehumanize Name}}EventArgs;
74-
if (e != null && {{dehumanize Name}} != null)
72+
if (rawEventArgs is {{dehumanize Name}}EventArgs e)
7573
{
76-
{{dehumanize Name}}(this, e);
74+
{{dehumanize Name}}?.Invoke(this, e);
7775
}
7876
}
77+
7978
{{/each}}
8079
}
8180
}

third_party/dotnet/devtools/src/generator/Templates/event.hbs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
2121
{{/if}}
2222
[JsonPropertyName("{{Name}}")]
2323
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
24-
public {{typemap ../context}} {{dehumanize Name}}
25-
{
26-
get;
27-
set;
28-
}
24+
public {{typemap ../context}} {{dehumanize Name}} { get; set; }
25+
2926
{{/each}}
3027
}
3128
}

third_party/dotnet/devtools/src/generator/Templates/type-hash.hbs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <auto-generated />
1+
// <auto-generated />
22
namespace {{rootNamespace}}.{{domain.Name}}
33
{
44
using System.Collections.Generic;
@@ -14,11 +14,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
1414
///</summary>
1515
[JsonPropertyName("{{Name}}")]
1616
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
17-
public {{typemap ../context}} {{dehumanize Name}}
18-
{
19-
get;
20-
set;
21-
}
17+
public {{typemap ../context}} {{dehumanize Name}} { get; set; }
18+
2219
{{/each}}
2320
}
24-
}
21+
}

third_party/dotnet/devtools/src/generator/Templates/type-object.hbs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <auto-generated />
1+
// <auto-generated />
22
namespace {{rootNamespace}}.{{domain.Name}}
33
{
44
using System.Text.Json.Serialization;
@@ -14,11 +14,8 @@ namespace {{rootNamespace}}.{{domain.Name}}
1414
///</summary>
1515
[JsonPropertyName("{{Name}}")]
1616
{{#if Optional}}[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]{{/if}}
17-
public {{typemap ../context}} {{dehumanize Name}}
18-
{
19-
get;
20-
set;
21-
}
17+
public {{typemap ../context}} {{dehumanize Name}} { get; set; }
18+
2219
{{/each}}
2320
}
24-
}
21+
}

0 commit comments

Comments
 (0)