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
21 changes: 21 additions & 0 deletions dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,25 @@ public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindows
{
return await Broker.ExecuteCommandAsync<GetClientWindowsCommand, GetClientWindowsResult>(new(), options).ConfigureAwait(false);
}

public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
{
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);

return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}

public async Task<EmptyResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
{
var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);

return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}

public async Task<EmptyResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
{
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);

return await Broker.ExecuteCommandAsync<SetDownloadBehaviorCommand, EmptyResult>(new SetDownloadBehaviorCommand(@params), options).ConfigureAwait(false);
}
}
43 changes: 43 additions & 0 deletions dotnet/src/webdriver/BiDi/Browser/SetDownloadBehaviorCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// <copyright file="SetDownloadBehaviorCommand.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 OpenQA.Selenium.BiDi.Communication;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OpenQA.Selenium.BiDi.Browser;

internal sealed class SetDownloadBehaviorCommand(SetDownloadBehaviorParameters @params)
: Command<SetDownloadBehaviorParameters, EmptyResult>(@params, "browser.setDownloadBehavior");

internal sealed record SetDownloadBehaviorParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] DownloadBehavior? DownloadBehavior, IEnumerable<UserContext>? UserContexts) : Parameters;

[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
[JsonDerivedType(typeof(DownloadBehaviorAllowed), "allowed")]
[JsonDerivedType(typeof(DownloadBehaviorDenied), "denied")]
internal abstract record DownloadBehavior;

internal sealed record DownloadBehaviorAllowed(string DestinationFolder) : DownloadBehavior;

internal sealed record DownloadBehaviorDenied : DownloadBehavior;

public sealed class SetDownloadBehaviorOptions : CommandOptions
{
public IEnumerable<UserContext>? UserContexts { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
[JsonSerializable(typeof(Browser.RemoveUserContextCommand))]
[JsonSerializable(typeof(Browser.GetClientWindowsCommand))]
[JsonSerializable(typeof(Browser.GetClientWindowsResult))]
[JsonSerializable(typeof(Browser.SetDownloadBehaviorCommand))]
[JsonSerializable(typeof(Browser.UserContextInfo))]
[JsonSerializable(typeof(IReadOnlyList<Browser.UserContextInfo>))]
[JsonSerializable(typeof(IReadOnlyList<Browser.ClientWindowInfo>))]
Expand Down
33 changes: 33 additions & 0 deletions dotnet/test/common/BiDi/Browser/BrowserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,37 @@ public async Task CanGetClientWindows()
Assert.That(clientWindows, Has.Count.GreaterThanOrEqualTo(1));
Assert.That(clientWindows[0].ClientWindow, Is.Not.Null);
}

[Test]
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
public async Task CanSetDownloadBehaviorAllowed()
{
var result = await bidi.Browser.SetDownloadBehaviorAllowedAsync("/my/path");

Assert.That(result, Is.Not.Null);
}

[Test]
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
public async Task CanSetDownloadBehaviorAllowedDefault()
{
var result = await bidi.Browser.SetDownloadBehaviorAllowedAsync();

Assert.That(result, Is.Not.Null);
}

[Test]
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
public async Task CanSetDownloadBehaviorDenied()
{
var result = await bidi.Browser.SetDownloadBehaviorDeniedAsync();

Assert.That(result, Is.Not.Null);
}
}