Skip to content

Commit

Permalink
Handle nullability of adjacent TargetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
RenderMichael committed Feb 5, 2025
1 parent ca21cab commit c54215d
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 83 deletions.
37 changes: 30 additions & 7 deletions dotnet/src/webdriver/DevTools/TargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,69 @@
// under the License.
// </copyright>

#nullable enable

namespace OpenQA.Selenium.DevTools
{
/// <summary>
/// Represents information about the target of a DevTools Protocol command
/// </summary>
public class TargetInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="TargetInfo"/> type.
/// </summary>
/// <param name="targetId">The ID of the target.</param>
/// <param name="type">The type of target.</param>
/// <param name="title">The title of the target.</param>
/// <param name="url">The URL of the target.</param>
/// <param name="isAttached">Whether the protocol is attached to the target.</param>
/// <param name="openerId">The ID of the opener of the target.</param>
/// <param name="browserContextId">The browser context ID.</param>
public TargetInfo(string targetId, string type, string title, string url, bool isAttached, string? openerId, string? browserContextId)
{
this.TargetId = targetId;
this.Type = type;
this.Title = title;
this.Url = url;
this.IsAttached = isAttached;
this.OpenerId = openerId;
this.BrowserContextId = browserContextId;
}

/// <summary>
/// Gets the ID of the target.
/// </summary>
public string TargetId { get; internal set; }
public string TargetId { get; }

/// <summary>
/// Gets the type of target.
/// </summary>
public string Type { get; internal set; }
public string Type { get; }

/// <summary>
/// Gets the title of the target.
/// </summary>
public string Title { get; internal set; }
public string Title { get; }

/// <summary>
/// Gets the URL of the target.
/// </summary>
public string Url { get; internal set; }
public string Url { get; }

/// <summary>
/// Gets a value indicating if the protocol is attached to the target.
/// </summary>
public bool IsAttached { get; internal set; }
public bool IsAttached { get; }

/// <summary>
/// Gets the ID of the opener of the target.
/// </summary>
public string OpenerId { get; internal set; }
public string? OpenerId { get; }

/// <summary>
/// Gets the browser context ID.
/// </summary>
public string BrowserContextId { get; internal set; }
public string? BrowserContextId { get; }
}
}
38 changes: 19 additions & 19 deletions dotnet/src/webdriver/DevTools/v130/V130Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public override async Task<ReadOnlyCollection<TargetInfo>> GetTargets(object? se
for (int i = 0; i < response.TargetInfos.Length; i++)
{
var targetInfo = response.TargetInfos[i];
var mapped = new TargetInfo()
{
TargetId = targetInfo.TargetId,
Title = targetInfo.Title,
Type = targetInfo.Type,
Url = targetInfo.Url,
OpenerId = targetInfo.OpenerId,
BrowserContextId = targetInfo.BrowserContextId,
IsAttached = targetInfo.Attached
};
var mapped = new TargetInfo
(
targetId: targetInfo.TargetId,
title: targetInfo.Title,
type: targetInfo.Type,
url: targetInfo.Url,
openerId: targetInfo.OpenerId,
browserContextId: targetInfo.BrowserContextId,
isAttached: targetInfo.Attached
);
targets.Add(mapped);
}

Expand Down Expand Up @@ -126,15 +126,15 @@ private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e)
private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e)
{
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
};
(
browserContextId: e.TargetInfo.BrowserContextId,
isAttached: e.TargetInfo.Attached,
openerId: e.TargetInfo.OpenerId,
targetId: e.TargetInfo.TargetId,
title: e.TargetInfo.Title,
type: e.TargetInfo.Type,
url: e.TargetInfo.Url
);

