Skip to content

[dotnet] Remove client side validation of well-known Options #16120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
23 changes: 0 additions & 23 deletions dotnet/src/webdriver/Chromium/ChromiumOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,6 @@ public abstract class ChromiumOptions : DriverOptions
private string? mobileEmulationDeviceName;
private ChromiumMobileEmulationDeviceSettings? mobileEmulationDeviceSettings;

/// <summary>
/// Initializes a new instance of the <see cref="ChromiumOptions"/> class.
/// </summary>
public ChromiumOptions() : base()
{
this.AddKnownCapabilityName(this.CapabilityName, "current ChromiumOptions class instance");
this.AddKnownCapabilityName(CapabilityType.LoggingPreferences, "SetLoggingPreference method");
this.AddKnownCapabilityName(this.LoggingPreferencesChromeOption, "SetLoggingPreference method");
this.AddKnownCapabilityName(ChromiumOptions.ArgumentsChromeOption, "AddArguments method");
this.AddKnownCapabilityName(ChromiumOptions.BinaryChromeOption, "BinaryLocation property");
this.AddKnownCapabilityName(ChromiumOptions.ExtensionsChromeOption, "AddExtensions method");
this.AddKnownCapabilityName(ChromiumOptions.LocalStateChromeOption, "AddLocalStatePreference method");
this.AddKnownCapabilityName(ChromiumOptions.PreferencesChromeOption, "AddUserProfilePreference method");
this.AddKnownCapabilityName(ChromiumOptions.DetachChromeOption, "LeaveBrowserRunning property");
this.AddKnownCapabilityName(ChromiumOptions.DebuggerAddressChromeOption, "DebuggerAddress property");
this.AddKnownCapabilityName(ChromiumOptions.ExcludeSwitchesChromeOption, "AddExcludedArgument property");
this.AddKnownCapabilityName(ChromiumOptions.MinidumpPathChromeOption, "MinidumpPath property");
this.AddKnownCapabilityName(ChromiumOptions.MobileEmulationChromeOption, "EnableMobileEmulation method");
this.AddKnownCapabilityName(ChromiumOptions.PerformanceLoggingPreferencesChromeOption, "PerformanceLoggingPreferences property");
this.AddKnownCapabilityName(ChromiumOptions.WindowTypesChromeOption, "AddWindowTypes method");
this.AddKnownCapabilityName(ChromiumOptions.UseSpecCompliantProtocolOption, "UseSpecCompliantProtocol property");
}

/// <summary>
/// Gets the vendor prefix to apply to Chromium-specific capability names.
/// </summary>
Expand Down
83 changes: 0 additions & 83 deletions dotnet/src/webdriver/DriverOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace OpenQA.Selenium;

Expand Down Expand Up @@ -115,23 +114,6 @@ public abstract class DriverOptions
{
private readonly Dictionary<string, object> additionalCapabilities = new Dictionary<string, object>();
private readonly Dictionary<string, LogLevel> loggingPreferences = new Dictionary<string, LogLevel>();
private readonly Dictionary<string, string> knownCapabilityNames = new Dictionary<string, string>();

/// <summary>
/// Initializes a new instance of the <see cref="DriverOptions"/> class.
/// </summary>
protected DriverOptions()
{
this.AddKnownCapabilityName(CapabilityType.BrowserName, "BrowserName property");
this.AddKnownCapabilityName(CapabilityType.BrowserVersion, "BrowserVersion property");
this.AddKnownCapabilityName(CapabilityType.PlatformName, "PlatformName property");
this.AddKnownCapabilityName(CapabilityType.Proxy, "Proxy property");
this.AddKnownCapabilityName(CapabilityType.UnhandledPromptBehavior, "UnhandledPromptBehavior property");
this.AddKnownCapabilityName(CapabilityType.PageLoadStrategy, "PageLoadStrategy property");
this.AddKnownCapabilityName(CapabilityType.UseStrictFileInteractability, "UseStrictFileInteractability property");
this.AddKnownCapabilityName(CapabilityType.WebSocketUrl, "UseWebSocketUrl property");
this.AddKnownCapabilityName(CapabilityType.EnableDownloads, "EnableDownloads property");
}

/// <summary>
/// Gets or sets the name of the browser.
Expand Down Expand Up @@ -361,71 +343,6 @@ protected void ValidateCapabilityName([NotNull] string? capabilityName)
{
throw new ArgumentException("Capability name may not be null an empty string.", nameof(capabilityName));
}

if (this.TryGetKnownCapability(capabilityName!, out string? typeSafeOptionName))
{
string message = string.Format(CultureInfo.InvariantCulture, "There is already an option for the {0} capability. Please use the {1} instead.", capabilityName, typeSafeOptionName);
throw new ArgumentException(message, nameof(capabilityName));
}
}

/// <summary>
/// Adds a known capability to the list of known capabilities and associates it
/// with the type-safe property name of the options class to be used instead.
/// </summary>
/// <param name="capabilityName">The name of the capability.</param>
/// <param name="typeSafeOptionName">The name of the option property or method to be used instead.</param>
protected void AddKnownCapabilityName(string capabilityName, string typeSafeOptionName)
{
this.knownCapabilityNames[capabilityName] = typeSafeOptionName;
}

/// <summary>
/// Remove a capability from the list of known capabilities
/// </summary>
/// <param name="capabilityName">The name of the capability to be removed.</param>
protected void RemoveKnownCapabilityName(string? capabilityName)
{
if (capabilityName is not null)
{
this.knownCapabilityNames.Remove(capabilityName);
}
}

