Skip to content

[dotnet] Annotate nullability on devtools event args #15134

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

Merged
merged 1 commit into from
Jan 23, 2025
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
17 changes: 15 additions & 2 deletions dotnet/src/webdriver/DevTools/AuthRequiredEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,34 @@

using System;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Event arguments present when the AuthRequired event is raised.
/// </summary>
public class AuthRequiredEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="AuthRequiredEventArgs"/> type.
/// </summary>
/// <param name="requestId">The request ID of the request raised the event.</param>
/// <param name="uri">The URI for which the event is raised.</param>
public AuthRequiredEventArgs(string requestId, string uri)
{
Uri = uri;
RequestId = requestId;
}

/// <summary>
/// Gets the URI for which the event is raised.
/// </summary>
public string Uri { get; internal set; }
public string Uri { get; }

/// <summary>
/// Gets the request ID of the request raising the event.
/// </summary>
public string RequestId { get; internal set; }
public string RequestId { get; }
}
}
21 changes: 18 additions & 3 deletions dotnet/src/webdriver/DevTools/BindingCalledEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,41 @@

using System;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Event arguments present when the BindingCalled event is raised.
/// </summary>
public class BindingCalledEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="BindingCalledEventArgs"/> type.
/// </summary>
/// <param name="executionContextId">The execution ID of the call to the binding.</param>
/// <param name="name">The name of the call to the binding.</param>
/// <param name="payload">The payload of the call to the binding.</param>
public BindingCalledEventArgs(long executionContextId, string name, string payload)
{
this.ExecutionContextId = executionContextId;
this.Name = name;
this.Payload = payload;
}

/// <summary>
/// Gets the execution context ID of the call to the binding.
/// </summary>
public long ExecutionContextId { get; internal set; }
public long ExecutionContextId { get; }

/// <summary>
/// Gets the name of the call to the binding.
/// </summary>
public string Name { get; internal set; }
public string Name { get; }

