Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/src/webdriver/BiDi/Communication/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace OpenQA.Selenium.BiDi.Communication;
[JsonDerivedType(typeof(Modules.Network.ProvideResponseCommand), "network.provideResponse")]
[JsonDerivedType(typeof(Modules.Network.ContinueWithAuthCommand), "network.continueWithAuth")]
[JsonDerivedType(typeof(Modules.Network.RemoveInterceptCommand), "network.removeIntercept")]
[JsonDerivedType(typeof(Modules.Network.SetCacheBehaviorCommand), "network.setCacheBehavior")]

[JsonDerivedType(typeof(Modules.Script.AddPreloadScriptCommand), "script.addPreloadScript")]
[JsonDerivedType(typeof(Modules.Script.RemovePreloadScriptCommand), "script.removePreloadScript")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task
return intercept;
}

public Task SetCacheBehaviorAsync(CacheBehavior behavior, BrowsingContextSetCacheBehaviorOptions? options = null)
{
SetCacheBehaviorOptions setCacheBehaviorOptions = new()
{
Contexts = [context]
};

return networkModule.SetCacheBehaviorAsync(behavior, setCacheBehaviorOptions);
}

public Task<Subscription> OnBeforeRequestSentAsync(Func<BeforeRequestSentEventArgs, Task> handler, SubscriptionOptions? options = null)
{
return networkModule.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] });
Expand Down
12 changes: 12 additions & 0 deletions dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public async Task<Intercept> InterceptResponseAsync(Func<ResponseStartedEventArg
return intercept;
}

public async Task SetCacheBehaviorAsync(CacheBehavior behavior, SetCacheBehaviorOptions? options = null)
{
var @params = new SetCacheBehaviorCommandParameters(behavior);

if (options is not null)
{
@params.Contexts = options.Contexts;
}

await Broker.ExecuteCommandAsync(new SetCacheBehaviorCommand(@params), options).ConfigureAwait(false);
}

public async Task<Intercept> InterceptAuthAsync(Func<AuthRequiredEventArgs, Task> handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null)
{
var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// <copyright file="SetCacheBehaviorCommand.cs" company="Selenium Committers">
// 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.
// </copyright>

using System.Collections.Generic;
using OpenQA.Selenium.BiDi.Communication;

#nullable enable

namespace OpenQA.Selenium.BiDi.Modules.Network;

internal class SetCacheBehaviorCommand(SetCacheBehaviorCommandParameters @params) : Command<SetCacheBehaviorCommandParameters>(@params);

internal record SetCacheBehaviorCommandParameters(CacheBehavior CacheBehavior) : CommandParameters
{
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
}

public record SetCacheBehaviorOptions : CommandOptions
{
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
}

public record BrowsingContextSetCacheBehaviorOptions
{

}

public enum CacheBehavior
{
Default,
Bypass
}
7 changes: 7 additions & 0 deletions dotnet/test/common/BiDi/Network/NetworkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,11 @@ public async Task CanFailRequest()

Assert.That(action, Throws.TypeOf<BiDiException>().With.Message.Contain("net::ERR_FAILED").Or.Message.Contain("NS_ERROR_ABORT"));
}

[Test]
public void CanSetCacheBehavior()
{
Assert.That(async () => await bidi.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
Assert.That(async () => await context.Network.SetCacheBehaviorAsync(CacheBehavior.Default), Throws.Nothing);
}
}
Loading