From 9e6f7139b33e280e7a783230cf2908a07a51fb6f Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 22 Jan 2025 21:15:49 +0300 Subject: [PATCH 1/2] Add SetCacheBehavior command --- .../webdriver/BiDi/Communication/Command.cs | 1 + .../BrowsingContextNetworkModule.cs | 10 ++++ .../BiDi/Modules/Network/NetworkModule.cs | 12 +++++ .../Network/SetCacheBehaviorCommand.cs | 48 +++++++++++++++++++ .../test/common/BiDi/Network/NetworkTest.cs | 7 +++ 5 files changed, 78 insertions(+) create mode 100644 dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs diff --git a/dotnet/src/webdriver/BiDi/Communication/Command.cs b/dotnet/src/webdriver/BiDi/Communication/Command.cs index 9c3fb09d3d58f..782992d513fe8 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Command.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Command.cs @@ -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")] diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs index da6bb2838ce3a..3d6b130d290b1 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs @@ -69,6 +69,16 @@ public async Task InterceptAuthAsync(Func OnBeforeRequestSentAsync(Func handler, SubscriptionOptions? options = null) { return networkModule.OnBeforeRequestSentAsync(handler, new BrowsingContextsSubscriptionOptions(options) { Contexts = [context] }); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs index c90dfa20a4df9..257da7c27daf8 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Network/NetworkModule.cs @@ -68,6 +68,18 @@ public async Task InterceptResponseAsync(Func InterceptAuthAsync(Func handler, AddInterceptOptions? interceptOptions = null, SubscriptionOptions? options = null) { var intercept = await AddInterceptAsync([InterceptPhase.AuthRequired], interceptOptions).ConfigureAwait(false); diff --git a/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs new file mode 100644 index 0000000000000..61916c5d4f0e8 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Modules/Network/SetCacheBehaviorCommand.cs @@ -0,0 +1,48 @@ +// +// 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. +// + +using System.Collections.Generic; +using OpenQA.Selenium.BiDi.Communication; + +#nullable enable + +namespace OpenQA.Selenium.BiDi.Modules.Network; + +internal class SetCacheBehaviorCommand(SetCacheBehaviorCommandParameters @params) : Command(@params); + +internal record SetCacheBehaviorCommandParameters(CacheBehavior CacheBehavior) : CommandParameters +{ + public IEnumerable? Contexts { get; set; } +} + +public record SetCacheBehaviorOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } +} + +public record BrowsingContextSetCacheBehaviorOptions +{ + +} + +public enum CacheBehavior +{ + Default, + Bypass +} diff --git a/dotnet/test/common/BiDi/Network/NetworkTest.cs b/dotnet/test/common/BiDi/Network/NetworkTest.cs index b3340edcd942d..3ffc72e551a83 100644 --- a/dotnet/test/common/BiDi/Network/NetworkTest.cs +++ b/dotnet/test/common/BiDi/Network/NetworkTest.cs @@ -211,4 +211,11 @@ public async Task CanFailRequest() Assert.That(action, Throws.TypeOf().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); + } } From 7ed2141b9ca5b400cb5349d3b0125d11c0f1c1dc Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Wed, 22 Jan 2025 22:14:09 +0300 Subject: [PATCH 2/2] Add missing placeholder for empty options --- .../BrowsingContext/BrowsingContextNetworkModule.cs | 2 +- .../BiDi/Modules/Network/SetCacheBehaviorCommand.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs index 3d6b130d290b1..117e662a208b4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/BrowsingContextNetworkModule.cs @@ -71,7 +71,7 @@ public async Task InterceptAuthAsync(Func? Contexts { get; set; } }