Skip to content

Commit 2773fe4

Browse files
Merge branch 'trunk' into driver-factory-test
2 parents c321a46 + 445ba70 commit 2773fe4

File tree

16 files changed

+252
-188
lines changed

16 files changed

+252
-188
lines changed

dotnet/src/webdriver/DevTools/JavaScript.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using System;
2121
using System.Threading.Tasks;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium.DevTools
2426
{
2527
/// <summary>
@@ -30,17 +32,17 @@ public abstract class JavaScript
3032
/// <summary>
3133
/// Occurs when a JavaScript script binding is called.
3234
/// </summary>
33-
public event EventHandler<BindingCalledEventArgs> BindingCalled;
35+
public event EventHandler<BindingCalledEventArgs>? BindingCalled;
3436

3537
/// <summary>
3638
/// Occurs when the browser's JavaScript console API is called.
3739
/// </summary>
38-
public event EventHandler<ConsoleApiCalledEventArgs> ConsoleApiCalled;
40+
public event EventHandler<ConsoleApiCalledEventArgs>? ConsoleApiCalled;
3941

4042
/// <summary>
4143
/// Occurs when a JavaScript exception is thrown.
4244
/// </summary>
43-
public event EventHandler<ExceptionThrownEventArgs> ExceptionThrown;
45+
public event EventHandler<ExceptionThrownEventArgs>? ExceptionThrown;
4446

4547
/// <summary>
4648
/// Asynchronously enables the Runtime domain in the DevTools Protocol.

dotnet/src/webdriver/DevTools/Log.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using System;
2121
using System.Threading.Tasks;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium.DevTools
2426
{
2527
/// <summary>
@@ -30,7 +32,7 @@ public abstract class Log
3032
/// <summary>
3133
/// Occurs when an entry is added to the browser's log.
3234
/// </summary>
33-
public event EventHandler<EntryAddedEventArgs> EntryAdded;
35+
public event EventHandler<EntryAddedEventArgs>? EntryAdded;
3436

3537
/// <summary>
3638
/// Asynchronously enables manipulation of the browser's log.

dotnet/src/webdriver/DevTools/Target.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
using System.Collections.ObjectModel;
2222
using System.Threading.Tasks;
2323

24+
#nullable enable
25+
2426
namespace OpenQA.Selenium.DevTools
2527
{
2628
/// <summary>
@@ -31,12 +33,12 @@ public abstract class Target
3133
/// <summary>
3234
/// Occurs when a target is detached.
3335
/// </summary>
34-
public event EventHandler<TargetDetachedEventArgs> TargetDetached;
36+
public event EventHandler<TargetDetachedEventArgs>? TargetDetached;
3537

3638
/// <summary>
3739
/// Occurs when a target is attached.
3840
/// </summary>
39-
public event EventHandler<TargetAttachedEventArgs> TargetAttached;
41+
public event EventHandler<TargetAttachedEventArgs>? TargetAttached;
4042

4143
/// <summary>
4244
/// Asynchronously gets the targets available for this session.
@@ -46,7 +48,7 @@ public abstract class Target
4648
/// contains the list of <see cref="TargetInfo"/> objects describing the
4749
/// targets available for this session.
4850
/// </returns>
49-
public abstract Task<ReadOnlyCollection<TargetInfo>> GetTargets(Object settings = null);
51+
public abstract Task<ReadOnlyCollection<TargetInfo>> GetTargets(object? settings = null);
5052

5153
/// <summary>
5254
/// Asynchronously attaches to a target.
@@ -66,7 +68,7 @@ public abstract class Target
6668
/// <returns>
6769
/// A task representing the asynchronous detach operation.
6870
/// </returns>
69-
public abstract Task DetachFromTarget(string sessionId = null, string targetId = null);
71+
public abstract Task DetachFromTarget(string? sessionId = null, string? targetId = null);
7072

7173
/// <summary>
7274
/// Asynchronously sets the DevTools Protocol connection to automatically attach to new targets.

dotnet/src/webdriver/DevTools/TargetInfo.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,69 @@
1717
// under the License.
1818
// </copyright>
1919

20+
#nullable enable
21+
2022
namespace OpenQA.Selenium.DevTools
2123
{
2224
/// <summary>
2325
/// Represents information about the target of a DevTools Protocol command
2426
/// </summary>
2527
public class TargetInfo
2628
{
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="TargetInfo"/> type.
31+
/// </summary>
32+
/// <param name="targetId">The ID of the target.</param>
33+
/// <param name="type">The type of target.</param>
34+
/// <param name="title">The title of the target.</param>
35+
/// <param name="url">The URL of the target.</param>
36+
/// <param name="isAttached">Whether the protocol is attached to the target.</param>
37+
/// <param name="openerId">The ID of the opener of the target.</param>
38+
/// <param name="browserContextId">The browser context ID.</param>
39+
public TargetInfo(string targetId, string type, string title, string url, bool isAttached, string? openerId, string? browserContextId)
40+
{
41+
this.TargetId = targetId;
42+
this.Type = type;
43+
this.Title = title;
44+
this.Url = url;
45+
this.IsAttached = isAttached;
46+
this.OpenerId = openerId;
47+
this.BrowserContextId = browserContextId;
48+
}
49+
2750
/// <summary>
2851
/// Gets the ID of the target.
2952
/// </summary>
30-
public string TargetId { get; internal set; }
53+
public string TargetId { get; }
3154

3255
/// <summary>
3356
/// Gets the type of target.
3457
/// </summary>
35-
public string Type { get; internal set; }
58+
public string Type { get; }
3659

3760
/// <summary>
3861
/// Gets the title of the target.
3962
/// </summary>
40-
public string Title { get; internal set; }
63+
public string Title { get; }
4164

4265
/// <summary>
4366
/// Gets the URL of the target.
4467
/// </summary>
45-
public string Url { get; internal set; }
68+
public string Url { get; }
4669

4770
/// <summary>
4871
/// Gets a value indicating if the protocol is attached to the target.
4972
/// </summary>
50-
public bool IsAttached { get; internal set; }
73+
public bool IsAttached { get; }
5174

5275
/// <summary>
5376
/// Gets the ID of the opener of the target.
5477
/// </summary>
55-
public string OpenerId { get; internal set; }
78+
public string? OpenerId { get; }
5679

5780
/// <summary>
5881
/// Gets the browser context ID.
5982
/// </summary>
60-
public string BrowserContextId { get; internal set; }
83+
public string? BrowserContextId { get; }
6184
}
6285
}

dotnet/src/webdriver/DevTools/v130/V130JavaScript.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@
2323
using System.Collections.Generic;
2424
using System.Threading.Tasks;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium.DevTools.V130
2729
{
2830
/// <summary>
2931
/// Class containing the JavaScript implementation for version 130 of the DevTools Protocol.
3032
/// </summary>
3133
public class V130JavaScript : JavaScript
3234
{
33-
private RuntimeAdapter runtime;
34-
private PageAdapter page;
35+
private readonly RuntimeAdapter runtime;
36+
private readonly PageAdapter page;
3537

3638
/// <summary>
3739
/// Initializes a new instance of the <see cref="V130JavaScript"/> class.
3840
/// </summary>
3941
/// <param name="runtime">The DevTools Protocol adapter for the Runtime domain.</param>
4042
/// <param name="page">The DevTools Protocol adapter for the Page domain.</param>
43+
/// <exception cref="ArgumentNullException">If <paramref name="runtime"/> or <paramref name="page"/> are <see langword="null"/>.</exception>
4144
public V130JavaScript(RuntimeAdapter runtime, PageAdapter page)
4245
{
43-
this.runtime = runtime;
44-
this.page = page;
46+
this.runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
47+
this.page = page ?? throw new ArgumentNullException(nameof(page));
4548
this.runtime.BindingCalled += OnRuntimeBindingCalled;
4649
this.runtime.ConsoleAPICalled += OnRuntimeConsoleApiCalled;
4750
this.runtime.ExceptionThrown += OnRuntimeExceptionThrown;
@@ -138,7 +141,7 @@ internal override async Task Evaluate(string script)
138141
await runtime.Evaluate(new EvaluateCommandSettings { Expression = script }).ConfigureAwait(false);
139142
}
140143

141-
private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArgs e)
144+
private void OnRuntimeBindingCalled(object? sender, Runtime.BindingCalledEventArgs e)
142145
{
143146
BindingCalledEventArgs wrapped = new BindingCalledEventArgs
144147
(
@@ -150,7 +153,7 @@ private void OnRuntimeBindingCalled(object sender, Runtime.BindingCalledEventArg
150153
this.OnBindingCalled(wrapped);
151154
}
152155

153-
private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEventArgs e)
156+
private void OnRuntimeExceptionThrown(object? sender, Runtime.ExceptionThrownEventArgs e)
154157
{
155158
// TODO: Collect stack trace elements
156159
var wrapped = new ExceptionThrownEventArgs
@@ -162,12 +165,12 @@ private void OnRuntimeExceptionThrown(object sender, Runtime.ExceptionThrownEven
162165
this.OnExceptionThrown(wrapped);
163166
}
164167

165-
private void OnRuntimeConsoleApiCalled(object sender, ConsoleAPICalledEventArgs e)
168+
private void OnRuntimeConsoleApiCalled(object? sender, ConsoleAPICalledEventArgs e)
166169
{
167-
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>();
170+
List<ConsoleApiArgument> args = new List<ConsoleApiArgument>(e.Args.Length);
168171
foreach (var arg in e.Args)
169172
{
170-
string argValue = arg.Value?.ToString();
173+
string? argValue = arg.Value?.ToString();
171174
args.Add(new ConsoleApiArgument(arg.Type.ToString(), argValue));
172175
}
173176

dotnet/src/webdriver/DevTools/v130/V130Log.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,28 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.DevTools.V130.Log;
21+
using System;
2122
using System.Threading.Tasks;
2223

24+
#nullable enable
25+
2326
namespace OpenQA.Selenium.DevTools.V130
2427
{
2528
/// <summary>
2629
/// Class containing the browser's log as referenced by version 130 of the DevTools Protocol.
2730
/// </summary>
2831
public class V130Log : DevTools.Log
2932
{
30-
private LogAdapter adapter;
33+
private readonly LogAdapter adapter;
3134

3235
/// <summary>
3336
/// Initializes a new instance of the <see cref="V130Log"/> class.
3437
/// </summary>
3538
/// <param name="adapter">The adapter for the Log domain.</param>
39+
/// <exception cref="ArgumentNullException">If <paramref name="adapter"/> is <see langword="null"/>.</exception>
3640
public V130Log(LogAdapter adapter)
3741
{
38-
this.adapter = adapter;
42+
this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter));
3943
this.adapter.EntryAdded += OnAdapterEntryAdded;
4044
}
4145

@@ -66,14 +70,14 @@ public override async Task Clear()
6670
await adapter.Clear().ConfigureAwait(false);
6771
}
6872

69-
private void OnAdapterEntryAdded(object sender, Log.EntryAddedEventArgs e)
73+
private void OnAdapterEntryAdded(object? sender, Log.EntryAddedEventArgs e)
7074
{
7175
var entry = new LogEntry(
7276
kind: e.Entry.Source.ToString(),
7377
message: e.Entry.Text
7478
);
75-
EntryAddedEventArgs propagated = new EntryAddedEventArgs(entry);
76-
this.OnEntryAdded(propagated);
79+
80+
this.OnEntryAdded(new EntryAddedEventArgs(entry));
7781
}
7882
}
7983
}

dotnet/src/webdriver/DevTools/v130/V130Target.cs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,25 @@
2323
using System.Collections.ObjectModel;
2424
using System.Threading.Tasks;
2525

26+
#nullable enable
27+
2628
namespace OpenQA.Selenium.DevTools.V130
2729
{
2830
/// <summary>
2931
/// Class providing functionality for manipulating targets for version 130 of the DevTools Protocol
3032
/// </summary>
3133
public class V130Target : DevTools.Target
3234
{
33-
private TargetAdapter adapter;
35+
private readonly TargetAdapter adapter;
3436

3537
/// <summary>
3638
/// Initializes a new instance of the <see cref="V130Target"/> class.
3739
/// </summary>
3840
/// <param name="adapter">The adapter for the Target domain.</param>
41+
/// <exception cref="ArgumentNullException">If <paramref name="adapter"/> is <see langword="null"/>.</exception>
3942
public V130Target(TargetAdapter adapter)
4043
{
41-
this.adapter = adapter;
44+
this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter));
4245
adapter.DetachedFromTarget += OnDetachedFromTarget;
4346
adapter.AttachedToTarget += OnAttachedToTarget;
4447
}
@@ -51,28 +54,26 @@ public V130Target(TargetAdapter adapter)
5154
/// contains the list of <see cref="TargetInfo"/> objects describing the
5255
/// targets available for this session.
5356
/// </returns>
54-
public override async Task<ReadOnlyCollection<TargetInfo>> GetTargets(Object settings = null)
55-
57+
public override async Task<ReadOnlyCollection<TargetInfo>> GetTargets(object? settings = null)
5658
{
57-
List<TargetInfo> targets = new List<TargetInfo>();
58-
if (settings == null)
59-
{
60-
settings = new GetTargetsCommandSettings();
61-
}
59+
settings ??= new GetTargetsCommandSettings();
60+
6261
var response = await adapter.GetTargets((GetTargetsCommandSettings)settings).ConfigureAwait(false);
62+
63+
List<TargetInfo> targets = new List<TargetInfo>(response.TargetInfos.Length);
6364
for (int i = 0; i < response.TargetInfos.Length; i++)
6465
{
6566
var targetInfo = response.TargetInfos[i];
66-
var mapped = new TargetInfo()
67-
{
68-
TargetId = targetInfo.TargetId,
69-
Title = targetInfo.Title,
70-
Type = targetInfo.Type,
71-
Url = targetInfo.Url,
72-
OpenerId = targetInfo.OpenerId,
73-
BrowserContextId = targetInfo.BrowserContextId,
74-
IsAttached = targetInfo.Attached
75-
};
67+
var mapped = new TargetInfo
68+
(
69+
targetId: targetInfo.TargetId,
70+
title: targetInfo.Title,
71+
type: targetInfo.Type,
72+
url: targetInfo.Url,
73+
openerId: targetInfo.OpenerId,
74+
browserContextId: targetInfo.BrowserContextId,
75+
isAttached: targetInfo.Attached
76+
);
7677
targets.Add(mapped);
7778
}
7879

@@ -99,7 +100,7 @@ public override async Task<string> AttachToTarget(string targetId)
99100
/// <param name="sessionId">The ID of the session of the target from which to detach.</param>
100101
/// <param name="targetId">The ID of the target from which to detach.</param>
101102
/// <returns>A task representing the asynchronous detach operation.</returns>
102-
public override async Task DetachFromTarget(string sessionId = null, string targetId = null)
103+
public override async Task DetachFromTarget(string? sessionId = null, string? targetId = null)
103104
{
104105
await adapter.DetachFromTarget(new DetachFromTargetCommandSettings()
105106
{
@@ -117,23 +118,23 @@ public override async Task SetAutoAttach()
117118
await adapter.SetAutoAttach(new SetAutoAttachCommandSettings() { AutoAttach = true, WaitForDebuggerOnStart = false, Flatten = true }).ConfigureAwait(false);
118119
}
119120

120-
private void OnDetachedFromTarget(object sender, DetachedFromTargetEventArgs e)
121+
private void OnDetachedFromTarget(object? sender, DetachedFromTargetEventArgs e)
121122
{
122123
this.OnTargetDetached(new TargetDetachedEventArgs(e.SessionId, e.TargetId));
123124
}
124125

125-
private void OnAttachedToTarget(object sender, AttachedToTargetEventArgs e)
126+
private void OnAttachedToTarget(object? sender, AttachedToTargetEventArgs e)
126127
{
127128
var targetInfo = e.TargetInfo == null ? null : new TargetInfo
128-
{
129-
BrowserContextId = e.TargetInfo.BrowserContextId,
130-
IsAttached = e.TargetInfo.Attached,
131-
OpenerId = e.TargetInfo.OpenerId,
132-
TargetId = e.TargetInfo.TargetId,
133-
Title = e.TargetInfo.Title,
134-
Type = e.TargetInfo.Type,
135-
Url = e.TargetInfo.Url
136-
};
129+
(
130+
browserContextId: e.TargetInfo.BrowserContextId,
131+
isAttached: e.TargetInfo.Attached,
132+
openerId: e.TargetInfo.OpenerId,
133+
targetId: e.TargetInfo.TargetId,
134+
title: e.TargetInfo.Title,
135+
type: e.TargetInfo.Type,
136+
url: e.TargetInfo.Url
137+
);
137138

138139
this.OnTargetAttached(new TargetAttachedEventArgs
139140
(

0 commit comments

Comments
 (0)