Skip to content

Commit cacbf19

Browse files
Merge branch 'trunk' into webelement-nullable-2
2 parents ee43eca + 5d88115 commit cacbf19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+956
-811
lines changed

dotnet/src/support/UI/PopupWindowFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public string Invoke(Action popupMethod)
131131

132132
ReadOnlyCollection<string> existingHandles = this.driver.WindowHandles;
133133
popupMethod();
134-
WebDriverWait wait = new WebDriverWait(new SystemClock(), this.driver, this.timeout, this.sleepInterval);
134+
WebDriverWait wait = new WebDriverWait(SystemClock.Instance, this.driver, this.timeout, this.sleepInterval);
135135
string popupHandle = wait.Until<string>((d) =>
136136
{
137137
string? foundHandle = null;

dotnet/src/support/UI/SlowLoadableComponent{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public abstract class SlowLoadableComponent<T> : LoadableComponent<T>
4343
/// </summary>
4444
/// <param name="timeout">The <see cref="TimeSpan"/> within which the component should be loaded.</param>
4545
protected SlowLoadableComponent(TimeSpan timeout)
46-
: this(timeout, new SystemClock())
46+
: this(timeout, SystemClock.Instance)
4747
{
4848
}
4949

dotnet/src/webdriver/By.cs

Lines changed: 87 additions & 81 deletions
Large diffs are not rendered by default.

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public void SetPermission(string permissionName, string permissionValue)
299299
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
300300
/// </summary>
301301
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
302+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
303+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
302304
public DevToolsSession GetDevToolsSession()
303305
{
304306
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = DevToolsSession.AutoDetectDevToolsProtocolVersion });
@@ -308,6 +310,8 @@ public DevToolsSession GetDevToolsSession()
308310
/// Creates a session to communicate with a browser using the Chromium Developer Tools debugging protocol.
309311
/// </summary>
310312
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
313+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
314+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
311315
public DevToolsSession GetDevToolsSession(DevToolsOptions options)
312316
{
313317
if (this.devToolsSession == null)
@@ -330,7 +334,7 @@ public DevToolsSession GetDevToolsSession(DevToolsOptions options)
330334

331335
try
332336
{
333-
DevToolsSession session = new DevToolsSession(debuggerAddress?.ToString(), options);
337+
DevToolsSession session = new DevToolsSession(debuggerAddress?.ToString()!, options);
334338
Task.Run(async () => await session.StartSession()).GetAwaiter().GetResult();
335339
this.devToolsSession = session;
336340
}
@@ -349,6 +353,8 @@ public DevToolsSession GetDevToolsSession(DevToolsOptions options)
349353
/// <param name="devToolsProtocolVersion">The version of the Chromium Developer Tools protocol to use. Defaults to autodetect the protocol version.</param>
350354
/// <returns>The active session to use to communicate with the Chromium Developer Tools debugging protocol.</returns>
351355
[Obsolete("Use GetDevToolsSession(DevToolsOptions options)")]
356+
[RequiresUnreferencedCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
357+
[RequiresDynamicCode(DevToolsSession.CDP_AOTIncompatibilityMessage)]
352358
public DevToolsSession GetDevToolsSession(int devToolsProtocolVersion)
353359
{
354360
return GetDevToolsSession(new DevToolsOptions() { ProtocolVersion = devToolsProtocolVersion });

dotnet/src/webdriver/Chromium/ChromiumOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ private static void AddAndroidOptions(Dictionary<string, object> chromeOptions,
615615

616616
if (!string.IsNullOrEmpty(androidOptions.AndroidProcess))
617617
{
618-
chromeOptions["androidProcess"] = androidOptions.AndroidProcess;
618+
chromeOptions["androidProcess"] = androidOptions.AndroidProcess!;
619619
}
620620

621621
if (androidOptions.UseRunningApp)

dotnet/src/webdriver/Cookie.cs

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using System.Linq;
2525
using System.Text.Json.Serialization;
2626

27+
#nullable enable
28+
2729
namespace OpenQA.Selenium
2830
{
2931
/// <summary>
@@ -32,15 +34,20 @@ namespace OpenQA.Selenium
3234
[Serializable]
3335
public class Cookie
3436
{
35-
private string cookieName;
36-
private string cookieValue;
37-
private string cookiePath;
38-
private string cookieDomain;
39-
private string sameSite;
40-
private bool isHttpOnly;
41-
private bool secure;
42-
private DateTime? cookieExpiry;
43-
private readonly string[] sameSiteValues = { "Strict", "Lax", "None" };
37+
private readonly string cookieName;
38+
private readonly string cookieValue;
39+
private readonly string? cookiePath;
40+
private readonly string? cookieDomain;
41+
private readonly string? sameSite;
42+
private readonly bool isHttpOnly;
43+
private readonly bool secure;
44+
private readonly DateTime? cookieExpiry;
45+
private readonly HashSet<string?> sameSiteValues = new HashSet<string?>()
46+
{
47+
"Strict",
48+
"Lax",
49+
"None"
50+
};
4451

4552
/// <summary>
4653
/// Initializes a new instance of the <see cref="Cookie"/> class with a specific name and value.
@@ -65,7 +72,7 @@ public Cookie(string name, string value)
6572
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
6673
/// or if it contains a semi-colon.</exception>
6774
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
68-
public Cookie(string name, string value, string path)
75+
public Cookie(string name, string value, string? path)
6976
: this(name, value, path, null)
7077
{
7178
}
@@ -81,7 +88,7 @@ public Cookie(string name, string value, string path)
8188
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
8289
/// or if it contains a semi-colon.</exception>
8390
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
84-
public Cookie(string name, string value, string path, DateTime? expiry)
91+
public Cookie(string name, string value, string? path, DateTime? expiry)
8592
: this(name, value, null, path, expiry)
8693
{
8794
}
@@ -98,7 +105,7 @@ public Cookie(string name, string value, string path, DateTime? expiry)
98105
/// <exception cref="ArgumentException">If the name is <see langword="null"/> or an empty string,
99106
/// or if it contains a semi-colon.</exception>
100107
/// <exception cref="ArgumentNullException">If the value is <see langword="null"/>.</exception>
101-
public Cookie(string name, string value, string domain, string path, DateTime? expiry)
108+
public Cookie(string name, string value, string? domain, string? path, DateTime? expiry)
102109
: this(name, value, domain, path, expiry, false, false, null)
103110
{
104111
}
@@ -118,7 +125,7 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
118125
/// <exception cref="ArgumentException">If the name and value are both an empty string,
119126
/// if the name contains a semi-colon, or if same site value is not valid.</exception>
120127
/// <exception cref="ArgumentNullException">If the name, value or currentUrl is <see langword="null"/>.</exception>
121-
public Cookie(string name, string value, string domain, string path, DateTime? expiry, bool secure, bool isHttpOnly, string sameSite)
128+
public Cookie(string name, string value, string? domain, string? path, DateTime? expiry, bool secure, bool isHttpOnly, string? sameSite)
122129
{
123130
if (name == null)
124131
{
@@ -135,7 +142,7 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
135142
throw new ArgumentException("Cookie name and value cannot both be empty string");
136143
}
137144

138-
if (name.IndexOf(';') != -1)
145+
if (name.Contains(';'))
139146
{
140147
throw new ArgumentException("Cookie names cannot contain a ';': " + name, nameof(name));
141148
}
@@ -172,77 +179,52 @@ public Cookie(string name, string value, string domain, string path, DateTime? e
172179
/// Gets the name of the cookie.
173180
/// </summary>
174181
[JsonPropertyName("name")]
175-
public string Name
176-
{
177-
get { return this.cookieName; }
178-
}
182+
public string Name => this.cookieName;
179183

180184
/// <summary>
181185
/// Gets the value of the cookie.
182186
/// </summary>
183187
[JsonPropertyName("value")]
184-
public string Value
185-
{
186-
get { return this.cookieValue; }
187-
}
188+
public string Value => this.cookieValue;
188189

189190
/// <summary>
190191
/// Gets the domain of the cookie.
191192
/// </summary>
192193
[JsonPropertyName("domain")]
193194
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
194-
public string Domain
195-
{
196-
get { return this.cookieDomain; }
197-
}
195+
public string? Domain => this.cookieDomain;
198196

199197
/// <summary>
200198
/// Gets the path of the cookie.
201199
/// </summary>
202200
[JsonPropertyName("path")]
203201
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
204-
public virtual string Path
205-
{
206-
get { return this.cookiePath; }
207-
}
202+
public virtual string? Path => this.cookiePath;
208203

209204
/// <summary>
210205
/// Gets a value indicating whether the cookie is secure.
211206
/// </summary>
212207
[JsonPropertyName("secure")]
213-
public virtual bool Secure
214-
{
215-
get { return this.secure; }
216-
}
208+
public virtual bool Secure => this.secure;
217209

218210
/// <summary>
219211
/// Gets a value indicating whether the cookie is an HTTP-only cookie.
220212
/// </summary>
221213
[JsonPropertyName("httpOnly")]
222-
public virtual bool IsHttpOnly
223-
{
224-
get { return this.isHttpOnly; }
225-
226-
}
214+
public virtual bool IsHttpOnly => this.isHttpOnly;
227215

228216
/// <summary>
229217
/// Gets the SameSite setting for the cookie.
230218
/// </summary>
231219
[JsonPropertyName("sameSite")]
232220
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
233-
public virtual string SameSite
234-
{
235-
get { return this.sameSite; }
236-
}
221+
public virtual string? SameSite => this.sameSite;
237222

238223
/// <summary>
239224
/// Gets the expiration date of the cookie.
240225
/// </summary>
241226
[JsonIgnore]
242-
public DateTime? Expiry
243-
{
244-
get { return this.cookieExpiry; }
245-
}
227+
public DateTime? Expiry => this.cookieExpiry;
246228

247229
/// <summary>
248230
/// Gets the cookie expiration date in seconds from the defined zero date (01 January 1970 00:00:00 UTC).
@@ -273,54 +255,54 @@ internal long? ExpirySeconds
273255
/// </summary>
274256
/// <param name="rawCookie">The Dictionary object containing the cookie parameters.</param>
275257
/// <returns>A <see cref="Cookie"/> object with the proper parameters set.</returns>
276-
public static Cookie FromDictionary(Dictionary<string, object> rawCookie)
258+
public static Cookie FromDictionary(Dictionary<string, object?> rawCookie)
277259
{
278260
if (rawCookie == null)
279261
{
280262
throw new ArgumentNullException(nameof(rawCookie));
281263
}
282264

283-
string name = rawCookie["name"].ToString();
265+
string name = rawCookie["name"]!.ToString()!;
284266
string value = string.Empty;
285-
if (rawCookie["value"] != null)
267+
if (rawCookie.TryGetValue("value", out object? valueObj))
286268
{
287-
value = rawCookie["value"].ToString();
269+
value = valueObj!.ToString()!;
288270
}
289271

290272
string path = "/";
291-
if (rawCookie.ContainsKey("path") && rawCookie["path"] != null)
273+
if (rawCookie.TryGetValue("path", out object? pathObj) && pathObj != null)
292274
{
293-
path = rawCookie["path"].ToString();
275+
path = pathObj.ToString()!;
294276
}
295277

296278
string domain = string.Empty;
297-
if (rawCookie.ContainsKey("domain") && rawCookie["domain"] != null)
279+
if (rawCookie.TryGetValue("domain", out object? domainObj) && domainObj != null)
298280
{
299-
domain = rawCookie["domain"].ToString();
281+
domain = domainObj.ToString()!;
300282
}
301283

302284
DateTime? expires = null;
303-
if (rawCookie.ContainsKey("expiry") && rawCookie["expiry"] != null)
285+
if (rawCookie.TryGetValue("expiry", out object? expiryObj) && expiryObj != null)
304286
{
305-
expires = ConvertExpirationTime(rawCookie["expiry"].ToString());
287+
expires = ConvertExpirationTime(expiryObj.ToString()!);
306288
}
307289

308290
bool secure = false;
309-
if (rawCookie.ContainsKey("secure") && rawCookie["secure"] != null)
291+
if (rawCookie.TryGetValue("secure", out object? secureObj) && secureObj != null)
310292
{
311-
secure = bool.Parse(rawCookie["secure"].ToString());
293+
secure = bool.Parse(secureObj.ToString()!);
312294
}
313295

314296
bool isHttpOnly = false;
315-
if (rawCookie.ContainsKey("httpOnly") && rawCookie["httpOnly"] != null)
297+
if (rawCookie.TryGetValue("httpOnly", out object? httpOnlyObj) && httpOnlyObj != null)
316298
{
317-
isHttpOnly = bool.Parse(rawCookie["httpOnly"].ToString());
299+
isHttpOnly = bool.Parse(httpOnlyObj.ToString()!);
318300
}
319301

320-
string sameSite = null;
321-
if (rawCookie.ContainsKey("sameSite") && rawCookie["sameSite"] != null)
302+
string? sameSite = null;
303+
if (rawCookie.TryGetValue("sameSite", out object? sameSiteObj))
322304
{
323-
sameSite = rawCookie["sameSite"].ToString();
305+
sameSite = sameSiteObj?.ToString();
324306
}
325307

326308
return new ReturnedCookie(name, value, domain, path, expires, secure, isHttpOnly, sameSite);
@@ -348,7 +330,7 @@ public override string ToString()
348330
/// <returns><see langword="true"/> if the specified <see cref="object">Object</see>
349331
/// is equal to the current <see cref="object">Object</see>; otherwise,
350332
/// <see langword="false"/>.</returns>
351-
public override bool Equals(object obj)
333+
public override bool Equals(object? obj)
352334
{
353335
// Two cookies are equal if the name and value match
354336
if (this == obj)
@@ -378,16 +360,15 @@ public override int GetHashCode()
378360
return this.cookieName.GetHashCode();
379361
}
380362

381-
private static string StripPort(string domain)
363+
private static string? StripPort(string? domain)
382364
{
383-
return string.IsNullOrEmpty(domain) ? null : domain.Split(':')[0];
365+
return string.IsNullOrEmpty(domain) ? null : domain!.Split(':')[0];
384366
}
385367

386368
private static DateTime? ConvertExpirationTime(string expirationTime)
387369
{
388370
DateTime? expires = null;
389-
double seconds = 0;
390-
if (double.TryParse(expirationTime, NumberStyles.Number, CultureInfo.InvariantCulture, out seconds))
371+
if (double.TryParse(expirationTime, NumberStyles.Number, CultureInfo.InvariantCulture, out double seconds))
391372
{
392373
try
393374
{

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.Internal.Logging;
2121
using System;
2222
using System.Collections.Concurrent;
23+
using System.Diagnostics.CodeAnalysis;
2324
using System.Globalization;
2425
using System.Net.Http;
2526
using System.Text.Json;
@@ -35,8 +36,12 @@ namespace OpenQA.Selenium.DevTools
3536
/// Represents a WebSocket connection to a running DevTools instance that can be used to send
3637
/// commands and receive events.
3738
///</summary>
39+
[RequiresUnreferencedCode(CDP_AOTIncompatibilityMessage)]
40+
[RequiresDynamicCode(CDP_AOTIncompatibilityMessage)]
3841
public class DevToolsSession : IDevToolsSession
3942
{
43+
internal const string CDP_AOTIncompatibilityMessage = "CDP is not compatible with trimming or AOT.";
44+
4045
/// <summary>
4146
/// A value indicating that the version of the DevTools protocol in use
4247
/// by the browser should be automatically detected.
@@ -496,7 +501,7 @@ private async Task InitializeSocketConnection()
496501
LogTrace("Creating WebSocket");
497502
this.connection = new WebSocketConnection(this.openConnectionWaitTimeSpan, this.closeConnectionWaitTimeSpan);
498503
connection.DataReceived += OnConnectionDataReceived;
499-
await connection.Start(this.EndpointAddress).ConfigureAwait(false);
504+
await connection.Start(this.EndpointAddress!).ConfigureAwait(false);
500505
LogTrace("WebSocket created");
501506
}
502507

0 commit comments

Comments
 (0)