Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 2 additions & 16 deletions dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,9 @@ public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindows
return await ExecuteAsync(GetClientWindowsCommand, Parameters.Empty, options, cancellationToken).ConfigureAwait(false);
}

public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default)
public async Task<SetDownloadBehaviorResult> 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<SetDownloadBehaviorResult> 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<SetDownloadBehaviorResult> 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);
}
Comment thread
nvborisenko marked this conversation as resolved.
Expand Down
4 changes: 1 addition & 3 deletions dotnet/src/webdriver/BiDi/Browser/IBrowserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ public interface IBrowserModule
Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null, CancellationToken cancellationToken = default);
Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null, CancellationToken cancellationToken = default);
Task<RemoveUserContextResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null, CancellationToken cancellationToken = default);
Comment thread
nvborisenko marked this conversation as resolved.
Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default);
Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default);
Task<SetDownloadBehaviorResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default);
Task<SetDownloadBehaviorResult> SetDownloadBehaviorAsync(DownloadBehavior? downloadBehavior, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default);
}
9 changes: 6 additions & 3 deletions dotnet/src/webdriver/BiDi/Browser/SetDownloadBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
24 changes: 11 additions & 13 deletions dotnet/test/webdriver/BiDi/Browser/BrowserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// under the License.
// </copyright>

using OpenQA.Selenium.BiDi.Browser;

namespace OpenQA.Selenium.Tests.BiDi.Browser;

internal class BrowserTests : BiDiTestFixture
Expand Down Expand Up @@ -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"));
Comment thread
nvborisenko marked this conversation as resolved.

Comment thread
nvborisenko marked this conversation as resolved.
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);
}
Expand Down
Loading