Skip to content

Commit d743665

Browse files
authored
Merge branch 'trunk' into add-jspecify-annotations-by
2 parents 4233ec5 + 1c23e13 commit d743665

File tree

5 files changed

+74
-104
lines changed

5 files changed

+74
-104
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ bazel_dep(name = "protobuf", version = "21.7", dev_dependency = True, repo_name
1717
# Required for rules_rust to import the crates properly
1818
bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True)
1919

20-
bazel_dep(name = "rules_dotnet", version = "0.16.0")
20+
bazel_dep(name = "rules_dotnet", version = "0.16.1")
2121
bazel_dep(name = "rules_java", version = "7.11.1")
2222
bazel_dep(name = "rules_jvm_external", version = "6.3")
2323
bazel_dep(name = "rules_nodejs", version = "6.3.0")

dotnet/src/webdriver/DriverOptions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Globalization;
25-
using System.Text.Json;
2625

2726
namespace OpenQA.Selenium
2827
{
@@ -390,15 +389,6 @@ public void SetLoggingPreference(string logType, LogLevel logLevel)
390389
this.loggingPreferences[logType] = logLevel;
391390
}
392391

393-
/// <summary>
394-
/// Returns a string representation of this <see cref="DriverOptions"/>.
395-
/// </summary>
396-
/// <returns>A string representation of this <see cref="DriverOptions"/>.</returns>
397-
public override string ToString()
398-
{
399-
return JsonSerializer.Serialize(this.ToDictionary(), new JsonSerializerOptions { WriteIndented = true });
400-
}
401-
402392
/// <summary>
403393
/// Returns the current options as a <see cref="Dictionary{TKey, TValue}"/>.
404394
/// </summary>

dotnet/src/webdriver/Internal/ReturnedCapabilities.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using System.Collections.Generic;
2222
using System.Collections.ObjectModel;
2323
using System.Globalization;
24-
using System.Text.Json;
2524

2625
namespace OpenQA.Selenium.Internal
2726
{
@@ -147,14 +146,5 @@ public Dictionary<string, object> ToDictionary()
147146
// we might want to copy/clone it instead.
148147
return this.capabilities;
149148
}
150-
151-
/// <summary>
152-
/// Return a string of capabilities being used
153-
/// </summary>
154-
/// <returns>String of capabilities being used</returns>
155-
public override string ToString()
156-
{
157-
return JsonSerializer.Serialize(this.capabilities, new JsonSerializerOptions { WriteIndented = true });
158-
}
159149
}
160150
}

dotnet/src/webdriver/Remote/RemoteSessionSettings.cs

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
using OpenQA.Selenium.Remote;
2121
using System;
22-
using System.Collections;
2322
using System.Collections.Generic;
2423
using System.Globalization;
25-
using System.Text.Json;
2624

