Skip to content

Commit e8134d0

Browse files
authored
Merge branch 'trunk' into renovate/firefox_standalone
2 parents ddab1d9 + cc5ca35 commit e8134d0

33 files changed

+115
-73
lines changed

dotnet/src/webdriver/SessionId.cs

+12-14
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium
2125
{
2226
/// <summary>
2327
/// Provides a mechanism for maintaining a session for a test
2428
/// </summary>
2529
public class SessionId
2630
{
27-
private string sessionOpaqueKey;
31+
private readonly string sessionOpaqueKey;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the <see cref="SessionId"/> class
3135
/// </summary>
3236
/// <param name="opaqueKey">Key for the session in use</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="opaqueKey"/> is <see langword="null"/>.</exception>
3338
public SessionId(string opaqueKey)
3439
{
35-
this.sessionOpaqueKey = opaqueKey;
40+
this.sessionOpaqueKey = opaqueKey ?? throw new ArgumentNullException(nameof(opaqueKey));
3641
}
3742

3843
/// <summary>
@@ -54,20 +59,13 @@ public override int GetHashCode()
5459
}
5560

5661
/// <summary>
57-
/// Compares two Sessions
62+
/// Indicates whether the current session ID value is the same as <paramref name="obj"/>.
5863
/// </summary>
59-
/// <param name="obj">Session to compare</param>
60-
/// <returns>True if they are equal or False if they are not</returns>
61-
public override bool Equals(object obj)
64+
/// <param name="obj">The session to compare to.</param>
65+
/// <returns><see langword="true"/> if the values are equal; otherwise, <see langword="false"/>.</returns>
66+
public override bool Equals(object? obj)
6267
{
63-
bool objectsAreEqual = false;
64-
SessionId other = obj as SessionId;
65-
if (other != null)
66-
{
67-
objectsAreEqual = this.sessionOpaqueKey.Equals(other.sessionOpaqueKey);
68-
}
69-
70-
return objectsAreEqual;
68+
return obj is SessionId otherSession && this.sessionOpaqueKey.Equals(otherSession.sessionOpaqueKey);
7169
}
7270
}
7371
}

dotnet/src/webdriver/WebDriver.cs

+10-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Collections;
2525
using System.Collections.Generic;
2626
using System.Collections.ObjectModel;
27+
using System.Diagnostics.CodeAnalysis;
2728
using System.Globalization;
2829
using System.Threading.Tasks;
2930

@@ -44,7 +45,7 @@ public class WebDriver : IWebDriver, ISearchContext, IJavaScriptExecutor, IFinds
4445
private IFileDetector fileDetector = new DefaultFileDetector();
4546
private NetworkManager network;
4647
private WebElementFactory elementFactory;
47-
private SessionId sessionId;
48+
4849
private List<string> registeredCommands = new List<string>();
4950

5051
/// <summary>
@@ -191,10 +192,7 @@ public bool IsActionExecutor
191192
/// <summary>
192193
/// Gets the <see cref="SessionId"/> for the current session of this driver.
193194
/// </summary>
194-
public SessionId SessionId
195-
{
196-
get { return this.sessionId; }
197-
}
195+
public SessionId SessionId { get; private set; }
198196