/// <summary>
/// Gets a value indicating whether the specified capability name is a known capability name which has a type-safe option.
/// </summary>
/// <param name="capabilityName">The name of the capability to check.</param>
/// <returns><see langword="true"/> if the capability name is known; otherwise <see langword="false"/>.</returns>
protected bool IsKnownCapabilityName(string capabilityName)
{
return this.knownCapabilityNames.ContainsKey(capabilityName);
}

/// <summary>
/// Gets a value indicating whether the specified capability name is a known capability name which has a type-safe option.
/// </summary>
/// <param name="capabilityName">The name of the capability to check.</param>
/// <param name="typeSafeOptionName">The name of the type-safe option for the given capability name, or <see langword="null"/> if not found.</param>
/// <returns><see langword="true"/> if the capability name is known; otherwise <see langword="false"/>.</returns>
protected bool TryGetKnownCapability(string capabilityName, [NotNullWhen(true)] out string? typeSafeOptionName)
{
return this.knownCapabilityNames.TryGetValue(capabilityName, out typeSafeOptionName);
}

/// <summary>
/// Gets the name of the type-safe option for a given capability name.
/// </summary>
/// <param name="capabilityName">The name of the capability to check.</param>
/// <returns>The name of the type-safe option for the given capability name.</returns>
protected string GetTypeSafeOptionName(string capabilityName)
{
if (!this.IsKnownCapabilityName(capabilityName))
{
return string.Empty;
}

return this.knownCapabilityNames[capabilityName];
}

/// <summary>
Expand Down
12 changes: 1 addition & 11 deletions dotnet/src/webdriver/Firefox/FirefoxOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,7 @@ public FirefoxOptions()
: base()
{
this.BrowserName = BrowserNameValue;
this.AddKnownCapabilityName(FirefoxOptions.FirefoxOptionsCapability, "current FirefoxOptions class instance");
this.AddKnownCapabilityName(FirefoxOptions.IsMarionetteCapability, "UseLegacyImplementation property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxProfileCapability, "Profile property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxBinaryCapability, "BrowserExecutableLocation property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxArgumentsCapability, "AddArguments method");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxPrefsCapability, "SetPreference method");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxEnvCapability, "SetEnvironmentVariable method");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxLogCapability, "LogLevel property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxLegacyProfileCapability, "Profile property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxLegacyBinaryCapability, "BrowserExecutableLocation property");
this.AddKnownCapabilityName(FirefoxOptions.FirefoxEnableDevToolsProtocolCapability, "EnableDevToolsProtocol property");

// https://fxdx.dev/deprecating-cdp-support-in-firefox-embracing-the-future-with-webdriver-bidi/.
// Enable BiDi only
this.SetPreference("remote.active-protocols", 1);
Expand Down
21 changes: 0 additions & 21 deletions dotnet/src/webdriver/IE/InternetExplorerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,6 @@ public InternetExplorerOptions() : base()
{
this.BrowserName = BrowserNameValue;
this.PlatformName = "windows";
this.AddKnownCapabilityName(Capability, "current InterentExplorerOptions class instance");
this.AddKnownCapabilityName(IgnoreProtectedModeSettingsCapability, "IntroduceInstabilityByIgnoringProtectedModeSettings property");
this.AddKnownCapabilityName(IgnoreZoomSettingCapability, "IgnoreZoomLevel property");
this.AddKnownCapabilityName(CapabilityType.HasNativeEvents, "EnableNativeEvents property");
this.AddKnownCapabilityName(InitialBrowserUrlCapability, "InitialBrowserUrl property");
this.AddKnownCapabilityName(ElementScrollBehaviorCapability, "ElementScrollBehavior property");
this.AddKnownCapabilityName(CapabilityType.UnexpectedAlertBehavior, "UnhandledPromptBehavior property");
this.AddKnownCapabilityName(EnablePersistentHoverCapability, "EnablePersistentHover property");
this.AddKnownCapabilityName(RequireWindowFocusCapability, "RequireWindowFocus property");
this.AddKnownCapabilityName(BrowserAttachTimeoutCapability, "BrowserAttachTimeout property");
this.AddKnownCapabilityName(ForceCreateProcessApiCapability, "ForceCreateProcessApi property");
this.AddKnownCapabilityName(ForceShellWindowsApiCapability, "ForceShellWindowsApi property");
this.AddKnownCapabilityName(BrowserCommandLineSwitchesCapability, "BrowserComaandLineArguments property");
this.AddKnownCapabilityName(UsePerProcessProxyCapability, "UsePerProcessProxy property");
this.AddKnownCapabilityName(EnsureCleanSessionCapability, "EnsureCleanSession property");
this.AddKnownCapabilityName(FileUploadDialogTimeoutCapability, "FileUploadDialogTimeout property");
this.AddKnownCapabilityName(EnableFullPageScreenshotCapability, "EnableFullPageScreenshot property");
this.AddKnownCapabilityName(LegacyFileUploadDialogHandlingCapability, "LegacyFileUploadDialogHanlding property");
this.AddKnownCapabilityName(AttachToEdgeChromeCapability, "AttachToEdgeChrome property");
this.AddKnownCapabilityName(EdgeExecutablePathCapability, "EdgeExecutablePath property");
this.AddKnownCapabilityName(IgnoreProcessMatchCapability, "IgnoreProcessMatch property");
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions dotnet/src/webdriver/Safari/SafariOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public SafariOptions() : base()
{
this.BrowserName = BrowserNameValue;
this.TechnologyPreview = false;
this.AddKnownCapabilityName(SafariOptions.EnableAutomaticInspectionSafariOption, "EnableAutomaticInspection property");
this.AddKnownCapabilityName(SafariOptions.EnableAutomaticProfilingSafariOption, "EnableAutomaticProfiling property");
}

/// <summary>
Expand Down
Loading