diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 3be20de67c742..ed1e8e0347788 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -30,32 +30,33 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))] [JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Number), TypeInfoPropertyName = "Script_RemoteValue_Number")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Boolean), TypeInfoPropertyName = "Script_RemoteValue_Boolean")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.String), TypeInfoPropertyName = "Script_RemoteValue_String")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Null), TypeInfoPropertyName = "Script_RemoteValue_Null")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Undefined), TypeInfoPropertyName = "Script_RemoteValue_Undefined")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Symbol))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Array), TypeInfoPropertyName = "Script_RemoteValue_Array")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Object), TypeInfoPropertyName = "Script_RemoteValue_Object")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Function))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp), TypeInfoPropertyName = "Script_RemoteValue_RegExp")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.RegExp.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Date), TypeInfoPropertyName = "Script_RemoteValue_Date")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Map), TypeInfoPropertyName = "Script_RemoteValue_Map")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Set), TypeInfoPropertyName = "Script_RemoteValue_Set")] -[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakMap))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.WeakSet))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Generator))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Error))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Proxy))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Promise))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.TypedArray))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.ArrayBuffer))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.NodeList))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.HtmlCollection))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.Node))] -[JsonSerializable(typeof(Modules.Script.RemoteValue.WindowProxy))] +[JsonSerializable(typeof(Modules.Script.NumberRemoteValue))] +[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue))] +[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue))] +[JsonSerializable(typeof(Modules.Script.StringRemoteValue))] +[JsonSerializable(typeof(Modules.Script.NullRemoteValue))] +[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue))] +[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue))] +[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue))] +[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue))] +[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue))] +[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue))] +[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue.RegExpValue), TypeInfoPropertyName = "Script_RegExpRemoteValue_RegExpValue")] +[JsonSerializable(typeof(Modules.Script.DateRemoteValue))] +[JsonSerializable(typeof(Modules.Script.MapRemoteValue))] +[JsonSerializable(typeof(Modules.Script.SetRemoteValue))] +[JsonSerializable(typeof(Modules.Script.WeakMapRemoteValue))] +[JsonSerializable(typeof(Modules.Script.WeakSetRemoteValue))] +[JsonSerializable(typeof(Modules.Script.GeneratorRemoteValue))] +[JsonSerializable(typeof(Modules.Script.ErrorRemoteValue))] +[JsonSerializable(typeof(Modules.Script.ProxyRemoteValue))] +[JsonSerializable(typeof(Modules.Script.PromiseRemoteValue))] +[JsonSerializable(typeof(Modules.Script.TypedArrayRemoteValue))] +[JsonSerializable(typeof(Modules.Script.ArrayBufferRemoteValue))] +[JsonSerializable(typeof(Modules.Script.NodeListRemoteValue))] +[JsonSerializable(typeof(Modules.Script.HtmlCollectionRemoteValue))] +[JsonSerializable(typeof(Modules.Script.NodeRemoteValue))] +[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue))] [JsonSerializable(typeof(Modules.Script.RealmInfo.Window))] [JsonSerializable(typeof(Modules.Script.RealmInfo.DedicatedWorker))] diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs index 027575d31acf1..4bc7af14acf4a 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs @@ -31,7 +31,7 @@ internal class LocateNodesResultConverter : JsonConverter public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { using var doc = JsonDocument.ParseValue(ref reader); - var nodes = doc.RootElement.GetProperty("nodes").Deserialize>(options); + var nodes = doc.RootElement.GetProperty("nodes").Deserialize>(options); return new LocateNodesResult(nodes!); } diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs index 88539ce7b55fd..f5319db4c5294 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/Polymorphic/RemoteValueConverter.cs @@ -33,36 +33,37 @@ internal class RemoteValueConverter : JsonConverter if (jsonDocument.RootElement.ValueKind == JsonValueKind.String) { - return new RemoteValue.String(jsonDocument.RootElement.GetString()!); + return new StringRemoteValue(jsonDocument.RootElement.GetString()!); } return jsonDocument.RootElement.GetProperty("type").ToString() switch { - "number" => jsonDocument.Deserialize(options), - "boolean" => jsonDocument.Deserialize(options), - "string" => jsonDocument.Deserialize(options), - "null" => jsonDocument.Deserialize(options), - "undefined" => jsonDocument.Deserialize(options), - "symbol" => jsonDocument.Deserialize(options), - "array" => jsonDocument.Deserialize(options), - "object" => jsonDocument.Deserialize(options), - "function" => jsonDocument.Deserialize(options), - "regexp" => jsonDocument.Deserialize(options), - "date" => jsonDocument.Deserialize(options), - "map" => jsonDocument.Deserialize(options), - "set" => jsonDocument.Deserialize(options), - "weakmap" => jsonDocument.Deserialize(options), - "weakset" => jsonDocument.Deserialize(options), - "generator" => jsonDocument.Deserialize(options), - "error" => jsonDocument.Deserialize(options), - "proxy" => jsonDocument.Deserialize(options), - "promise" => jsonDocument.Deserialize(options), - "typedarray" => jsonDocument.Deserialize(options), - "arraybuffer" => jsonDocument.Deserialize(options), - "nodelist" => jsonDocument.Deserialize(options), - "htmlcollection" => jsonDocument.Deserialize(options), - "node" => jsonDocument.Deserialize(options), - "window" => jsonDocument.Deserialize(options), + "number" => jsonDocument.Deserialize(options), + "boolean" => jsonDocument.Deserialize(options), + "bigint" => jsonDocument.Deserialize(options), + "string" => jsonDocument.Deserialize(options), + "null" => jsonDocument.Deserialize(options), + "undefined" => jsonDocument.Deserialize(options), + "symbol" => jsonDocument.Deserialize(options), + "array" => jsonDocument.Deserialize(options), + "object" => jsonDocument.Deserialize(options), + "function" => jsonDocument.Deserialize(options), + "regexp" => jsonDocument.Deserialize(options), + "date" => jsonDocument.Deserialize(options), + "map" => jsonDocument.Deserialize(options), + "set" => jsonDocument.Deserialize(options), + "weakmap" => jsonDocument.Deserialize(options), + "weakset" => jsonDocument.Deserialize(options), + "generator" => jsonDocument.Deserialize(options), + "error" => jsonDocument.Deserialize(options), + "proxy" => jsonDocument.Deserialize(options), + "promise" => jsonDocument.Deserialize(options), + "typedarray" => jsonDocument.Deserialize(options), + "arraybuffer" => jsonDocument.Deserialize(options), + "nodelist" => jsonDocument.Deserialize(options), + "htmlcollection" => jsonDocument.Deserialize(options), + "node" => jsonDocument.Deserialize(options), + "window" => jsonDocument.Deserialize(options), _ => null, }; } diff --git a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs index fdc7e29b7b04c..147dbc0303ed9 100644 --- a/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs +++ b/dotnet/src/webdriver/BiDi/Modules/BrowsingContext/LocateNodesCommand.cs @@ -37,20 +37,20 @@ public record LocateNodesOptions : CommandOptions public IEnumerable? StartNodes { get; set; } } -public record LocateNodesResult : IReadOnlyList +public record LocateNodesResult : IReadOnlyList { - private readonly IReadOnlyList _nodes; + private readonly IReadOnlyList _nodes; - internal LocateNodesResult(IReadOnlyList nodes) + internal LocateNodesResult(IReadOnlyList nodes) { _nodes = nodes; } - public Script.RemoteValue.Node this[int index] => _nodes[index]; + public Script.NodeRemoteValue this[int index] => _nodes[index]; public int Count => _nodes.Count; - public IEnumerator GetEnumerator() => _nodes.GetEnumerator(); + public IEnumerator GetEnumerator() => _nodes.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => (_nodes as IEnumerable).GetEnumerator(); } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs b/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs index b1d44271018ea..804580a7d2fd0 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/NodeProperties.cs @@ -28,7 +28,7 @@ public record NodeProperties(long NodeType, long ChildNodeCount) public IReadOnlyDictionary? Attributes { get; internal set; } [JsonInclude] - public IReadOnlyList? Children { get; internal set; } + public IReadOnlyList? Children { get; internal set; } [JsonInclude] public string? LocalName { get; internal set; } @@ -43,5 +43,5 @@ public record NodeProperties(long NodeType, long ChildNodeCount) public string? NodeValue { get; internal set; } [JsonInclude] - public RemoteValue.Node? ShadowRoot { get; internal set; } + public NodeRemoteValue? ShadowRoot { get; internal set; } } diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 6a791189179fa..d75a4efc0aab4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; +using System.Numerics; using System.Text.Json; using System.Text.Json.Serialization; @@ -26,42 +27,46 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(Number), "number")] -//[JsonDerivedType(typeof(Boolean), "boolean")] -//[JsonDerivedType(typeof(String), "string")] -//[JsonDerivedType(typeof(Null), "null")] -//[JsonDerivedType(typeof(Undefined), "undefined")] -//[JsonDerivedType(typeof(Symbol), "symbol")] -//[JsonDerivedType(typeof(Array), "array")] -//[JsonDerivedType(typeof(Object), "object")] -//[JsonDerivedType(typeof(Function), "function")] -//[JsonDerivedType(typeof(RegExp), "regexp")] -//[JsonDerivedType(typeof(Date), "date")] -//[JsonDerivedType(typeof(Map), "map")] -//[JsonDerivedType(typeof(Set), "set")] -//[JsonDerivedType(typeof(WeakMap), "weakmap")] -//[JsonDerivedType(typeof(WeakSet), "weakset")] -//[JsonDerivedType(typeof(Generator), "generator")] -//[JsonDerivedType(typeof(Error), "error")] -//[JsonDerivedType(typeof(Proxy), "proxy")] -//[JsonDerivedType(typeof(Promise), "promise")] -//[JsonDerivedType(typeof(TypedArray), "typedarray")] -//[JsonDerivedType(typeof(ArrayBuffer), "arraybuffer")] -//[JsonDerivedType(typeof(NodeList), "nodelist")] -//[JsonDerivedType(typeof(HtmlCollection), "htmlcollection")] -//[JsonDerivedType(typeof(Node), "node")] -//[JsonDerivedType(typeof(WindowProxy), "window")] +//[JsonDerivedType(typeof(NumberRemoteValue), "number")] +//[JsonDerivedType(typeof(BooleanRemoteValue), "boolean")] +//[JsonDerivedType(typeof(BigIntRemoteValue), "bigint")] +//[JsonDerivedType(typeof(StringRemoteValue), "string")] +//[JsonDerivedType(typeof(NullRemoteValue), "null")] +//[JsonDerivedType(typeof(UndefinedRemoteValue), "undefined")] +//[JsonDerivedType(typeof(SymbolRemoteValue), "symbol")] +//[JsonDerivedType(typeof(ArrayRemoteValue), "array")] +//[JsonDerivedType(typeof(ObjectRemoteValue), "object")] +//[JsonDerivedType(typeof(FunctionRemoteValue), "function")] +//[JsonDerivedType(typeof(RegExpRemoteValue), "regexp")] +//[JsonDerivedType(typeof(DateRemoteValue), "date")] +//[JsonDerivedType(typeof(MapRemoteValue), "map")] +//[JsonDerivedType(typeof(SetRemoteValue), "set")] +//[JsonDerivedType(typeof(WeakMapRemoteValue), "weakmap")] +//[JsonDerivedType(typeof(WeakSetRemoteValue), "weakset")] +//[JsonDerivedType(typeof(GeneratorRemoteValue), "generator")] +//[JsonDerivedType(typeof(ErrorRemoteValue), "error")] +//[JsonDerivedType(typeof(ProxyRemoteValue), "proxy")] +//[JsonDerivedType(typeof(PromiseRemoteValue), "promise")] +//[JsonDerivedType(typeof(TypedArrayRemoteValue), "typedarray")] +//[JsonDerivedType(typeof(ArrayBufferRemoteValue), "arraybuffer")] +//[JsonDerivedType(typeof(NodeListRemoteValue), "nodelist")] +//[JsonDerivedType(typeof(HtmlCollectionRemoteValue), "htmlcollection")] +//[JsonDerivedType(typeof(NodeRemoteValue), "node")] +//[JsonDerivedType(typeof(WindowProxyRemoteValue), "window")] public abstract record RemoteValue { - public static implicit operator int(RemoteValue remoteValue) => (int)((Number)remoteValue).Value; - public static implicit operator long(RemoteValue remoteValue) => (long)((Number)remoteValue).Value; + public static implicit operator double(RemoteValue remoteValue) => (double)((NumberRemoteValue)remoteValue).Value; + + public static implicit operator int(RemoteValue remoteValue) => (int)(double)remoteValue; + public static implicit operator long(RemoteValue remoteValue) => (long)(double)remoteValue; + public static implicit operator string?(RemoteValue remoteValue) { return remoteValue switch { - String stringValue => stringValue.Value, - Null => null, - _ => throw new BiDiException($"Cannot convert {remoteValue} to string") + StringRemoteValue stringValue => stringValue.Value, + NullRemoteValue => null, + _ => throw new InvalidCastException($"Cannot convert {remoteValue} to string") }; } @@ -72,15 +77,15 @@ public abstract record RemoteValue if (type == typeof(bool)) { - return (TResult)(Convert.ToBoolean(((Boolean)this).Value) as object); + return (TResult)(Convert.ToBoolean(((BooleanRemoteValue)this).Value) as object); } if (type == typeof(int)) { - return (TResult)(Convert.ToInt32(((Number)this).Value) as object); + return (TResult)(Convert.ToInt32(((NumberRemoteValue)this).Value) as object); } else if (type == typeof(string)) { - return (TResult)(((String)this).Value as object); + return (TResult)(((StringRemoteValue)this).Value as object); } else if (type is object) { @@ -90,181 +95,183 @@ public abstract record RemoteValue throw new BiDiException("Cannot convert ....."); } +} - public record Number(double Value) : PrimitiveProtocolRemoteValue; +public record NumberRemoteValue(double Value) : PrimitiveProtocolRemoteValue; - public record Boolean(bool Value) : PrimitiveProtocolRemoteValue; +public record BooleanRemoteValue(bool Value) : PrimitiveProtocolRemoteValue; - public record String(string Value) : PrimitiveProtocolRemoteValue; +public record BigIntRemoteValue(string Value) : PrimitiveProtocolRemoteValue; - public record Null : PrimitiveProtocolRemoteValue; +public record StringRemoteValue(string Value) : PrimitiveProtocolRemoteValue; - public record Undefined : PrimitiveProtocolRemoteValue; +public record NullRemoteValue : PrimitiveProtocolRemoteValue; - public record Symbol : RemoteValue - { - public Handle? Handle { get; set; } +public record UndefinedRemoteValue : PrimitiveProtocolRemoteValue; - public InternalId? InternalId { get; set; } - } +public record SymbolRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record Array : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } +} - public InternalId? InternalId { get; set; } +public record ArrayRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public IReadOnlyList? Value { get; set; } - } + public InternalId? InternalId { get; set; } - public record Object : RemoteValue - { - public Handle? Handle { get; set; } + public IReadOnlyList? Value { get; set; } +} - public InternalId? InternalId { get; set; } +public record ObjectRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public IReadOnlyList>? Value { get; set; } - } + public InternalId? InternalId { get; set; } - public record Function : RemoteValue - { - public Handle? Handle { get; set; } + public IReadOnlyList>? Value { get; set; } +} - public InternalId? InternalId { get; set; } - } +public record FunctionRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record RegExp(RegExp.RegExpValue Value) : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } +} - public InternalId? InternalId { get; set; } +public record RegExpRemoteValue(RegExpRemoteValue.RegExpValue Value) : RemoteValue +{ + public Handle? Handle { get; set; } - public record RegExpValue(string Pattern) - { - public string? Flags { get; set; } - } - } + public InternalId? InternalId { get; set; } - public record Date(string Value) : RemoteValue + public record RegExpValue(string Pattern) { - public Handle? Handle { get; set; } - - public InternalId? InternalId { get; set; } + public string? Flags { get; set; } } +} - public record Map : RemoteValue - { - public Handle? Handle { get; set; } +public record DateRemoteValue(string Value) : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } +} - public IReadOnlyList>? Value { get; set; } - } +public record MapRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record Set : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } + public IReadOnlyList>? Value { get; set; } +} - public IReadOnlyList? Value { get; set; } - } +public record SetRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record WeakMap : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } - } + public IReadOnlyList? Value { get; set; } +} - public record WeakSet : RemoteValue - { - public Handle? Handle { get; set; } +public record WeakMapRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record Generator : RemoteValue - { - public Handle? Handle { get; set; } +public record WeakSetRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record Error : RemoteValue - { - public Handle? Handle { get; set; } +public record GeneratorRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record Proxy : RemoteValue - { - public Handle? Handle { get; set; } +public record ErrorRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record Promise : RemoteValue - { - public Handle? Handle { get; set; } +public record ProxyRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record TypedArray : RemoteValue - { - public Handle? Handle { get; set; } +public record PromiseRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record ArrayBuffer : RemoteValue - { - public Handle? Handle { get; set; } +public record TypedArrayRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record NodeList : RemoteValue - { - public Handle? Handle { get; set; } +public record ArrayBufferRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } +} - public IReadOnlyList? Value { get; set; } - } +public record NodeListRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record HtmlCollection : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } + public IReadOnlyList? Value { get; set; } +} - public IReadOnlyList? Value { get; set; } - } +public record HtmlCollectionRemoteValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record Node : RemoteValue, ISharedReference - { - [JsonInclude] - public string? SharedId { get; internal set; } + public InternalId? InternalId { get; set; } - public Handle? Handle { get; set; } + public IReadOnlyList? Value { get; set; } +} - public InternalId? InternalId { get; set; } +public record NodeRemoteValue : RemoteValue, ISharedReference +{ + [JsonInclude] + public string? SharedId { get; internal set; } - [JsonInclude] - public NodeProperties? Value { get; internal set; } - } + public Handle? Handle { get; set; } - public record WindowProxy(WindowProxy.Properties Value) : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } + [JsonInclude] + public NodeProperties? Value { get; internal set; } +} - public record Properties(BrowsingContext.BrowsingContext Context); - } +public record WindowProxyRemoteValue(WindowProxyRemoteValue.Properties Value) : RemoteValue +{ + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } + + public record Properties(BrowsingContext.BrowsingContext Context); } public abstract record PrimitiveProtocolRemoteValue : RemoteValue; diff --git a/dotnet/test/common/BiDi/Log/LogTest.cs b/dotnet/test/common/BiDi/Log/LogTest.cs index 96db3a77c7517..58e0c6a701f6b 100644 --- a/dotnet/test/common/BiDi/Log/LogTest.cs +++ b/dotnet/test/common/BiDi/Log/LogTest.cs @@ -52,7 +52,7 @@ public async Task CanListenToConsoleLog() Assert.That(consoleLogEntry.Args, Is.Not.Null); Assert.That(consoleLogEntry.Args, Has.Count.EqualTo(1)); - Assert.That(consoleLogEntry.Args[0], Is.AssignableFrom()); + Assert.That(consoleLogEntry.Args[0], Is.AssignableFrom()); } [Test] diff --git a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs index d1e2608ddb431..2a9468c3ee07e 100644 --- a/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs +++ b/dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs @@ -32,7 +32,7 @@ public async Task CanCallFunctionWithDeclaration() Assert.That(res, Is.Not.Null); Assert.That(res.Realm, Is.Not.Null); - Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(3)); + Assert.That((res.Result as NumberRemoteValue).Value, Is.EqualTo(3)); } [Test] @@ -75,9 +75,9 @@ public async Task CanCallFunctionWithArguments() Arguments = ["abc", 42] }); - Assert.That(res.Result, Is.AssignableFrom()); - Assert.That((string)(res.Result as RemoteValue.Array).Value[0], Is.EqualTo("abc")); - Assert.That((int)(res.Result as RemoteValue.Array).Value[1], Is.EqualTo(42)); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((string)(res.Result as ArrayRemoteValue).Value[0], Is.EqualTo("abc")); + Assert.That((int)(res.Result as ArrayRemoteValue).Value[1], Is.EqualTo(42)); } [Test] @@ -90,8 +90,8 @@ public async Task CanCallFunctionToGetIFrameBrowsingContext() """, false); Assert.That(res, Is.Not.Null); - Assert.That(res.Result, Is.AssignableFrom()); - Assert.That((res.Result as RemoteValue.WindowProxy).Value, Is.Not.Null); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as WindowProxyRemoteValue).Value, Is.Not.Null); } [Test] @@ -104,8 +104,8 @@ public async Task CanCallFunctionToGetElement() """, false); Assert.That(res, Is.Not.Null); - Assert.That(res.Result, Is.AssignableFrom()); - Assert.That((res.Result as RemoteValue.Node).Value, Is.Not.Null); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as NodeRemoteValue).Value, Is.Not.Null); } [Test] @@ -132,7 +132,7 @@ async function() { """, awaitPromise: false); Assert.That(res, Is.Not.Null); - Assert.That(res.Result, Is.AssignableFrom()); + Assert.That(res.Result, Is.AssignableFrom()); } [Test] @@ -156,9 +156,9 @@ public async Task CanCallFunctionWithOwnershipRoot() }); Assert.That(res, Is.Not.Null); - Assert.That((res.Result as RemoteValue.Object).Handle, Is.Not.Null); - Assert.That((string)(res.Result as RemoteValue.Object).Value[0][0], Is.EqualTo("a")); - Assert.That((int)(res.Result as RemoteValue.Object).Value[0][1], Is.EqualTo(1)); + Assert.That((res.Result as ObjectRemoteValue).Handle, Is.Not.Null); + Assert.That((string)(res.Result as ObjectRemoteValue).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as ObjectRemoteValue).Value[0][1], Is.EqualTo(1)); } [Test] @@ -170,9 +170,9 @@ public async Task CanCallFunctionWithOwnershipNone() }); Assert.That(res, Is.Not.Null); - Assert.That((res.Result as RemoteValue.Object).Handle, Is.Null); - Assert.That((string)(res.Result as RemoteValue.Object).Value[0][0], Is.EqualTo("a")); - Assert.That((int)(res.Result as RemoteValue.Object).Value[0][1], Is.EqualTo(1)); + Assert.That((res.Result as ObjectRemoteValue).Handle, Is.Null); + Assert.That((string)(res.Result as ObjectRemoteValue).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as ObjectRemoteValue).Value[0][1], Is.EqualTo(1)); } [Test] @@ -191,7 +191,7 @@ public async Task CanCallFunctionInASandBox() var res = await context.Script.CallFunctionAsync("() => window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); - Assert.That(res.Result, Is.AssignableFrom()); + Assert.That(res.Result, Is.AssignableFrom()); // Make changes in the sandbox await context.Script.CallFunctionAsync("() => { window.foo = 2; }", true, targetOptions: new() { Sandbox = "sandbox" }); @@ -199,8 +199,8 @@ public async Task CanCallFunctionInASandBox() // Check if the changes are present in the sandbox res = await context.Script.CallFunctionAsync("() => window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); - Assert.That(res.Result, Is.AssignableFrom()); - Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(2)); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as NumberRemoteValue).Value, Is.EqualTo(2)); } [Test] diff --git a/dotnet/test/common/BiDi/Script/CallFunctionRemoteValueTest.cs b/dotnet/test/common/BiDi/Script/CallFunctionRemoteValueTest.cs index 638df753af139..35defc34beda8 100644 --- a/dotnet/test/common/BiDi/Script/CallFunctionRemoteValueTest.cs +++ b/dotnet/test/common/BiDi/Script/CallFunctionRemoteValueTest.cs @@ -30,7 +30,7 @@ public async Task CanCallFunctionAndReturnUndefined() { var response = await context.Script.CallFunctionAsync("() => { return undefined; }", false); - Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.AssignableTo()); } [Test] @@ -38,7 +38,7 @@ public async Task CanCallFunctionAndReturnNull() { var response = await context.Script.CallFunctionAsync("() => { return null; }", false); - Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.AssignableTo()); } [Test] @@ -46,8 +46,8 @@ public async Task CanCallFunctionAndReturnTrue() { var response = await context.Script.CallFunctionAsync("() => { return true; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Boolean)response.Result).Value, Is.True); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((BooleanRemoteValue)response.Result).Value, Is.True); } [Test] @@ -55,8 +55,8 @@ public async Task CanCallFunctionAndReturnFalse() { var response = await context.Script.CallFunctionAsync("() => { return false; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Boolean)response.Result).Value, Is.False); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((BooleanRemoteValue)response.Result).Value, Is.False); } @@ -65,8 +65,8 @@ public async Task CanCallFunctionAndReturnEmptyString() { var response = await context.Script.CallFunctionAsync("() => { return ''; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.String)response.Result).Value, Is.Empty); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((StringRemoteValue)response.Result).Value, Is.Empty); } [Test] @@ -74,8 +74,8 @@ public async Task CanCallFunctionAndReturnNonEmptyString() { var response = await context.Script.CallFunctionAsync("() => { return 'whoa'; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.String)response.Result).Value, Is.EqualTo("whoa")); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((StringRemoteValue)response.Result).Value, Is.EqualTo("whoa")); } [Test] @@ -85,8 +85,8 @@ public async Task CanCallFunctionAndReturnRecentDate() var response = await context.Script.CallFunctionAsync($$"""() => { return new Date('{{PinnedDateTimeString}}'); }""", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(response.Result, Is.EqualTo(new RemoteValue.Date(PinnedDateTimeString))); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.EqualTo(new DateRemoteValue(PinnedDateTimeString))); } [Test] @@ -96,8 +96,8 @@ public async Task CanCallFunctionAndReturnUnixEpoch() var response = await context.Script.CallFunctionAsync($$"""() => { return new Date('{{EpochString}}'); }""", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(response.Result, Is.EqualTo(new RemoteValue.Date(EpochString))); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.EqualTo(new DateRemoteValue(EpochString))); } [Test] @@ -105,8 +105,8 @@ public async Task CanCallFunctionAndReturnNumberFive() { var response = await context.Script.CallFunctionAsync("() => { return 5; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Number)response.Result).Value, Is.EqualTo(5)); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((NumberRemoteValue)response.Result).Value, Is.EqualTo(5)); } [Test] @@ -114,8 +114,8 @@ public async Task CanCallFunctionAndReturnNumberNegativeFive() { var response = await context.Script.CallFunctionAsync("() => { return -5; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Number)response.Result).Value, Is.EqualTo(-5)); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((NumberRemoteValue)response.Result).Value, Is.EqualTo(-5)); } [Test] @@ -123,8 +123,8 @@ public async Task CanCallFunctionAndReturnNumberZero() { var response = await context.Script.CallFunctionAsync("() => { return 0; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Number)response.Result).Value, Is.Zero); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((NumberRemoteValue)response.Result).Value, Is.Zero); } [Test] @@ -132,9 +132,9 @@ public async Task CanCallFunctionAndReturnNumberNegativeZero() { var response = await context.Script.CallFunctionAsync("() => { return -0; }", false); - Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.AssignableTo()); - var actualNumberValue = ((RemoteValue.Number)response.Result).Value; + var actualNumberValue = ((NumberRemoteValue)response.Result).Value; Assert.That(actualNumberValue, Is.Zero); Assert.That(double.IsNegative(actualNumberValue), Is.True); } @@ -144,9 +144,9 @@ public async Task CanCallFunctionAndReturnNumberPositiveInfinity() { var response = await context.Script.CallFunctionAsync("() => { return Number.POSITIVE_INFINITY; }", false); - Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.AssignableTo()); - var expectedInfinity = ((RemoteValue.Number)response.Result).Value; + var expectedInfinity = ((NumberRemoteValue)response.Result).Value; Assert.That(double.IsPositiveInfinity(expectedInfinity)); } @@ -155,9 +155,9 @@ public async Task CanCallFunctionAndReturnNumberNegativeInfinity() { var response = await context.Script.CallFunctionAsync("() => { return Number.NEGATIVE_INFINITY; }", false); - Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.AssignableTo()); - var expectedInfinity = ((RemoteValue.Number)response.Result).Value; + var expectedInfinity = ((NumberRemoteValue)response.Result).Value; Assert.That(double.IsNegativeInfinity(expectedInfinity)); } @@ -166,8 +166,8 @@ public async Task CanCallFunctionAndReturnNumberNaN() { var response = await context.Script.CallFunctionAsync("() => { return NaN; }", false); - Assert.That(response.Result, Is.AssignableTo()); - var expectedInfinity = ((RemoteValue.Number)response.Result).Value; + Assert.That(response.Result, Is.AssignableTo()); + var expectedInfinity = ((NumberRemoteValue)response.Result).Value; Assert.That(double.IsNaN(expectedInfinity)); } @@ -176,8 +176,8 @@ public async Task CanCallFunctionAndReturnRegExp() { var response = await context.Script.CallFunctionAsync("() => { return /foo*/g; }", false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(response.Result, Is.EqualTo(new RemoteValue.RegExp(new RemoteValue.RegExp.RegExpValue("foo*") { Flags = "g" }))); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.EqualTo(new RegExpRemoteValue(new RegExpRemoteValue.RegExpValue("foo*") { Flags = "g" }))); } [Test] @@ -185,9 +185,9 @@ public async Task CanCallFunctionAndReturnArray() { var response = await context.Script.CallFunctionAsync("() => { return ['hi']; }", false); - var expectedArray = new RemoteValue.Array { Value = [new RemoteValue.String("hi")] }; - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Array)response.Result).Value, Is.EqualTo(expectedArray.Value)); + var expectedArray = new ArrayRemoteValue { Value = [new StringRemoteValue("hi")] }; + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((ArrayRemoteValue)response.Result).Value, Is.EqualTo(expectedArray.Value)); } [Test] @@ -195,21 +195,21 @@ public async Task CanCallFunctionAndReturnObject() { var response = await context.Script.CallFunctionAsync("() => { return { objKey: 'objValue' }; }", false); - Assert.That(response.Result, Is.AssignableTo()); + Assert.That(response.Result, Is.AssignableTo()); - var expected = new RemoteValue.Object + var expected = new ObjectRemoteValue { - Value = [[new RemoteValue.String("objKey"), new RemoteValue.String("objValue")]] + Value = [[new StringRemoteValue("objKey"), new StringRemoteValue("objValue")]] }; - Assert.That(((RemoteValue.Object)response.Result).Value, Is.EqualTo(expected.Value)); + Assert.That(((ObjectRemoteValue)response.Result).Value, Is.EqualTo(expected.Value)); } [Test] public async Task CanCallFunctionAndReturnMap() { - var expected = new RemoteValue.Map + var expected = new MapRemoteValue { - Value = [[new RemoteValue.String("mapKey"), new RemoteValue.String("mapValue")]] + Value = [[new StringRemoteValue("mapKey"), new StringRemoteValue("mapValue")]] }; var response = await context.Script.CallFunctionAsync($$""" @@ -220,14 +220,14 @@ public async Task CanCallFunctionAndReturnMap() } """, false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Map)response.Result).Value, Is.EqualTo(expected.Value)); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((MapRemoteValue)response.Result).Value, Is.EqualTo(expected.Value)); } [Test] public async Task CanCallFunctionAndReturnSet() { - var expected = new RemoteValue.Set { Value = [new RemoteValue.String("setKey")] }; + var expected = new SetRemoteValue { Value = [new StringRemoteValue("setKey")] }; var response = await context.Script.CallFunctionAsync($$""" () => { const set = new Set(); @@ -236,7 +236,7 @@ public async Task CanCallFunctionAndReturnSet() } """, false); - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteValue.Set)response.Result).Value, Is.EqualTo(expected.Value)); + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((SetRemoteValue)response.Result).Value, Is.EqualTo(expected.Value)); } } diff --git a/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs b/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs index a38f76c43fc95..df581f79fccf4 100644 --- a/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs +++ b/dotnet/test/common/BiDi/Script/EvaluateParametersTest.cs @@ -32,7 +32,7 @@ public async Task CanEvaluateScript() Assert.That(res, Is.Not.Null); Assert.That(res.Realm, Is.Not.Null); - Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(3)); + Assert.That((res.Result as NumberRemoteValue).Value, Is.EqualTo(3)); } [Test] @@ -84,9 +84,9 @@ public async Task CanEvaluateScriptWithResulWithOwnership() }); Assert.That(res, Is.Not.Null); - Assert.That((res.Result as RemoteValue.Object).Handle, Is.Not.Null); - Assert.That((string)(res.Result as RemoteValue.Object).Value[0][0], Is.EqualTo("a")); - Assert.That((int)(res.Result as RemoteValue.Object).Value[0][1], Is.EqualTo(1)); + Assert.That((res.Result as ObjectRemoteValue).Handle, Is.Not.Null); + Assert.That((string)(res.Result as ObjectRemoteValue).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as ObjectRemoteValue).Value[0][1], Is.EqualTo(1)); } [Test] @@ -97,7 +97,7 @@ public async Task CanEvaluateInASandBox() var res = await context.Script.EvaluateAsync("window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); - Assert.That(res.Result, Is.AssignableFrom()); + Assert.That(res.Result, Is.AssignableFrom()); // Make changes in the sandbox await context.Script.EvaluateAsync("window.foo = 2", true, targetOptions: new() { Sandbox = "sandbox" }); @@ -105,8 +105,8 @@ public async Task CanEvaluateInASandBox() // Check if the changes are present in the sandbox res = await context.Script.EvaluateAsync("window.foo", true, targetOptions: new() { Sandbox = "sandbox" }); - Assert.That(res.Result, Is.AssignableFrom()); - Assert.That((res.Result as RemoteValue.Number).Value, Is.EqualTo(2)); + Assert.That(res.Result, Is.AssignableFrom()); + Assert.That((res.Result as NumberRemoteValue).Value, Is.EqualTo(2)); } [Test] diff --git a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs index 798ea1cbbf9f2..916941fe25440 100644 --- a/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs +++ b/dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs @@ -164,6 +164,6 @@ public async Task CanRemovePreloadedScript() var resultAfterRemoval = await context.Script.EvaluateAsync("window.bar", true, targetOptions: new() { Sandbox = "sandbox" }); - Assert.That(resultAfterRemoval.Result, Is.AssignableFrom()); + Assert.That(resultAfterRemoval.Result, Is.AssignableFrom()); } }