Skip to content

Commit

Permalink
[dotnet] Annotate nullability for DriverService and chromium/safari…
Browse files Browse the repository at this point in the history
… services (#15101)

* [dotnet] Annotate nullability for `DriverService` and some derived types

* Default values to `null` instead of sentinel values.
  • Loading branch information
RenderMichael authored Jan 24, 2025
1 parent d4ba7a5 commit 286c139
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 160 deletions.
113 changes: 38 additions & 75 deletions dotnet/src/webdriver/Chromium/ChromiumDriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System.Globalization;
using System.Text;

#nullable enable

namespace OpenQA.Selenium.Chromium
{
/// <summary>
Expand All @@ -30,15 +32,6 @@ public abstract class ChromiumDriverService : DriverService
{
private const string DefaultChromeDriverServiceExecutableName = "chromedriver";

private string logPath = string.Empty;
private string urlPathPrefix = string.Empty;
private string portServerAddress = string.Empty;
private string allowedIPAddresses = string.Empty;
private int adbPort = -1;
private bool disableBuildCheck;
private bool enableVerboseLogging;
private bool enableAppendLog;

/// <summary>
/// Initializes a new instance of the <see cref="ChromiumDriverService"/> class.
/// </summary>
Expand All @@ -51,94 +44,64 @@ protected ChromiumDriverService(string executablePath, string executableFileName
}

/// <summary>
/// Gets or sets the location of the log file written to by the ChromeDriver executable.
/// <para>Gets or sets the location of the log file written to by the ChromeDriver executable.</para>
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no log path.</para>
/// </summary>
public string LogPath
{
get { return this.logPath; }
set { this.logPath = value; }
}
public string? LogPath { get; set; }

/// <summary>
/// Gets or sets the base URL path prefix for commands (e.g., "wd/url").
/// <para>Gets or sets the base URL path prefix for commands (e.g., "wd/url").</para>
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no prefix.</para>
/// </summary>
public string UrlPathPrefix
{
get { return this.urlPathPrefix; }
set { this.urlPathPrefix = value; }
}
public string? UrlPathPrefix { get; set; }

/// <summary>
/// Gets or sets the address of a server to contact for reserving a port.
/// <para>Gets or sets the address of a server to contact for reserving a port.</para>
/// <para><see langword="null"/> or <see cref="string.Empty"/> signify no port server.</para>
/// </summary>
public string PortServerAddress
{
get { return this.portServerAddress; }
set { this.portServerAddress = value; }
}
public string? PortServerAddress { get; set; }

/// <summary>
/// Gets or sets the port on which the Android Debug Bridge is listening for commands.
/// <para>Gets or sets the port on which the Android Debug Bridge is listening for commands.</para>
/// <para>A value less than or equal to 0, or <see langword="null"/>, indicates no Android Debug Bridge specified.</para>
/// </summary>
public int AndroidDebugBridgePort
{
get { return this.adbPort; }
set { this.adbPort = value; }
}
public int? AndroidDebugBridgePort { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to skip version compatibility check
/// between the driver and the browser.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool DisableBuildCheck
{
get { return this.disableBuildCheck; }
set { this.disableBuildCheck = value; }
}
public bool DisableBuildCheck { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable verbose logging for the ChromeDriver executable.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool EnableVerboseLogging
{
get { return this.enableVerboseLogging; }
set { this.enableVerboseLogging = value; }
}
public bool EnableVerboseLogging { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable appending to an existing ChromeDriver log file.
/// Defaults to <see langword="false"/>.
/// </summary>
public bool EnableAppendLog
{
get { return this.enableAppendLog; }
set { this.enableAppendLog = value; }
}
public bool EnableAppendLog { get; set; }

/// <summary>
/// Gets or sets the comma-delimited list of IP addresses that are approved to
/// connect to this instance of the Chrome driver. Defaults to an empty string,
/// which means only the local loopback address can connect.
/// <para>Gets or sets the comma-delimited list of IP addresses that are approved to connect to this instance of the Chrome driver.</para>
/// <para>A value of <see langword="null"/> or <see cref="string.Empty"/> means only the local loopback address can connect.</para>
/// </summary>
[Obsolete($"Use {nameof(AllowedIPAddresses)}")]
public string WhitelistedIPAddresses
public string? WhitelistedIPAddresses
{
get { return this.allowedIPAddresses; }
set { this.allowedIPAddresses = value; }
get => this.AllowedIPAddresses;
set => this.AllowedIPAddresses = value;
}

/// <summary>
/// Gets or sets the comma-delimited list of IP addresses that are approved to
/// connect to this instance of the Chrome driver. Defaults to an empty string,
/// which means only the local loopback address can connect.
/// <para>Gets or sets the comma-delimited list of IP addresses that are approved to connect to this instance of the Chrome driver.</para>
/// <para>A value of <see langword="null"/> or <see cref="string.Empty"/> means only the local loopback address can connect.</para>
/// </summary>
public string AllowedIPAddresses
{
get => this.allowedIPAddresses;
set => this.allowedIPAddresses = value;
}
public string? AllowedIPAddresses { get; set; }

/// <summary>
/// Gets the command-line arguments for the driver service.
Expand All @@ -148,49 +111,49 @@ protected override string CommandLineArguments
get
{
StringBuilder argsBuilder = new StringBuilder(base.CommandLineArguments);
if (this.adbPort > 0)
if (this.AndroidDebugBridgePort is int adb && adb > 0)
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", this.adbPort);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --adb-port={0}", adb);
}

if (this.SuppressInitialDiagnosticInformation)
{
argsBuilder.Append(" --silent");
}

if (this.disableBuildCheck)
if (this.DisableBuildCheck)
{
argsBuilder.Append(" --disable-build-check");
}

if (this.enableVerboseLogging)
if (this.EnableVerboseLogging)
{
argsBuilder.Append(" --verbose");
}

if (this.enableAppendLog)
if (this.EnableAppendLog)
{
argsBuilder.Append(" --append-log");
}

if (!string.IsNullOrEmpty(this.logPath))
if (!string.IsNullOrEmpty(this.LogPath))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.logPath);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --log-path=\"{0}\"", this.LogPath);
}

if (!string.IsNullOrEmpty(this.urlPathPrefix))
if (!string.IsNullOrEmpty(this.UrlPathPrefix))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.urlPathPrefix);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --url-base={0}", this.UrlPathPrefix);
}

if (!string.IsNullOrEmpty(this.portServerAddress))
if (!string.IsNullOrEmpty(this.PortServerAddress))
{
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.portServerAddress);
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --port-server={0}", this.PortServerAddress);
}

if (!string.IsNullOrEmpty(this.allowedIPAddresses))
if (!string.IsNullOrEmpty(this.AllowedIPAddresses))
{
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.allowedIPAddresses));
argsBuilder.Append(string.Format(CultureInfo.InvariantCulture, " -allowed-ips={0}", this.AllowedIPAddresses));
}

return argsBuilder.ToString();
Expand Down
Loading

0 comments on commit 286c139

Please sign in to comment.