/// <summary>
/// Gets the payload of the call to the binding.
/// </summary>
public string Payload { get; internal set; }
public string Payload { get; }
}
}
6 changes: 4 additions & 2 deletions dotnet/src/webdriver/DevTools/CommandResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// under the License.
// </copyright>

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -29,8 +31,8 @@ public static class ICommandResponseExtensions
/// </summary>
/// <typeparam name="TCommandResponse">The concrete implementation type of command response expected.</typeparam>
/// <param name="response">The <see cref="ICommandResponse"/> object to convert to the implementation type</param>
/// <returns>The concrete implementation of the command response.</returns>
public static TCommandResponse GetResponse<TCommandResponse>(this ICommandResponse response)
/// <returns>The concrete implementation of the command response, or <see langword="null"/> if <paramref name="response"/> is not the right type.</returns>
public static TCommandResponse? GetResponse<TCommandResponse>(this ICommandResponse response)
where TCommandResponse : class, ICommandResponse
{
return response as TCommandResponse;
Expand Down
18 changes: 16 additions & 2 deletions dotnet/src/webdriver/DevTools/CommandResponseTypeMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
Expand All @@ -34,8 +37,19 @@ public class CommandResponseTypeMap
/// </summary>
/// <param name="commandSettingsType">The type of command to add the mapping for.</param>
/// <param name="commandResponseType">The type of response object corresponding to the command.</param>
/// <exception cref="ArgumentNullException">If <paramref name="commandSettingsType"/> or <paramref name="commandResponseType"/> are <see langword="null"/>.</exception>
public void AddCommandResponseType(Type commandSettingsType, Type commandResponseType)
{
if (commandSettingsType is null)
{
throw new ArgumentNullException(nameof(commandSettingsType));
}

if (commandResponseType is null)
{
throw new ArgumentNullException(nameof(commandResponseType));
}

if (!commandResponseTypeDictionary.ContainsKey(commandSettingsType))
{
commandResponseTypeDictionary.Add(commandSettingsType, commandResponseType);
Expand All @@ -48,7 +62,7 @@ public void AddCommandResponseType(Type commandSettingsType, Type commandRespons
/// <typeparam name="T">The type of command for which to retrieve the response type.</typeparam>
/// <param name="commandResponseType">The returned response type.</param>
/// <returns><see langword="true"/> if the specified command type has a mapped response type; otherwise, <see langword="false"/>.</returns>
public bool TryGetCommandResponseType<T>(out Type commandResponseType)
public bool TryGetCommandResponseType<T>([NotNullWhen(true)] out Type? commandResponseType)
where T : ICommand
{
return commandResponseTypeDictionary.TryGetValue(typeof(T), out commandResponseType);
Expand All @@ -60,7 +74,7 @@ public bool TryGetCommandResponseType<T>(out Type commandResponseType)
/// <param name="command">The type of command for which to retrieve the response type.</param>
/// <param name="commandResponseType">The returned response type.</param>
/// <returns><see langword="true"/> if the specified command type has a mapped response type; otherwise, <see langword="false"/>.</returns>
public bool TryGetCommandResponseType(ICommand command, out Type commandResponseType)
public bool TryGetCommandResponseType(ICommand command, [NotNullWhen(true)] out Type? commandResponseType)
{
return commandResponseTypeDictionary.TryGetValue(command.GetType(), out commandResponseType);
}
Expand Down
20 changes: 18 additions & 2 deletions dotnet/src/webdriver/DevTools/ConsoleApiArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,37 @@
// under the License.
// </copyright>

#nullable enable

using System;

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Represents information about a an argument in call to the browser's console API.
/// </summary>
public class ConsoleApiArgument
{
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleApiArgument"/> type.
/// </summary>
/// <param name="type">The type of the argument in the call to the browser's console API.</param>
/// <param name="value">The value of the argument in the call to the browser's console API.</param>
/// <exception cref="ArgumentNullException">If <paramref name="type"/> is <see langword="null"/>.</exception>
public ConsoleApiArgument(string type, string? value)
{
Type = type ?? throw new ArgumentNullException(nameof(type));
Value = value;
}

/// <summary>
/// Gets the type of the argument in the call to the browser's console API.
/// </summary>
public string Type { get; internal set; }
public string Type { get; }

/// <summary>
/// Gets the value of the argument in the call to the browser's console API.
/// </summary>
public string Value { get; internal set; }
public string? Value { get; }
}
}
22 changes: 19 additions & 3 deletions dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,42 @@
using System;
using System.Collections.ObjectModel;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Event arguments present when the ConsoleApiCalled event is raised.
/// </summary>
public class ConsoleApiCalledEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="ConsoleApiCalledEventArgs"/> type.
/// </summary>
/// <param name="timestamp">The time stanp when the browser's console API is called.</param>
/// <param name="type">The type of message when the browser's console API is called.</param>
/// <param name="arguments">The arguments of the call to the browser's console API.</param>
/// <exception cref="ArgumentNullException">If <paramref name="arguments"/> is <see langword="null"/>.</exception>
public ConsoleApiCalledEventArgs(DateTime timestamp, string type, ReadOnlyCollection<ConsoleApiArgument> arguments)
{
Timestamp = timestamp;
Type = type;
Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments));
}

/// <summary>
/// Gets the time stanp when the browser's console API is called.
/// </summary>
public DateTime Timestamp { get; internal set; }
public DateTime Timestamp { get; }

/// <summary>
/// Gets the type of message when the browser's console API is called.
/// </summary>
public string Type { get; internal set; }
public string Type { get; }

/// <summary>
/// Gets the arguments of the call to the browser's console API.
/// </summary>
public ReadOnlyCollection<ConsoleApiArgument> Arguments { get; internal set; }
public ReadOnlyCollection<ConsoleApiArgument> Arguments { get; }
}
}
11 changes: 8 additions & 3 deletions dotnet/src/webdriver/DevTools/DevToolsCommandData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
// under the License.
// </copyright>