this.OnTargetAttached(new TargetAttachedEventArgs
(
Expand Down
38 changes: 19 additions & 19 deletions dotnet/src/webdriver/DevTools/v131/V131Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public override async Task<ReadOnlyCollection<TargetInfo>> GetTargets(object? se
for (int i = 0; i < response.TargetInfos.Length; i++)
{
var targetInfo = response.TargetInfos[i];
var mapped = new TargetInfo()
{
TargetId = targetInfo.TargetId,
Title = targetInfo.Title,
Type = targetInfo.Type,
Url = targetInfo.Url,
OpenerId = targetInfo.OpenerId,
BrowserContextId = targetInfo.BrowserContextId,
IsAttached = targetInfo.Attached
};
var mapped = new TargetInfo
(
targetId: targetInfo.TargetId,
title: targetInfo.Title,
type: targetInfo.Type,
url: targetInfo.Url,
openerId: targetInfo.OpenerId,
browserContextId: targetInfo.BrowserContextId,
isAttached: targetInfo.Attached
);
targets.Add(mapped);
}

Expand Down Expand Up @@ -126,15 +126,15 @@ private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e)
private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e)
{
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
};
(
browserContextId: e.TargetInfo.BrowserContextId,
isAttached: e.TargetInfo.Attached,
openerId: e.TargetInfo.OpenerId,
targetId: e.TargetInfo.TargetId,
title: e.TargetInfo.Title,
type: e.TargetInfo.Type,
url: e.TargetInfo.Url
);

this.OnTargetAttached(new TargetAttachedEventArgs
(
Expand Down
38 changes: 19 additions & 19 deletions dotnet/src/webdriver/DevTools/v132/V132Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public override async Task<ReadOnlyCollection<TargetInfo>> GetTargets(object? se
for (int i = 0; i < response.TargetInfos.Length; i++)
{
var targetInfo = response.TargetInfos[i];
var mapped = new TargetInfo()
{
TargetId = targetInfo.TargetId,
Title = targetInfo.Title,
Type = targetInfo.Type,
Url = targetInfo.Url,
OpenerId = targetInfo.OpenerId,
BrowserContextId = targetInfo.BrowserContextId,
IsAttached = targetInfo.Attached
};
var mapped = new TargetInfo
(
targetId: targetInfo.TargetId,
title: targetInfo.Title,
type: targetInfo.Type,
url: targetInfo.Url,
openerId: targetInfo.OpenerId,
browserContextId: targetInfo.BrowserContextId,
isAttached: targetInfo.Attached
);
targets.Add(mapped);
}

Expand Down Expand Up @@ -126,15 +126,15 @@ private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e)
private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e)
{
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
};
(
browserContextId: e.TargetInfo.BrowserContextId,
isAttached: e.TargetInfo.Attached,
openerId: e.TargetInfo.OpenerId,
targetId: e.TargetInfo.TargetId,
title: e.TargetInfo.Title,
type: e.TargetInfo.Type,
url: e.TargetInfo.Url
);

this.OnTargetAttached(new TargetAttachedEventArgs
(
Expand Down
38 changes: 19 additions & 19 deletions dotnet/src/webdriver/DevTools/v85/V85Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ public override async Task<ReadOnlyCollection<TargetInfo>> GetTargets(object? se
for (int i = 0; i < response.TargetInfos.Length; i++)
{
var targetInfo = response.TargetInfos[i];
var mapped = new TargetInfo()
{
TargetId = targetInfo.TargetId,
Title = targetInfo.Title,
Type = targetInfo.Type,
Url = targetInfo.Url,
OpenerId = targetInfo.OpenerId,
BrowserContextId = targetInfo.BrowserContextId,
IsAttached = targetInfo.Attached
};
var mapped = new TargetInfo
(
targetId: targetInfo.TargetId,
title: targetInfo.Title,
type: targetInfo.Type,
url: targetInfo.Url,
openerId: targetInfo.OpenerId,
browserContextId: targetInfo.BrowserContextId,
isAttached: targetInfo.Attached
);
targets.Add(mapped);
}

Expand Down Expand Up @@ -124,15 +124,15 @@ private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e)
private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e)
{
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
{
BrowserContextId = e.TargetInfo.BrowserContextId,
IsAttached = e.TargetInfo.Attached,
OpenerId = e.TargetInfo.OpenerId,
TargetId = e.TargetInfo.TargetId,
Title = e.TargetInfo.Title,
Type = e.TargetInfo.Type,
Url = e.TargetInfo.Url
};
(
browserContextId: e.TargetInfo.BrowserContextId,
isAttached: e.TargetInfo.Attached,
openerId: e.TargetInfo.OpenerId,
targetId: e.TargetInfo.TargetId,
title: e.TargetInfo.Title,
type: e.TargetInfo.Type,
url: e.TargetInfo.Url
);

this.OnTargetAttached(new TargetAttachedEventArgs
(
Expand Down

0 comments on commit c54215d

Please sign in to comment.