Skip to content

Commit

Permalink
[dotnet] implement ability for Chrome and Edge to set applicable perm…
Browse files Browse the repository at this point in the history
…issions on browser
  • Loading branch information
titusfortner committed Sep 29, 2021
1 parent 232bd58 commit 90e8e61
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions dotnet/src/webdriver/Chromium/ChromiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public abstract class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
private const string SendChromeCommand = "sendChromeCommand";
private const string SendChromeCommandWithResult = "sendChromeCommandWithResult";
private const string LaunchAppCommand = "launchAppCommand";
private const string SetPermissionCommand = "setPermission";

private readonly string optionsCapabilityName;
private DevToolsSession devToolsSession;
Expand Down Expand Up @@ -83,6 +84,7 @@ public ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, Ti
this.AddCustomChromeCommand(SendChromeCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command");
this.AddCustomChromeCommand(SendChromeCommandWithResult, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
this.AddCustomChromeCommand(LaunchAppCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/launch_app");
this.AddCustomChromeCommand(SetPermissionCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/permissions");
}

/// <summary>
Expand Down Expand Up @@ -151,6 +153,31 @@ public void LaunchApp(string id)
this.Execute(LaunchAppCommand, parameters);
}

/// <summary>
/// Set supported permission on browser.
/// </summary>
/// <param name="permissionName">Name of item to set the permission on.</param>
/// <param name="permissionValue">Value to set the permission to.</param>
public void SetPermission(string permissionName, string permissionValue)
{
if (permissionName == null)
{
throw new ArgumentNullException("permissionName", "name must not be null");
}

if (permissionValue == null)
{
throw new ArgumentNullException("permissionValue", "value must not be null");
}

Dictionary<string, object> nameParameter = new Dictionary<string, object>();
nameParameter["name"] = permissionName;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["descriptor"] = nameParameter;
parameters["state"] = permissionValue;
this.Execute(SetPermissionCommand, parameters);
}

/// <summary>
/// Executes a custom Chrome Dev Tools Protocol Command.
/// </summary>
Expand Down

0 comments on commit 90e8e61

Please sign in to comment.