Skip to content

Commit 43c6e35

Browse files
authored
[dotnet] [bidi] Add network SetCacheBehavior command (#15133)
1 parent 99df4ba commit 43c6e35

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

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

+1
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

+10
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

+12
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);
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

+7
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
}

0 commit comments

Comments
 (0)