Skip to content

Commit 379930d

Browse files
RenderMichaelnvborisenko
authored andcommitted
[dotnet] [bidi] Migrate RemoteValue to separate types (SeleniumHQ#15426)
Co-authored-by: Nikolay Borisenko <[email protected]>
1 parent e26e56c commit 379930d

File tree

11 files changed

+292
-283
lines changed

11 files changed

+292
-283
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

+27-26
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,33 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
3030
[JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))]
3131
[JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))]
3232

33-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Number), TypeInfoPropertyName = "Script_RemoteValue_Number")]
34-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Boolean), TypeInfoPropertyName = "Script_RemoteValue_Boolean")]
35-
[JsonSerializable(typeof(Modules.Script.RemoteValue.String), TypeInfoPropertyName = "Script_RemoteValue_String")]
36-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Null), TypeInfoPropertyName = "Script_RemoteValue_Null")]
37-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Undefined), TypeInfoPropertyName = "Script_RemoteValue_Undefined")]
38-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Symbol))]
39-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Array), TypeInfoPropertyName = "Script_RemoteValue_Array")]
40-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Object), TypeInfoPropertyName = "Script_RemoteValue_Object")]
41-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Function))]
42-
[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp), TypeInfoPropertyName = "Script_RemoteValue_RegExp")]
43-
[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")]
44-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Date), TypeInfoPropertyName = "Script_RemoteValue_Date")]
45-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Map), TypeInfoPropertyName = "Script_RemoteValue_Map")]
46-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Set), TypeInfoPropertyName = "Script_RemoteValue_Set")]
47-
[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakMap))]
48-
[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakSet))]
49-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Generator))]
50-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Error))]
51-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Proxy))]
52-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Promise))]
53-
[JsonSerializable(typeof(Modules.Script.RemoteValue.TypedArray))]
54-
[JsonSerializable(typeof(Modules.Script.RemoteValue.ArrayBuffer))]
55-
[JsonSerializable(typeof(Modules.Script.RemoteValue.NodeList))]
56-
[JsonSerializable(typeof(Modules.Script.RemoteValue.HtmlCollection))]
57-
[JsonSerializable(typeof(Modules.Script.RemoteValue.Node))]
58-
[JsonSerializable(typeof(Modules.Script.RemoteValue.WindowProxy))]
33+
[JsonSerializable(typeof(Modules.Script.NumberRemoteValue))]
34+
[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue))]
35+
[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue))]
36+
[JsonSerializable(typeof(Modules.Script.StringRemoteValue))]
37+
[JsonSerializable(typeof(Modules.Script.NullRemoteValue))]
38+
[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue))]
39+
[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue))]
40+
[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue))]
41+
[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue))]
42+
[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue))]
43+
[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue))]
44+
[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue.RegExpValue), TypeInfoPropertyName = "Script_RegExpRemoteValue_RegExpValue")]
45+
[JsonSerializable(typeof(Modules.Script.DateRemoteValue))]
46+
[JsonSerializable(typeof(Modules.Script.MapRemoteValue))]
47+
[JsonSerializable(typeof(Modules.Script.SetRemoteValue))]
48+
[JsonSerializable(typeof(Modules.Script.WeakMapRemoteValue))]
49+
[JsonSerializable(typeof(Modules.Script.WeakSetRemoteValue))]
50+
[JsonSerializable(typeof(Modules.Script.GeneratorRemoteValue))]
51+
[JsonSerializable(typeof(Modules.Script.ErrorRemoteValue))]
52+
[JsonSerializable(typeof(Modules.Script.ProxyRemoteValue))]
53+
[JsonSerializable(typeof(Modules.Script.PromiseRemoteValue))]
54+
[JsonSerializable(typeof(Modules.Script.TypedArrayRemoteValue))]
55+
[JsonSerializable(typeof(Modules.Script.ArrayBufferRemoteValue))]
56+
[JsonSerializable(typeof(Modules.Script.NodeListRemoteValue))]
57+
[JsonSerializable(typeof(Modules.Script.HtmlCollectionRemoteValue))]
58+
[JsonSerializable(typeof(Modules.Script.NodeRemoteValue))]
59+
[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue))]
5960