199197
/// <summary>
200198
/// Gets or sets the <see cref="IFileDetector"/> responsible for detecting
@@ -612,7 +610,7 @@ protected virtual Response Execute(string driverCommandToExecute,
612610
/// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
613611
protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecute, Dictionary<string, object> parameters)
614612
{
615-
Command commandToExecute = new Command(this.sessionId, driverCommandToExecute, parameters);
613+
Command commandToExecute = new Command(SessionId, driverCommandToExecute, parameters);
616614

617615
Response commandResponse;
618616

@@ -641,6 +639,7 @@ protected virtual async Task<Response> ExecuteAsync(string driverCommandToExecut
641639
/// Starts a session with the driver
642640
/// </summary>
643641
/// <param name="capabilities">Capabilities of the browser</param>
642+
[MemberNotNull(nameof(SessionId))]
644643
protected void StartSession(ICapabilities capabilities)
645644
{
646645
Dictionary<string, object> parameters = new Dictionary<string, object>();
@@ -679,7 +678,9 @@ protected void StartSession(ICapabilities capabilities)
679678

680679
ReturnedCapabilities returnedCapabilities = new ReturnedCapabilities(rawCapabilities);
681680
this.capabilities = returnedCapabilities;
682-
this.sessionId = new SessionId(response.SessionId);
681+
682+
string sessionId = response.SessionId ?? throw new WebDriverException($"The remote end did not respond with ID of a session when it was required. {response.Value}");
683+
this.SessionId = new SessionId(sessionId);
683684
}
684685

685686
/// <summary>
@@ -723,7 +724,7 @@ protected virtual void Dispose(bool disposing)
723724
{
724725
try
725726
{
726-
if (this.sessionId is not null)
727+
if (this.SessionId is not null)
727728
{
728729
this.Execute(DriverCommand.Quit, null);
729730
}
@@ -739,7 +740,7 @@ protected virtual void Dispose(bool disposing)
739740
}
740741
finally
741742
{
742-
this.sessionId = null;
743+
this.SessionId = null;
743744
}
744745
this.executor.Dispose();
745746
}

dotnet/test/common/DevTools/DevToolsProfilerTest.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ private void ValidateProfile(CurrentCdpVersion.Profiler.Profile profiler)
131131
{
132132
Assert.That(profiler, Is.Not.Null);
133133
Assert.That(profiler.Nodes, Is.Not.Null);
134-
Assert.That(profiler.StartTime, Is.Not.Null);
135-
Assert.That(profiler.EndTime, Is.Not.Null);
134+
Assert.That(profiler.StartTime, Is.Not.Zero);
135+
Assert.That(profiler.EndTime, Is.Not.Zero);
136136
Assert.That(profiler.TimeDeltas, Is.Not.Null);
137137
foreach (var delta in profiler.TimeDeltas)
138138
{
139-
Assert.That(delta, Is.Not.Null);
139+
Assert.That(delta, Is.Not.Zero);
140140
}
141141

142142
foreach (var node in profiler.Nodes)

dotnet/test/common/DevTools/DevToolsTestFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void Setup()
3939
devTools = driver as IDevTools;
4040
if (devTools == null)
4141
{
42-
Assert.Ignore("{0} does not support Chrome DevTools Protocol", EnvironmentManager.Instance.Browser);
42+
Assert.Ignore($"{EnvironmentManager.Instance.Browser} does not support Chrome DevTools Protocol");
4343
return;
4444
}
4545

java/src/org/openqa/selenium/Architecture.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.openqa.selenium;
1919

20+
import java.util.Locale;
21+
2022
/**
2123
* Represents the known architectures used in WebDriver. It attempts to smooth over some of Java's
2224
* rough edges when dealing with microprocessor architectures by, for instance, allowing you to
@@ -98,7 +100,7 @@ public int getDataModel() {
98100

99101
@Override
100102
public String toString() {
101-
return name().toLowerCase();
103+
return name().toLowerCase(Locale.ENGLISH);
102104
}
103105

104106
/**
@@ -121,7 +123,7 @@ public static Architecture getCurrent() {
121123
*/
122124
public static Architecture extractFromSysProperty(String arch) {
123125
if (arch != null) {
124-
arch = arch.toLowerCase();
126+
arch = arch.toLowerCase(Locale.ENGLISH);
125127
}
126128

127129
// Some architectures are basically the same even though they have different names. ia32, x86,

java/src/org/openqa/selenium/Platform.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium;
1919

2020
import java.util.Arrays;
21+
import java.util.Locale;
2122
import java.util.regex.Matcher;
2223
import java.util.regex.Pattern;
2324

@@ -414,7 +415,7 @@ public static Platform extractFromSysProperty(String osName) {
414415
* @return the most likely platform based on given operating system name and version
415416
*/
416417
public static Platform extractFromSysProperty(String osName, String osVersion) {
417-
osName = osName.toLowerCase();
418+
osName = osName.toLowerCase(Locale.ENGLISH);
418419
// os.name for android is linux
419420
if ("dalvik".equalsIgnoreCase(System.getProperty("java.vm.name"))) {
420421
return Platform.ANDROID;
@@ -434,7 +435,7 @@ public static Platform extractFromSysProperty(String osName, String osVersion) {
434435
if ("".equals(matcher)) {
435436
continue;
436437
}
437-
matcher = matcher.toLowerCase();
438+
matcher = matcher.toLowerCase(Locale.ENGLISH);
438439
if (os.isExactMatch(osName, matcher)) {
439440
return os;
440441
}

java/src/org/openqa/selenium/Proxy.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Arrays;
2121
import java.util.HashMap;
2222
import java.util.List;
23+
import java.util.Locale;
2324
import java.util.Map;
2425
import java.util.Objects;
2526
import java.util.Optional;
@@ -93,7 +94,8 @@ public Proxy() {
9394
public Proxy(Map<String, ?> raw) {
9495
Map<String, Consumer<Object>> setters = new HashMap<>();
9596
setters.put(
96-
PROXY_TYPE, value -> setProxyType(ProxyType.valueOf(((String) value).toUpperCase())));
97+
PROXY_TYPE,
98+
value -> setProxyType(ProxyType.valueOf(((String) value).toUpperCase(Locale.ENGLISH))));
9799
setters.put(FTP_PROXY, value -> setFtpProxy((String) value));
98100
setters.put(HTTP_PROXY, value -> setHttpProxy((String) value));
99101
setters.put(
@@ -448,7 +450,7 @@ public String toString() {
448450
case DIRECT:
449451
case MANUAL:
450452
case SYSTEM:
451-
builder.append(getProxyType().toString().toLowerCase());
453+
builder.append(getProxyType().toString().toLowerCase(Locale.ENGLISH));
452454
break;
453455

454456
case PAC:

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.ArrayList;
3030
import java.util.HashMap;
3131
import java.util.List;
32+
import java.util.Locale;
3233
import java.util.Map;
3334
import org.openqa.selenium.Capabilities;
3435
import org.openqa.selenium.WebDriverException;
@@ -300,7 +301,7 @@ protected List<String> createArgs() {
300301
}
301302

302303
if (logLevel != null) {
303-
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase()));
304+
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase(Locale.ENGLISH)));
304305
}
305306
if (allowedListIps != null) {
306307
args.add(String.format("--allowed-ips=%s", allowedListIps));

java/src/org/openqa/selenium/chromium/ChromiumDriverLogLevel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.chromium;
1919

20+
import java.util.Locale;
2021
import java.util.Map;
2122
import java.util.logging.Level;
2223

@@ -46,7 +47,7 @@ public enum ChromiumDriverLogLevel {
4647

4748
@Override
4849
public String toString() {
49-
return super.toString().toLowerCase();
50+
return super.toString().toLowerCase(Locale.ENGLISH);
5051
}
5152

5253
public static ChromiumDriverLogLevel fromString(String text) {

java/src/org/openqa/selenium/devtools/NetworkInterceptor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.openqa.selenium.remote.http.Contents.utf8String;
2121

22+
import java.util.Locale;
2223
import java.util.Map;
2324
import java.util.Optional;
2425
import org.openqa.selenium.WebDriver;
@@ -105,7 +106,7 @@ public void close() {
105106
protected HttpMethod convertFromCdpHttpMethod(String method) {
106107
Require.nonNull("HTTP Method", method);
107108
try {
108-
return HttpMethod.valueOf(method.toUpperCase());
109+
return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH));
109110
} catch (IllegalArgumentException e) {
110111
// Spam in a reasonable value
111112
return HttpMethod.GET;

java/src/org/openqa/selenium/devtools/idealized/Network.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Base64;
2727
import java.util.LinkedHashMap;
2828
import java.util.List;
29+
import java.util.Locale;
2930
import java.util.Map;
3031
import java.util.Optional;
3132
import java.util.concurrent.CancellationException;
@@ -300,7 +301,7 @@ protected Optional<Credentials> getAuthCredentials(URI uri) {
300301
protected HttpMethod convertFromCdpHttpMethod(String method) {
301302
Require.nonNull("HTTP Method", method);
302303
try {
303-
return HttpMethod.valueOf(method.toUpperCase());
304+
return HttpMethod.valueOf(method.toUpperCase(Locale.ENGLISH));
304305
} catch (IllegalArgumentException e) {
305306
// Spam in a reasonable value
306307
return HttpMethod.GET;

java/src/org/openqa/selenium/edge/EdgeDriverService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.Duration;
2828
import java.util.ArrayList;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.Map;
3132
import org.openqa.selenium.Capabilities;
3233
import org.openqa.selenium.WebDriverException;
@@ -294,7 +295,7 @@ protected List<String> createArgs() {
294295
}
295296

296297
if (logLevel != null) {
297-
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase()));
298+
args.add(String.format("--log-level=%s", logLevel.toString().toUpperCase(Locale.ENGLISH)));
298299
}
299300
if (Boolean.TRUE.equals(silent)) {
300301
args.add("--silent");

java/src/org/openqa/selenium/firefox/FirefoxBinary.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.ArrayList;
3131
import java.util.Collections;
3232
import java.util.List;
33+
import java.util.Locale;
3334
import java.util.Map;
3435
import java.util.Optional;
3536
import java.util.stream.Collectors;
@@ -72,7 +73,7 @@ public String toString() {
7273
* @return the Channel enum value matching the parameter
7374
*/
7475
public static Channel fromString(String name) {
75-
final String lcName = name.toLowerCase();
76+
final String lcName = name.toLowerCase(Locale.ENGLISH);
7677
return stream(Channel.values())
7778
.filter(ch -> ch.name.equals(lcName))
7879
.findFirst()

java/src/org/openqa/selenium/firefox/FirefoxDriverLogLevel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.firefox;
1919

2020
import java.util.Collections;
21+
import java.util.Locale;
2122
import java.util.Map;
2223
import java.util.logging.Level;
2324

@@ -47,7 +48,7 @@ public enum FirefoxDriverLogLevel {
4748

4849
@Override
4950
public String toString() {
50-
return super.toString().toLowerCase();
51+
return super.toString().toLowerCase(Locale.ENGLISH);
5152
}
5253

5354
public static FirefoxDriverLogLevel fromString(String text) {

java/src/org/openqa/selenium/grid/config/DescribedOption.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Collection;
3333
import java.util.HashSet;
3434
import java.util.List;
35+
import java.util.Locale;
3536
import java.util.Objects;
3637
import java.util.Optional;
3738
import java.util.ServiceLoader;
@@ -194,7 +195,7 @@ public int hashCode() {
194195
}
195196

196197
public String getType(Type type) {
197-
String className = deriveClass(type).getSimpleName().toLowerCase();
198+
String className = deriveClass(type).getSimpleName().toLowerCase(Locale.ENGLISH);
198199

199200
return isCollection(type) ? "list of " + className + "s" : className;
200201
}

java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.google.common.annotations.VisibleForTesting;
2323
import java.util.Comparator;
24+
import java.util.Locale;
2425
import java.util.Set;
2526
import org.openqa.selenium.Capabilities;
2627
import org.openqa.selenium.grid.config.Config;
@@ -67,7 +68,7 @@ public Set<SlotId> selectSlot(
6768
@VisibleForTesting
6869
long getNumberOfSupportedBrowsers(NodeStatus nodeStatus) {
6970
return nodeStatus.getSlots().stream()
70-
.map(slot -> slot.getStereotype().getBrowserName().toLowerCase())
71+
.map(slot -> slot.getStereotype().getBrowserName().toLowerCase(Locale.ENGLISH))
7172
.distinct()
7273
.count();
7374
}

0 commit comments

Comments
 (0)