[dotnet] implement getting and setting permissions on Safari
// </copyright>
using System;
+using System.Collections.Generic;
using OpenQA.Selenium.Remote;
namespace OpenQA.Selenium.Safari
@@ -61,6 +62,9 @@ namespace OpenQA.Selenium.Safari
/// </example>
public class SafariDriver : WebDriver
{
+ private const string GetPermissionsCommand = "getPermissions";
+ private const string SetPermissionsCommand = "setPermissions";
+
/// <summary>
/// Initializes a new instance of the <see cref="SafariDriver"/> class.
/// </summary>
@@ -140,6 +144,37 @@ public SafariDriver(SafariDriverService service, SafariOptions options)
public SafariDriver(SafariDriverService service, SafariOptions options, TimeSpan commandTimeout)
: base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
{
+ this.AddCustomSafariCommand(GetPermissionsCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/apple/permissions");
+ this.AddCustomSafariCommand(SetPermissionsCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/apple/permissions");
+ }
+
+ /// <summary>
+ /// Set permission of an item on the browser. The only supported permission at this time is "getUserMedia".
+ /// </summary>
+ /// <param name="permissionName">The name of the item to set permission on.</param>
+ /// <param name="permissionValue">Whether the permission has been granted.</param>
+ public void SetPermission(string permissionName, bool permissionValue)
+ {
+ if (string.IsNullOrEmpty(permissionName))
+ {
+ throw new ArgumentNullException("permissionName", "permission must not be null or the empty string");
+ }
+
+ Dictionary<string, object> permissions = new Dictionary<string, object>();
+ permissions[permissionName] = permissionValue;
+ Dictionary<string, object> parameters = new Dictionary<string, object>();
+ parameters["permissions"] = permissions;
+ this.Execute(SetPermissionsCommand, parameters);
+ }
+
+ /// <summary>
+ /// Returns Each available permission item and whether it is allowed or not.
+ /// </summary>
+ /// <returns>whether the item is allowed or not.</returns>
+ public Object GetPermissions()
+ {
+ Response response = this.Execute(GetPermissionsCommand, null);
+ return response.Value;
}
/// <summary>
@@ -167,5 +202,11 @@ private static ICapabilities ConvertOptionsToCapabilities(SafariOptions options)
return options.ToCapabilities();
}
+
+ private void AddCustomSafariCommand(string commandName, string method, string resourcePath)
+ {
+ HttpCommandInfo commandInfoToAdd = new HttpCommandInfo(method, resourcePath);
+ this.CommandExecutor.TryAddCommand(commandName, commandInfoToAdd);
+ }
}
}