using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Threading;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -35,6 +38,7 @@ public class DevToolsCommandData
/// <param name="commandId">The ID of the commmand execution.</param>
/// <param name="commandName">The method name of the DevTools command.</param>
/// <param name="commandParameters">The parameters of the DevTools command.</param>
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
public DevToolsCommandData(long commandId, string commandName, JsonNode commandParameters)
: this(commandId, null, commandName, commandParameters)
{
Expand All @@ -47,11 +51,12 @@ public DevToolsCommandData(long commandId, string commandName, JsonNode commandP
/// <param name="sessionId">The session ID of the current command execution.</param>
/// <param name="commandName">The method name of the DevTools command.</param>
/// <param name="commandParameters">The parameters of the DevTools command.</param>
public DevToolsCommandData(long commandId, string sessionId, string commandName, JsonNode commandParameters)
/// <exception cref="ArgumentNullException">If <paramref name="commandName"/> is <see langword="null"/>.</exception>
public DevToolsCommandData(long commandId, string? sessionId, string commandName, JsonNode commandParameters)
{
CommandId = commandId;
SessionId = sessionId;
CommandName = commandName;
CommandName = commandName ?? throw new ArgumentNullException(nameof(commandName));
CommandParameters = commandParameters;
SyncEvent = new ManualResetEventSlim(false);
}
Expand All @@ -61,7 +66,7 @@ public DevToolsCommandData(long commandId, string sessionId, string commandName,
/// </summary>
[JsonPropertyName("sessionId")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string SessionId { get; }
public string? SessionId { get; }

/// <summary>
/// Gets the numeric ID of the command execution.
Expand Down
7 changes: 5 additions & 2 deletions dotnet/src/webdriver/DevTools/DevToolsEventData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

using System;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
Expand All @@ -31,10 +33,11 @@ public class DevToolsEventData
/// </summary>
/// <param name="eventArgsType">The type of the event args for the event to be raised.</param>
/// <param name="invoker">The method that will be used to invoke the event.</param>
/// <exception cref="ArgumentNullException">If<paramref name="eventArgsType"/> or <paramref name="invoker"/> is <see langword="null"/>.</exception>
public DevToolsEventData(Type eventArgsType, Action<object> invoker)
{
EventArgsType = eventArgsType;
EventInvoker = invoker;
EventArgsType = eventArgsType ?? throw new ArgumentNullException(nameof(eventArgsType));
EventInvoker = invoker ?? throw new ArgumentNullException(nameof(invoker));
}

/// <summary>
Expand Down
14 changes: 13 additions & 1 deletion dotnet/src/webdriver/DevTools/EntryAddedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@

using System;

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Provides data for events relating to entries being added to the browser's log.
/// </summary>
public class EntryAddedEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="EntryAddedEventArgs"/> type.
/// </summary>
/// <param name="entry">The entry added to the browser's log.</param>
/// <exception cref="ArgumentNullException">If </exception>
public EntryAddedEventArgs(LogEntry entry)
{
Entry = entry ?? throw new ArgumentNullException(nameof(entry));
}

/// <summary>
/// The entry added to the browser's log.
/// </summary>
public LogEntry Entry { get; set; }
public LogEntry Entry { get; }
}
}
17 changes: 15 additions & 2 deletions dotnet/src/webdriver/DevTools/LogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,34 @@
// under the License.
// </copyright>

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Represents information about a log entry when the browser console is written to.
/// </summary>
public class LogEntry
{
/// <summary>
/// Initializes a new instance of the <see cref="LogEntry"/> type.
/// </summary>
/// <param name="kind">The kind of message written to the log.</param>
/// <param name="message">The text of the message written to the log.</param>
public LogEntry(string kind, string message)
{
Kind = kind;
Message = message;
}

/// <summary>
/// Gets the kind of message written to the log.
/// </summary>
public string Kind { get; internal set; }
public string Kind { get; }

/// <summary>
/// Gets the text of the message written to the log.
/// </summary>
public string Message { get; internal set; }
public string Message { get; }
}
}
Loading
Loading