6061
[JsonSerializable(typeof(Modules.Script.RealmInfo.Window))]
6162
[JsonSerializable(typeof(Modules.Script.RealmInfo.DedicatedWorker))]

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
3131
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3232
{
3333
using var doc = JsonDocument.ParseValue(ref reader);
34-
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<RemoteValue.Node>>(options);
34+
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<NodeRemoteValue>>(options);
3535

3636
return new LocateNodesResult(nodes!);
3737
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs

+27-26
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,37 @@ internal class RemoteValueConverter : JsonConverter<RemoteValue>
3333

3434
if (jsonDocument.RootElement.ValueKind == JsonValueKind.String)
3535
{
36-
return new RemoteValue.String(jsonDocument.RootElement.GetString()!);
36+
return new StringRemoteValue(jsonDocument.RootElement.GetString()!);
3737
}
3838

3939
return jsonDocument.RootElement.GetProperty("type").ToString() switch
4040
{
41-
"number" => jsonDocument.Deserialize<RemoteValue.Number>(options),
42-
"boolean" => jsonDocument.Deserialize<RemoteValue.Boolean>(options),
43-
"string" => jsonDocument.Deserialize<RemoteValue.String>(options),
44-
"null" => jsonDocument.Deserialize<RemoteValue.Null>(options),
45-
"undefined" => jsonDocument.Deserialize<RemoteValue.Undefined>(options),
46-
"symbol" => jsonDocument.Deserialize<RemoteValue.Symbol>(options),
47-
"array" => jsonDocument.Deserialize<RemoteValue.Array>(options),
48-
"object" => jsonDocument.Deserialize<RemoteValue.Object>(options),
49-
"function" => jsonDocument.Deserialize<RemoteValue.Function>(options),
50-
"regexp" => jsonDocument.Deserialize<RemoteValue.RegExp>(options),
51-
"date" => jsonDocument.Deserialize<RemoteValue.Date>(options),
52-
"map" => jsonDocument.Deserialize<RemoteValue.Map>(options),
53-
"set" => jsonDocument.Deserialize<RemoteValue.Set>(options),
54-
"weakmap" => jsonDocument.Deserialize<RemoteValue.WeakMap>(options),
55-
"weakset" => jsonDocument.Deserialize<RemoteValue.WeakSet>(options),
56-
"generator" => jsonDocument.Deserialize<RemoteValue.Generator>(options),
57-
"error" => jsonDocument.Deserialize<RemoteValue.Error>(options),
58-
"proxy" => jsonDocument.Deserialize<RemoteValue.Proxy>(options),
59-
"promise" => jsonDocument.Deserialize<RemoteValue.Promise>(options),
60-
"typedarray" => jsonDocument.Deserialize<RemoteValue.TypedArray>(options),
61-
"arraybuffer" => jsonDocument.Deserialize<RemoteValue.ArrayBuffer>(options),
62-
"nodelist" => jsonDocument.Deserialize<RemoteValue.NodeList>(options),
63-
"htmlcollection" => jsonDocument.Deserialize<RemoteValue.HtmlCollection>(options),
64-
"node" => jsonDocument.Deserialize<RemoteValue.Node>(options),
65-
"window" => jsonDocument.Deserialize<RemoteValue.WindowProxy>(options),
41+
"number" => jsonDocument.Deserialize<NumberRemoteValue>(options),
42+
"boolean" => jsonDocument.Deserialize<BooleanRemoteValue>(options),
43+
"bigint" => jsonDocument.Deserialize<BigIntRemoteValue>(options),
44+
"string" => jsonDocument.Deserialize<StringRemoteValue>(options),
45+
"null" => jsonDocument.Deserialize<NullRemoteValue>(options),
46+
"undefined" => jsonDocument.Deserialize<UndefinedRemoteValue>(options),
47+
"symbol" => jsonDocument.Deserialize<SymbolRemoteValue>(options),
48+
"array" => jsonDocument.Deserialize<ArrayRemoteValue>(options),
49+
"object" => jsonDocument.Deserialize<ObjectRemoteValue>(options),
50+
"function" => jsonDocument.Deserialize<FunctionRemoteValue>(options),
51+
"regexp" => jsonDocument.Deserialize<RegExpRemoteValue>(options),
52+
"date" => jsonDocument.Deserialize<DateRemoteValue>(options),
53+
"map" => jsonDocument.Deserialize<MapRemoteValue>(options),
54+
"set" => jsonDocument.Deserialize<SetRemoteValue>(options),
55+
"weakmap" => jsonDocument.Deserialize<WeakMapRemoteValue>(options),
56+
"weakset" => jsonDocument.Deserialize<WeakSetRemoteValue>(options),
57+
"generator" => jsonDocument.Deserialize<GeneratorRemoteValue>(options),
58+
"error" => jsonDocument.Deserialize<ErrorRemoteValue>(options),
59+
"proxy" => jsonDocument.Deserialize<ProxyRemoteValue>(options),
60+
"promise" => jsonDocument.Deserialize<PromiseRemoteValue>(options),
61+
"typedarray" => jsonDocument.Deserialize<TypedArrayRemoteValue>(options),
62+
"arraybuffer" => jsonDocument.Deserialize<ArrayBufferRemoteValue>(options),
63+
"nodelist" => jsonDocument.Deserialize<NodeListRemoteValue>(options),
64+
"htmlcollection" => jsonDocument.Deserialize<HtmlCollectionRemoteValue>(options),
65+
"node" => jsonDocument.Deserialize<NodeRemoteValue>(options),
66+
"window" => jsonDocument.Deserialize<WindowProxyRemoteValue>(options),
6667
_ => null,
6768
};
6869
}

dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ public record LocateNodesOptions : CommandOptions
3737
public IEnumerable<Script.ISharedReference>? StartNodes { get; set; }
3838
}
3939

40-
public record LocateNodesResult : IReadOnlyList<Script.RemoteValue.Node>
40+
public record LocateNodesResult : IReadOnlyList<Script.NodeRemoteValue>
4141
{
42-
private readonly IReadOnlyList<Script.RemoteValue.Node> _nodes;
42+
private readonly IReadOnlyList<Script.NodeRemoteValue> _nodes;
4343

44-
internal LocateNodesResult(IReadOnlyList<Script.RemoteValue.Node> nodes)
44+
internal LocateNodesResult(IReadOnlyList<Script.NodeRemoteValue> nodes)
4545
{
4646
_nodes = nodes;
4747
}
4848

49-
public Script.RemoteValue.Node this[int index] => _nodes[index];
49+
public Script.NodeRemoteValue this[int index] => _nodes[index];
5050

5151
public int Count => _nodes.Count;
5252

53-
public IEnumerator<Script.RemoteValue.Node> GetEnumerator() => _nodes.GetEnumerator();
53+
public IEnumerator<Script.NodeRemoteValue> GetEnumerator() => _nodes.GetEnumerator();
5454

5555
IEnumerator IEnumerable.GetEnumerator() => (_nodes as IEnumerable).GetEnumerator();
5656
}

dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public record NodeProperties(long NodeType, long ChildNodeCount)
2828
public IReadOnlyDictionary<string, string>? Attributes { get; internal set; }
2929

3030
[JsonInclude]
31-
public IReadOnlyList<RemoteValue.Node>? Children { get; internal set; }
31+
public IReadOnlyList<NodeRemoteValue>? Children { get; internal set; }
3232

3333
[JsonInclude]
3434
public string? LocalName { get; internal set; }
@@ -43,5 +43,5 @@ public record NodeProperties(long NodeType, long ChildNodeCount)
4343
public string? NodeValue { get; internal set; }
4444

4545
[JsonInclude]
46-
public RemoteValue.Node? ShadowRoot { get; internal set; }
46+
public NodeRemoteValue? ShadowRoot { get; internal set; }
4747
}

0 commit comments

Comments
 (0)