diff --git a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs index d0e847adaf826..938790269bfe4 100644 --- a/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs @@ -71,23 +71,9 @@ public async Task GetClientWindowsAsync(GetClientWindows return await ExecuteAsync(GetClientWindowsCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false); } - public async Task SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) + public async Task SetDownloadBehaviorAsync(DownloadBehavior? downloadBehavior, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) { - var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts); - - return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); - } - - public async Task SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) - { - var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts); - - return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); - } - - public async Task SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default) - { - var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts); + var @params = new SetDownloadBehaviorParameters(downloadBehavior, options?.UserContexts); return await ExecuteAsync(SetDownloadBehaviorCommand, @params, options, cancellationToken).ConfigureAwait(false); } diff --git a/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs b/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs index b79395b311e81..b77ebccd877fd 100644 --- a/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs +++ b/dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs @@ -26,7 +26,5 @@ public interface IBrowserModule Task GetClientWindowsAsync(GetClientWindowsOptions? options = null, CancellationToken cancellationToken = default); Task GetUserContextsAsync(GetUserContextsOptions? options = null, CancellationToken cancellationToken = default); Task RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null, CancellationToken cancellationToken = default); - Task SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); - Task SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); - Task SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); + Task SetDownloadBehaviorAsync(DownloadBehavior? downloadBehavior, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default); } diff --git a/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs b/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs index aef71f681dc28..cd3f6fab9c34f 100644 --- a/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs +++ b/dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs @@ -26,11 +26,14 @@ internal sealed record SetDownloadBehaviorParameters([property: JsonIgnore(Condi [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(DownloadBehaviorAllowed), "allowed")] [JsonDerivedType(typeof(DownloadBehaviorDenied), "denied")] -internal abstract record DownloadBehavior; +public abstract record DownloadBehavior +{ + public static DownloadBehavior? Default => null; +} -internal sealed record DownloadBehaviorAllowed(string DestinationFolder) : DownloadBehavior; +public sealed record DownloadBehaviorAllowed(string DestinationFolder) : DownloadBehavior; -internal sealed record DownloadBehaviorDenied : DownloadBehavior; +public sealed record DownloadBehaviorDenied : DownloadBehavior; public sealed record SetDownloadBehaviorOptions : CommandOptions { diff --git a/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs b/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs index 7a1047dafe948..548c64cd3c6e9 100644 --- a/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs +++ b/dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs @@ -17,6 +17,8 @@ // under the License. // +using OpenQA.Selenium.BiDi.Browser; + namespace OpenQA.Selenium.Tests.BiDi.Browser; internal class BrowserTests : BiDiTestFixture @@ -68,34 +70,30 @@ public async Task CanGetClientWindows() } [Test] - [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")] public async Task CanSetDownloadBehaviorAllowed() { - var result = await bidi.Browser.SetDownloadBehaviorAllowedAsync("/my/path"); + var result = await bidi.Browser.SetDownloadBehaviorAsync(new DownloadBehaviorAllowed("/my/path")); Assert.That(result, Is.Not.Null); } [Test] - [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")] - public async Task CanSetDownloadBehaviorAllowedDefault() + public async Task CanSetDownloadBehaviorDefault() { - var result = await bidi.Browser.SetDownloadBehaviorAllowedAsync(); + var result = await bidi.Browser.SetDownloadBehaviorAsync(null); + + // or + + var result2 = await bidi.Browser.SetDownloadBehaviorAsync(DownloadBehavior.Default); Assert.That(result, Is.Not.Null); + Assert.That(result2, Is.Not.Null); } [Test] - [IgnoreBrowser(Infrastructure.Browser.Chrome, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Edge, "Not supported yet?")] - [IgnoreBrowser(Infrastructure.Browser.Firefox, "Not supported yet?")] public async Task CanSetDownloadBehaviorDenied() { - var result = await bidi.Browser.SetDownloadBehaviorDeniedAsync(); + var result = await bidi.Browser.SetDownloadBehaviorAsync(new DownloadBehaviorDenied()); Assert.That(result, Is.Not.Null); }