2725
namespace OpenQA.Selenium
2826
{
@@ -71,18 +69,12 @@ public RemoteSessionSettings(DriverOptions mustMatchDriverOptions, params Driver
7169
/// <summary>
7270
/// Gets a value indicating the options that must be matched by the remote end to create a session.
7371
/// </summary>
74-
internal DriverOptions MustMatchDriverOptions
75-
{
76-
get { return this.mustMatchDriverOptions; }
77-
}
72+
internal DriverOptions MustMatchDriverOptions => this.mustMatchDriverOptions;
7873

7974
/// <summary>
8075
/// Gets a value indicating the number of options that may be matched by the remote end to create a session.
8176
/// </summary>
82-
internal int FirstMatchOptionsCount
83-
{
84-
get { return this.firstMatchOptions.Count; }
85-
}
77+
internal int FirstMatchOptionsCount => this.firstMatchOptions.Count;
8678

8779
/// <summary>
8880
/// Gets the capability value with the specified name.
@@ -92,6 +84,7 @@ internal int FirstMatchOptionsCount
9284
/// <exception cref="ArgumentException">
9385
/// The specified capability name is not in the set of capabilities.
9486
/// </exception>
87+
/// <exception cref="ArgumentNullException">If <paramref name="capabilityName"/> is null.</exception>
9588
public object this[string capabilityName]
9689
{
9790
get
@@ -121,18 +114,10 @@ public object this[string capabilityName]
121114
/// </summary>
122115
/// <param name="settingName">The name of the setting to set.</param>
123116
/// <param name="settingValue">The value of the setting.</param>
124-
/// <remarks>
125-
/// The value to be set must be serializable to JSON for transmission
126-
/// across the wire to the remote end. To be JSON-serializable, the value
127-
/// must be a string, a numeric value, a boolean value, an object that
128-
/// implmeents <see cref="IEnumerable"/> that contains JSON-serializable
129-
/// objects, or a <see cref="Dictionary{TKey, TValue}"/> where the keys
130-
/// are strings and the values are JSON-serializable.
131-
/// </remarks>
132117
/// <exception cref="ArgumentException">
133-
/// Thrown if the setting name is null, the empty string, or one of the
134-
/// reserved names of metadata settings; or if the setting value is not
135-
/// JSON serializable.
118+
/// <para>If the setting name is null or empty.</para>
119+
/// <para>-or-</para>
120+
/// <para>If one of the reserved names of metadata settings.</para>
136121
/// </exception>
137122
public void AddMetadataSetting(string settingName, object settingValue)
138123
{
@@ -146,11 +131,6 @@ public void AddMetadataSetting(string settingName, object settingValue)
146131
throw new ArgumentException(string.Format("'{0}' is a reserved name for a metadata setting, and cannot be used as a name.", settingName), nameof(settingName));
147132
}
148133

149-
if (!this.IsJsonSerializable(settingValue))
150-
{
151-
throw new ArgumentException("Metadata setting value must be JSON serializable.", nameof(settingValue));
152-
}
153-
154134
this.remoteMetadataSettings[settingName] = settingValue;
155135
}
156136

@@ -161,9 +141,9 @@ public void AddMetadataSetting(string settingName, object settingValue)
161141
/// <param name="options">The <see cref="DriverOptions"/> to add to the list of "first matched" options.</param>
162142
public void AddFirstMatchDriverOption(DriverOptions options)
163143
{
164-
if (mustMatchDriverOptions != null)
144+
if (this.mustMatchDriverOptions != null)
165145
{
166-
DriverOptionsMergeResult mergeResult = mustMatchDriverOptions.GetMergeResult(options);
146+
DriverOptionsMergeResult mergeResult = this.mustMatchDriverOptions.GetMergeResult(options);
167147
if (mergeResult.IsMergeConflict)
168148
{
169149
string msg = string.Format(CultureInfo.InvariantCulture, "You cannot request the same capability in both must-match and first-match capabilities. You are attempting to add a first-match driver options object that defines a capability, '{0}', that is already defined in the must-match driver options.", mergeResult.MergeConflictOptionName);
@@ -271,15 +251,6 @@ public Dictionary<string, object> ToDictionary()
271251
return capabilitiesDictionary;
272252
}
273253

274-
/// <summary>
275-
/// Return a string representation of the remote session settings to be sent.
276-
/// </summary>
277-
/// <returns>String representation of the remote session settings to be sent.</returns>
278-
public override string ToString()
279-
{
280-
return JsonSerializer.Serialize(this.ToDictionary(), new JsonSerializerOptions { WriteIndented = true });
281-
}
282-
283254
internal DriverOptions GetFirstMatchDriverOptions(int firstMatchIndex)
284255
{
285256
if (firstMatchIndex < 0 || firstMatchIndex >= this.firstMatchOptions.Count)
@@ -297,58 +268,13 @@ private IDictionary<string, object> GetAlwaysMatchOptionsAsSerializableDictionar
297268

298269
private List<object> GetFirstMatchOptionsAsSerializableList()
299270
{
300-
List<object> optionsMatches = new List<object>();
271+
List<object> optionsMatches = new List<object>(this.firstMatchOptions.Count);
301272
foreach (DriverOptions options in this.firstMatchOptions)
302273
{
303274
optionsMatches.Add(options.ToDictionary());
304275
}
305276

306277
return optionsMatches;
307278
}
308-
309-
private bool IsJsonSerializable(object arg)
310-
{
311-
IEnumerable argAsEnumerable = arg as IEnumerable;
312-
IDictionary argAsDictionary = arg as IDictionary;
313-
314-
if (arg is string || arg is float || arg is double || arg is int || arg is long || arg is bool || arg == null)
315-
{
316-
return true;
317-
}
318-
else if (argAsDictionary != null)
319-
{
320-
foreach (object key in argAsDictionary.Keys)
321-
{
322-
if (!(key is string))
323-
{
324-
return false;
325-
}
326-
}
327-
328-
foreach (object value in argAsDictionary.Values)
329-
{
330-
if (!IsJsonSerializable(value))
331-
{
332-
return false;
333-
}
334-
}
335-
}
336-
else if (argAsEnumerable != null)
337-
{
338-
foreach (object item in argAsEnumerable)
339-
{
340-
if (!IsJsonSerializable(item))
341-
{
342-
return false;
343-
}
344-
}
345-
}
346-
else
347-
{
348-
return false;
349-
}
350-
351-
return true;
352-
}
353279
}
354280
}

dotnet/test/remote/RemoteSessionCreationTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// </copyright>
1919

2020
using NUnit.Framework;
21+
using System.Collections.Generic;
22+
using System.Text.Json;
23+
using System.Text.Json.Nodes;
2124

2225
namespace OpenQA.Selenium.Remote
2326
{
@@ -68,5 +71,66 @@ public void CreateEdgeRemoteSession()
6871
edge.Quit();
6972
}
7073
}
74+
75+
[Test]
76+
public void ShouldSetRemoteSessionSettingsMetadata()
77+
{
78+
var settings = new RemoteSessionSettings();
79+
80+
Assert.That(settings.HasCapability("a"), Is.False);
81+
82+
settings.AddMetadataSetting("a", null);
83+
Assert.That(settings.HasCapability("a"));
84+
Assert.That(settings.GetCapability("a"), Is.Null);
85+
86+
settings.AddMetadataSetting("a", true);
87+
Assert.That(settings.HasCapability("a"));
88+
Assert.That(settings.GetCapability("a"), Is.True);
89+
90+
settings.AddMetadataSetting("a", false);
91+
Assert.That(settings.HasCapability("a"));
92+
Assert.That(settings.GetCapability("a"), Is.False);
93+
94+
settings.AddMetadataSetting("a", 123);
95+
Assert.That(settings.HasCapability("a"));
96+
Assert.That(settings.GetCapability("a"), Is.TypeOf<int>().And.EqualTo(123));
97+
98+
settings.AddMetadataSetting("a", 123f);
99+
Assert.That(settings.HasCapability("a"));
100+
Assert.That(settings.GetCapability("a"), Is.TypeOf<float>().And.EqualTo(123f));
101+
102+
settings.AddMetadataSetting("a", 123d);
103+
Assert.That(settings.HasCapability("a"));
104+
Assert.That(settings.GetCapability("a"), Is.TypeOf<double>().And.EqualTo(123d));
105+
106+
JsonNode trueName = JsonValue.Create(true);
107+
settings.AddMetadataSetting("a", trueName);
108+
Assert.That(settings.HasCapability("a"));
109+
Assert.That(settings.GetCapability("a"), Is.InstanceOf<JsonNode>().And.EqualTo(trueName).Using<JsonNode>(JsonNode.DeepEquals));
110+
111+
var reader = new Utf8JsonReader("false"u8);
112+
JsonElement trueElement = JsonElement.ParseValue(ref reader);
113+
114+
settings.AddMetadataSetting("a", trueElement);
115+
Assert.That(settings.HasCapability("a"));
116+
Assert.That(settings.GetCapability("a"), Is.TypeOf<JsonElement>().And.Matches<JsonElement>(static left =>
117+
{
118+
return left.ValueKind == JsonValueKind.False;
119+
}));
120+
121+
List<int> intValues = [1, 2, 3];
122+
settings.AddMetadataSetting("a", intValues);
123+
Assert.That(settings.HasCapability("a"));
124+
Assert.That(settings.GetCapability("a"), Is.TypeOf<List<int>>().And.EqualTo(intValues));
125+
126+
Dictionary<string, int> dictionaryValues = new Dictionary<string, int>
127+
{
128+
{"value1", 1 },
129+
{"value2", 1 },
130+
};
131+
settings.AddMetadataSetting("a", dictionaryValues);
132+
Assert.That(settings.HasCapability("a"));
133+
Assert.That(settings.GetCapability("a"), Is.TypeOf<Dictionary<string, int>>().And.EqualTo(dictionaryValues));
134+
}
71135
}
72136
}

0 commit comments

Comments
 (0)