From fe7623aea2f727e9b985d8b3d4daeb3c776c8fd7 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 15 Mar 2025 09:34:02 -0400 Subject: [PATCH 1/6] [dotnet] [bidi] Migrate RemoteValue to separate types --- .../Json/BiDiJsonSerializerContext.cs | 53 +-- .../Enumerable/LocateNodesResultConverter.cs | 2 +- .../Polymorphic/RemoteValueConverter.cs | 53 +-- .../BrowsingContext/LocateNodesCommand.cs | 10 +- .../BiDi/Modules/Script/NodeProperties.cs | 4 +- .../BiDi/Modules/Script/RemoteValue.cs | 359 ++++++++++-------- dotnet/test/common/BiDi/Log/LogTest.cs | 2 +- .../BiDi/Script/CallFunctionParameterTest.cs | 36 +- .../Script/CallFunctionRemoteValueTest.cs | 88 ++--- .../BiDi/Script/EvaluateParametersTest.cs | 14 +- .../common/BiDi/Script/ScriptCommandsTest.cs | 2 +- 11 files changed, 340 insertions(+), 283 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index 3be20de67c742..da7596eab542d 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.RemoteNumberValue), TypeInfoPropertyName = "Script_RemoteValue_Number")] +[JsonSerializable(typeof(Modules.Script.RemoteBooleanValue), TypeInfoPropertyName = "Script_RemoteValue_Boolean")] +[JsonSerializable(typeof(Modules.Script.RemoteBigIntValue), TypeInfoPropertyName = "Script_RemoteValue_BigInt")] +[JsonSerializable(typeof(Modules.Script.RemoteStringValue), TypeInfoPropertyName = "Script_RemoteValue_String")] +[JsonSerializable(typeof(Modules.Script.RemoteNullValue), TypeInfoPropertyName = "Script_RemoteValue_Null")] +[JsonSerializable(typeof(Modules.Script.RemoteUndefinedValue), TypeInfoPropertyName = "Script_RemoteValue_Undefined")] +[JsonSerializable(typeof(Modules.Script.RemoteSymbolValue))] +[JsonSerializable(typeof(Modules.Script.RemoteArrayValue), TypeInfoPropertyName = "Script_RemoteValue_Array")] +[JsonSerializable(typeof(Modules.Script.RemoteObjectValue), TypeInfoPropertyName = "Script_RemoteValue_Object")] +[JsonSerializable(typeof(Modules.Script.RemoteFunctionValue))] +[JsonSerializable(typeof(Modules.Script.RemoteRegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp")] +[JsonSerializable(typeof(Modules.Script.RemoteRegExpValue.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")] +[JsonSerializable(typeof(Modules.Script.RemoteDateValue), TypeInfoPropertyName = "Script_RemoteValue_Date")] +[JsonSerializable(typeof(Modules.Script.RemoteMapValue), TypeInfoPropertyName = "Script_RemoteValue_Map")] +[JsonSerializable(typeof(Modules.Script.RemoteSetValue), TypeInfoPropertyName = "Script_RemoteValue_Set")] +[JsonSerializable(typeof(Modules.Script.RemoteWeakMapValue))] +[JsonSerializable(typeof(Modules.Script.RemoteWeakSetValue))] +[JsonSerializable(typeof(Modules.Script.RemoteGeneratorValue))] +[JsonSerializable(typeof(Modules.Script.RemoteErrorValue))] +[JsonSerializable(typeof(Modules.Script.RemoteProxyValue))] +[JsonSerializable(typeof(Modules.Script.RemotePromiseValue))] +[JsonSerializable(typeof(Modules.Script.RemoteTypedArrayValue))] +[JsonSerializable(typeof(Modules.Script.RemoteArrayBufferValue))] +[JsonSerializable(typeof(Modules.Script.RemoteNodeListValue))] +[JsonSerializable(typeof(Modules.Script.RemoteHtmlCollectionValue))] +[JsonSerializable(typeof(Modules.Script.RemoteNodeValue))] +[JsonSerializable(typeof(Modules.Script.RemoteWindowProxyValue))] [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..0c409c872f108 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..a216f68e95879 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 RemoteValue.String(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..491e85af25d82 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.RemoteNodeValue 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..53dcc39c0b867 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 RemoteNodeValue? 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..685f87b0c5e40 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(RemoteNumberValue), "number")] +//[JsonDerivedType(typeof(RemoteBooleanValue), "boolean")] +//[JsonDerivedType(typeof(RemoteBigIntValue), "bigint")] +//[JsonDerivedType(typeof(RemoteStringValue), "string")] +//[JsonDerivedType(typeof(RemoteNullValue), "null")] +//[JsonDerivedType(typeof(RemoteUndefinedValue), "undefined")] +//[JsonDerivedType(typeof(RemoteSymbolValue), "symbol")] +//[JsonDerivedType(typeof(RemoteArrayValue), "array")] +//[JsonDerivedType(typeof(RemoteObjectValue), "object")] +//[JsonDerivedType(typeof(RemoteFunctionValue), "function")] +//[JsonDerivedType(typeof(RemoteRegExpValue), "regexp")] +//[JsonDerivedType(typeof(RemoteDateValue), "date")] +//[JsonDerivedType(typeof(RemoteMapValue), "map")] +//[JsonDerivedType(typeof(RemoteSetValue), "set")] +//[JsonDerivedType(typeof(RemoteWeakMapValue), "weakmap")] +//[JsonDerivedType(typeof(RemoteWeakSetValue), "weakset")] +//[JsonDerivedType(typeof(RemoteGeneratorValue), "generator")] +//[JsonDerivedType(typeof(RemoteErrorValue), "error")] +//[JsonDerivedType(typeof(RemoteProxyValue), "proxy")] +//[JsonDerivedType(typeof(RemotePromiseValue), "promise")] +//[JsonDerivedType(typeof(RemoteTypedArrayValue), "typedarray")] +//[JsonDerivedType(typeof(RemoteArrayBufferValue), "arraybuffer")] +//[JsonDerivedType(typeof(RemoteNodeListValue), "nodelist")] +//[JsonDerivedType(typeof(RemoteHtmlCollectionValue), "htmlcollection")] +//[JsonDerivedType(typeof(RemoteNodeValue), "node")] +//[JsonDerivedType(typeof(RemoteWindowProxyValue), "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)((RemoteNumberValue)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") + RemoteStringValue stringValue => stringValue.Value, + RemoteNullValue => 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(((RemoteBooleanValue)this).Value) as object); } if (type == typeof(int)) { - return (TResult)(Convert.ToInt32(((Number)this).Value) as object); + return (TResult)(Convert.ToInt32(((RemoteNumberValue)this).Value) as object); } else if (type == typeof(string)) { - return (TResult)(((String)this).Value as object); + return (TResult)(((RemoteStringValue)this).Value as object); } else if (type is object) { @@ -91,180 +96,230 @@ public abstract record RemoteValue throw new BiDiException("Cannot convert ....."); } - public record Number(double Value) : PrimitiveProtocolRemoteValue; + public static RemoteBigIntValue BigInt(BigInteger value) + { + return new RemoteBigIntValue(value.ToString()); + } - public record Boolean(bool Value) : PrimitiveProtocolRemoteValue; + public static RemoteNumberValue Number(double value) + { + return new RemoteNumberValue(value); + } - public record String(string Value) : PrimitiveProtocolRemoteValue; + public static RemoteBooleanValue Boolean(bool value) + { + return new RemoteBooleanValue(value); + } - public record Null : PrimitiveProtocolRemoteValue; + public static RemoteValue String(string? value) + { + return value is null ? RemoteNullValue.Instance : new RemoteStringValue(value); + } - public record Undefined : PrimitiveProtocolRemoteValue; + public static RemoteNullValue Null => RemoteNullValue.Instance; - public record Symbol : RemoteValue - { - public Handle? Handle { get; set; } + public static RemoteUndefinedValue Undefined => RemoteUndefinedValue.Instance; - public InternalId? InternalId { get; set; } - } + public static RemoteNumberValue NegativeInfinity => RemoteNumberValue.NegativeInfinity; - public record Array : RemoteValue - { - public Handle? Handle { get; set; } + public static RemoteNumberValue PositiveInfinity => RemoteNumberValue.PositiveInfinity; - public InternalId? InternalId { get; set; } + public static RemoteNumberValue NaN => RemoteNumberValue.NaN; - public IReadOnlyList? Value { get; set; } - } + public static RemoteNumberValue NegativeZero => RemoteNumberValue.NegativeZero; +} - public record Object : RemoteValue - { - public Handle? Handle { get; set; } +public record RemoteBigIntValue(string Value) : PrimitiveProtocolRemoteValue; - public InternalId? InternalId { get; set; } +public record RemoteNumberValue(double Value) : PrimitiveProtocolRemoteValue +{ + public static RemoteNumberValue NegativeInfinity { get; } = new RemoteNumberValue(double.NegativeInfinity); - public IReadOnlyList>? Value { get; set; } - } + public static RemoteNumberValue PositiveInfinity { get; } = new RemoteNumberValue(double.PositiveInfinity); - public record Function : RemoteValue - { - public Handle? Handle { get; set; } + public static RemoteNumberValue NaN { get; } = new RemoteNumberValue(double.NaN); - public InternalId? InternalId { get; set; } - } + public static RemoteNumberValue NegativeZero { get; } = new RemoteNumberValue(-0.0d); +} - public record RegExp(RegExp.RegExpValue Value) : RemoteValue - { - public Handle? Handle { get; set; } +public record RemoteBooleanValue(bool Value) : PrimitiveProtocolRemoteValue; - public InternalId? InternalId { get; set; } +public record RemoteStringValue(string Value) : PrimitiveProtocolRemoteValue; - public record RegExpValue(string Pattern) - { - public string? Flags { get; set; } - } - } +public record RemoteNullValue : PrimitiveProtocolRemoteValue +{ + public static RemoteNullValue Instance { get; } = new RemoteNullValue(); +} - public record Date(string Value) : RemoteValue - { - public Handle? Handle { get; set; } +public record RemoteUndefinedValue : PrimitiveProtocolRemoteValue +{ + public static RemoteUndefinedValue Instance { get; } = new RemoteUndefinedValue(); - public InternalId? InternalId { get; set; } - } +} - public record Map : RemoteValue - { - public Handle? Handle { get; set; } +public record RemoteSymbolValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } +} - public IReadOnlyList>? Value { get; set; } - } +public record RemoteArrayValue : 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 RemoteObjectValue : 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 RemoteFunctionValue : 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 RemoteRegExpValue(RemoteRegExpValue.RegExpValue Value) : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } - } + public InternalId? InternalId { get; set; } - public record Error : RemoteValue + public record RegExpValue(string Pattern) { - public Handle? Handle { get; set; } - - public InternalId? InternalId { get; set; } + public string? Flags { get; set; } } +} - public record Proxy : RemoteValue - { - public Handle? Handle { get; set; } +public record RemoteDateValue(string Value) : 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 RemoteMapValue : 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 IReadOnlyList>? Value { get; set; } +} - public InternalId? InternalId { get; set; } - } +public record RemoteSetValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record ArrayBuffer : RemoteValue - { - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } - public InternalId? InternalId { get; set; } - } + public IReadOnlyList? Value { get; set; } +} - public record NodeList : RemoteValue - { - public Handle? Handle { get; set; } +public record RemoteWeakMapValue : RemoteValue +{ + public Handle? Handle { get; set; } - public InternalId? InternalId { get; set; } + public InternalId? InternalId { get; set; } +} - public IReadOnlyList? Value { get; set; } - } +public record RemoteWeakSetValue : 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 record RemoteGeneratorValue : RemoteValue +{ + public Handle? Handle { get; set; } - public IReadOnlyList? Value { get; set; } - } + public InternalId? InternalId { get; set; } +} - public record Node : RemoteValue, ISharedReference - { - [JsonInclude] - public string? SharedId { get; internal set; } +public record RemoteErrorValue : RemoteValue +{ + public Handle? Handle { get; set; } - public Handle? Handle { get; set; } + public InternalId? InternalId { get; set; } +} - public InternalId? InternalId { get; set; } +public record RemoteProxyValue : RemoteValue +{ + public Handle? Handle { get; set; } - [JsonInclude] - public NodeProperties? Value { get; internal set; } - } + public InternalId? InternalId { get; set; } +} - public record WindowProxy(WindowProxy.Properties Value) : RemoteValue - { - public Handle? Handle { get; set; } +public record RemotePromiseValue : RemoteValue +{ + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } +} - public InternalId? InternalId { get; set; } +public record RemoteTypedArrayValue : RemoteValue +{ + public Handle? Handle { get; set; } - public record Properties(BrowsingContext.BrowsingContext Context); - } + public InternalId? InternalId { get; set; } +} + +public record RemoteArrayBufferValue : RemoteValue +{ + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } +} + +public record RemoteNodeListValue : RemoteValue +{ + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } + + public IReadOnlyList? Value { get; set; } +} + +public record RemoteHtmlCollectionValue : RemoteValue +{ + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } + + public IReadOnlyList? Value { get; set; } +} + +public record RemoteNodeValue : RemoteValue, ISharedReference +{ + [JsonInclude] + public string? SharedId { get; internal set; } + + public Handle? Handle { get; set; } + + public InternalId? InternalId { get; set; } + + [JsonInclude] + public NodeProperties? Value { get; internal set; } +} + +public record RemoteWindowProxyValue(RemoteWindowProxyValue.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..f70c37940012f 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..dec93092e0f73 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 RemoteNumberValue).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 RemoteArrayValue).Value[0], Is.EqualTo("abc")); + Assert.That((int)(res.Result as RemoteArrayValue).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 RemoteWindowProxyValue).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 RemoteNodeValue).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 RemoteObjectValue).Handle, Is.Not.Null); + Assert.That((string)(res.Result as RemoteObjectValue).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as RemoteObjectValue).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 RemoteObjectValue).Handle, Is.Null); + Assert.That((string)(res.Result as RemoteObjectValue).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as RemoteObjectValue).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 RemoteNumberValue).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..ea7bebe6df275 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(((RemoteBooleanValue)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(((RemoteBooleanValue)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(((RemoteStringValue)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(((RemoteStringValue)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 RemoteDateValue(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 RemoteDateValue(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(((RemoteNumberValue)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(((RemoteNumberValue)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(((RemoteNumberValue)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 = ((RemoteNumberValue)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 = ((RemoteNumberValue)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 = ((RemoteNumberValue)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 = ((RemoteNumberValue)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 RemoteRegExpValue(new RemoteRegExpValue.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 RemoteArrayValue { Value = [new RemoteStringValue("hi")] }; + Assert.That(response.Result, Is.AssignableTo()); + Assert.That(((RemoteArrayValue)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 RemoteObjectValue { - Value = [[new RemoteValue.String("objKey"), new RemoteValue.String("objValue")]] + Value = [[new RemoteStringValue("objKey"), new RemoteStringValue("objValue")]] }; - Assert.That(((RemoteValue.Object)response.Result).Value, Is.EqualTo(expected.Value)); + Assert.That(((RemoteObjectValue)response.Result).Value, Is.EqualTo(expected.Value)); } [Test] public async Task CanCallFunctionAndReturnMap() { - var expected = new RemoteValue.Map + var expected = new RemoteMapValue { - Value = [[new RemoteValue.String("mapKey"), new RemoteValue.String("mapValue")]] + Value = [[new RemoteStringValue("mapKey"), new RemoteStringValue("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(((RemoteMapValue)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 RemoteSetValue { Value = [new RemoteStringValue("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(((RemoteSetValue)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..7bc0f840d3d82 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 RemoteNumberValue).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 RemoteObjectValue).Handle, Is.Not.Null); + Assert.That((string)(res.Result as RemoteObjectValue).Value[0][0], Is.EqualTo("a")); + Assert.That((int)(res.Result as RemoteObjectValue).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 RemoteNumberValue).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..e26a74d55e9d1 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()); } } From 29feb1b7952621b837ad9ddd799e1f93c3cb31d6 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 15 Mar 2025 09:36:12 -0400 Subject: [PATCH 2/6] Remove helpers --- .../BiDi/Modules/Script/RemoteValue.cs | 54 ++----------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 685f87b0c5e40..1f38727a8848a 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -95,67 +95,19 @@ public abstract record RemoteValue throw new BiDiException("Cannot convert ....."); } - - public static RemoteBigIntValue BigInt(BigInteger value) - { - return new RemoteBigIntValue(value.ToString()); - } - - public static RemoteNumberValue Number(double value) - { - return new RemoteNumberValue(value); - } - - public static RemoteBooleanValue Boolean(bool value) - { - return new RemoteBooleanValue(value); - } - - public static RemoteValue String(string? value) - { - return value is null ? RemoteNullValue.Instance : new RemoteStringValue(value); - } - - public static RemoteNullValue Null => RemoteNullValue.Instance; - - public static RemoteUndefinedValue Undefined => RemoteUndefinedValue.Instance; - - public static RemoteNumberValue NegativeInfinity => RemoteNumberValue.NegativeInfinity; - - public static RemoteNumberValue PositiveInfinity => RemoteNumberValue.PositiveInfinity; - - public static RemoteNumberValue NaN => RemoteNumberValue.NaN; - - public static RemoteNumberValue NegativeZero => RemoteNumberValue.NegativeZero; } public record RemoteBigIntValue(string Value) : PrimitiveProtocolRemoteValue; -public record RemoteNumberValue(double Value) : PrimitiveProtocolRemoteValue -{ - public static RemoteNumberValue NegativeInfinity { get; } = new RemoteNumberValue(double.NegativeInfinity); - - public static RemoteNumberValue PositiveInfinity { get; } = new RemoteNumberValue(double.PositiveInfinity); - - public static RemoteNumberValue NaN { get; } = new RemoteNumberValue(double.NaN); - - public static RemoteNumberValue NegativeZero { get; } = new RemoteNumberValue(-0.0d); -} +public record RemoteNumberValue(double Value) : PrimitiveProtocolRemoteValue; public record RemoteBooleanValue(bool Value) : PrimitiveProtocolRemoteValue; public record RemoteStringValue(string Value) : PrimitiveProtocolRemoteValue; -public record RemoteNullValue : PrimitiveProtocolRemoteValue -{ - public static RemoteNullValue Instance { get; } = new RemoteNullValue(); -} +public record RemoteNullValue : PrimitiveProtocolRemoteValue; -public record RemoteUndefinedValue : PrimitiveProtocolRemoteValue -{ - public static RemoteUndefinedValue Instance { get; } = new RemoteUndefinedValue(); - -} +public record RemoteUndefinedValue : PrimitiveProtocolRemoteValue; public record RemoteSymbolValue : RemoteValue { From aff5a6a7c4bac539dc0b94d0d3401f282b72d79d Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 15 Mar 2025 09:37:14 -0400 Subject: [PATCH 3/6] move BigInt around --- dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs index 1f38727a8848a..d73fbec7ac24c 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -97,12 +97,12 @@ public abstract record RemoteValue } } -public record RemoteBigIntValue(string Value) : PrimitiveProtocolRemoteValue; - public record RemoteNumberValue(double Value) : PrimitiveProtocolRemoteValue; public record RemoteBooleanValue(bool Value) : PrimitiveProtocolRemoteValue; +public record RemoteBigIntValue(string Value) : PrimitiveProtocolRemoteValue; + public record RemoteStringValue(string Value) : PrimitiveProtocolRemoteValue; public record RemoteNullValue : PrimitiveProtocolRemoteValue; From 38730ca83ffb199dc3dbbbbbc63023041b15bcfe Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 15 Mar 2025 11:16:59 -0400 Subject: [PATCH 4/6] PR feedback --- .../Json/BiDiJsonSerializerContext.cs | 54 ++++---- .../Enumerable/LocateNodesResultConverter.cs | 2 +- .../Polymorphic/RemoteValueConverter.cs | 54 ++++---- .../BrowsingContext/LocateNodesCommand.cs | 10 +- .../BiDi/Modules/Script/NodeProperties.cs | 4 +- .../BiDi/Modules/Script/RemoteValue.cs | 116 +++++++++--------- dotnet/test/common/BiDi/Log/LogTest.cs | 2 +- .../BiDi/Script/CallFunctionParameterTest.cs | 36 +++--- .../Script/CallFunctionRemoteValueTest.cs | 88 ++++++------- .../BiDi/Script/EvaluateParametersTest.cs | 14 +-- .../common/BiDi/Script/ScriptCommandsTest.cs | 2 +- 11 files changed, 191 insertions(+), 191 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index da7596eab542d..e0efdade35d1b 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -30,33 +30,33 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))] [JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))] -[JsonSerializable(typeof(Modules.Script.RemoteNumberValue), TypeInfoPropertyName = "Script_RemoteValue_Number")] -[JsonSerializable(typeof(Modules.Script.RemoteBooleanValue), TypeInfoPropertyName = "Script_RemoteValue_Boolean")] -[JsonSerializable(typeof(Modules.Script.RemoteBigIntValue), TypeInfoPropertyName = "Script_RemoteValue_BigInt")] -[JsonSerializable(typeof(Modules.Script.RemoteStringValue), TypeInfoPropertyName = "Script_RemoteValue_String")] -[JsonSerializable(typeof(Modules.Script.RemoteNullValue), TypeInfoPropertyName = "Script_RemoteValue_Null")] -[JsonSerializable(typeof(Modules.Script.RemoteUndefinedValue), TypeInfoPropertyName = "Script_RemoteValue_Undefined")] -[JsonSerializable(typeof(Modules.Script.RemoteSymbolValue))] -[JsonSerializable(typeof(Modules.Script.RemoteArrayValue), TypeInfoPropertyName = "Script_RemoteValue_Array")] -[JsonSerializable(typeof(Modules.Script.RemoteObjectValue), TypeInfoPropertyName = "Script_RemoteValue_Object")] -[JsonSerializable(typeof(Modules.Script.RemoteFunctionValue))] -[JsonSerializable(typeof(Modules.Script.RemoteRegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp")] -[JsonSerializable(typeof(Modules.Script.RemoteRegExpValue.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")] -[JsonSerializable(typeof(Modules.Script.RemoteDateValue), TypeInfoPropertyName = "Script_RemoteValue_Date")] -[JsonSerializable(typeof(Modules.Script.RemoteMapValue), TypeInfoPropertyName = "Script_RemoteValue_Map")] -[JsonSerializable(typeof(Modules.Script.RemoteSetValue), TypeInfoPropertyName = "Script_RemoteValue_Set")] -[JsonSerializable(typeof(Modules.Script.RemoteWeakMapValue))] -[JsonSerializable(typeof(Modules.Script.RemoteWeakSetValue))] -[JsonSerializable(typeof(Modules.Script.RemoteGeneratorValue))] -[JsonSerializable(typeof(Modules.Script.RemoteErrorValue))] -[JsonSerializable(typeof(Modules.Script.RemoteProxyValue))] -[JsonSerializable(typeof(Modules.Script.RemotePromiseValue))] -[JsonSerializable(typeof(Modules.Script.RemoteTypedArrayValue))] -[JsonSerializable(typeof(Modules.Script.RemoteArrayBufferValue))] -[JsonSerializable(typeof(Modules.Script.RemoteNodeListValue))] -[JsonSerializable(typeof(Modules.Script.RemoteHtmlCollectionValue))] -[JsonSerializable(typeof(Modules.Script.RemoteNodeValue))] -[JsonSerializable(typeof(Modules.Script.RemoteWindowProxyValue))] +[JsonSerializable(typeof(Modules.Script.NumberRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Number")] +[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Boolean")] +[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_BigInt")] +[JsonSerializable(typeof(Modules.Script.StringRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_String")] +[JsonSerializable(typeof(Modules.Script.NullRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Null")] +[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Undefined")] +[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue))] +[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Array")] +[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Object")] +[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue))] +[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp")] +[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")] +[JsonSerializable(typeof(Modules.Script.DateRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Date")] +[JsonSerializable(typeof(Modules.Script.MapRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Map")] +[JsonSerializable(typeof(Modules.Script.SetRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Set")] +[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 0c409c872f108..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 a216f68e95879..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,37 +33,37 @@ internal class RemoteValueConverter : JsonConverter if (jsonDocument.RootElement.ValueKind == JsonValueKind.String) { - return 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), - "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), + "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 491e85af25d82..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.RemoteNodeValue 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 53dcc39c0b867..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 RemoteNodeValue? 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 d73fbec7ac24c..d75a4efc0aab4 100644 --- a/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs +++ b/dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs @@ -27,35 +27,35 @@ namespace OpenQA.Selenium.BiDi.Modules.Script; // https://github.com/dotnet/runtime/issues/72604 //[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] -//[JsonDerivedType(typeof(RemoteNumberValue), "number")] -//[JsonDerivedType(typeof(RemoteBooleanValue), "boolean")] -//[JsonDerivedType(typeof(RemoteBigIntValue), "bigint")] -//[JsonDerivedType(typeof(RemoteStringValue), "string")] -//[JsonDerivedType(typeof(RemoteNullValue), "null")] -//[JsonDerivedType(typeof(RemoteUndefinedValue), "undefined")] -//[JsonDerivedType(typeof(RemoteSymbolValue), "symbol")] -//[JsonDerivedType(typeof(RemoteArrayValue), "array")] -//[JsonDerivedType(typeof(RemoteObjectValue), "object")] -//[JsonDerivedType(typeof(RemoteFunctionValue), "function")] -//[JsonDerivedType(typeof(RemoteRegExpValue), "regexp")] -//[JsonDerivedType(typeof(RemoteDateValue), "date")] -//[JsonDerivedType(typeof(RemoteMapValue), "map")] -//[JsonDerivedType(typeof(RemoteSetValue), "set")] -//[JsonDerivedType(typeof(RemoteWeakMapValue), "weakmap")] -//[JsonDerivedType(typeof(RemoteWeakSetValue), "weakset")] -//[JsonDerivedType(typeof(RemoteGeneratorValue), "generator")] -//[JsonDerivedType(typeof(RemoteErrorValue), "error")] -//[JsonDerivedType(typeof(RemoteProxyValue), "proxy")] -//[JsonDerivedType(typeof(RemotePromiseValue), "promise")] -//[JsonDerivedType(typeof(RemoteTypedArrayValue), "typedarray")] -//[JsonDerivedType(typeof(RemoteArrayBufferValue), "arraybuffer")] -//[JsonDerivedType(typeof(RemoteNodeListValue), "nodelist")] -//[JsonDerivedType(typeof(RemoteHtmlCollectionValue), "htmlcollection")] -//[JsonDerivedType(typeof(RemoteNodeValue), "node")] -//[JsonDerivedType(typeof(RemoteWindowProxyValue), "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 double(RemoteValue remoteValue) => (double)((RemoteNumberValue)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; @@ -64,8 +64,8 @@ public abstract record RemoteValue { return remoteValue switch { - RemoteStringValue stringValue => stringValue.Value, - RemoteNullValue => null, + StringRemoteValue stringValue => stringValue.Value, + NullRemoteValue => null, _ => throw new InvalidCastException($"Cannot convert {remoteValue} to string") }; } @@ -77,15 +77,15 @@ public abstract record RemoteValue if (type == typeof(bool)) { - return (TResult)(Convert.ToBoolean(((RemoteBooleanValue)this).Value) as object); + return (TResult)(Convert.ToBoolean(((BooleanRemoteValue)this).Value) as object); } if (type == typeof(int)) { - return (TResult)(Convert.ToInt32(((RemoteNumberValue)this).Value) as object); + return (TResult)(Convert.ToInt32(((NumberRemoteValue)this).Value) as object); } else if (type == typeof(string)) { - return (TResult)(((RemoteStringValue)this).Value as object); + return (TResult)(((StringRemoteValue)this).Value as object); } else if (type is object) { @@ -97,26 +97,26 @@ public abstract record RemoteValue } } -public record RemoteNumberValue(double Value) : PrimitiveProtocolRemoteValue; +public record NumberRemoteValue(double Value) : PrimitiveProtocolRemoteValue; -public record RemoteBooleanValue(bool Value) : PrimitiveProtocolRemoteValue; +public record BooleanRemoteValue(bool Value) : PrimitiveProtocolRemoteValue; -public record RemoteBigIntValue(string Value) : PrimitiveProtocolRemoteValue; +public record BigIntRemoteValue(string Value) : PrimitiveProtocolRemoteValue; -public record RemoteStringValue(string Value) : PrimitiveProtocolRemoteValue; +public record StringRemoteValue(string Value) : PrimitiveProtocolRemoteValue; -public record RemoteNullValue : PrimitiveProtocolRemoteValue; +public record NullRemoteValue : PrimitiveProtocolRemoteValue; -public record RemoteUndefinedValue : PrimitiveProtocolRemoteValue; +public record UndefinedRemoteValue : PrimitiveProtocolRemoteValue; -public record RemoteSymbolValue : RemoteValue +public record SymbolRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteArrayValue : RemoteValue +public record ArrayRemoteValue : RemoteValue { public Handle? Handle { get; set; } @@ -125,7 +125,7 @@ public record RemoteArrayValue : RemoteValue public IReadOnlyList? Value { get; set; } } -public record RemoteObjectValue : RemoteValue +public record ObjectRemoteValue : RemoteValue { public Handle? Handle { get; set; } @@ -134,14 +134,14 @@ public record RemoteObjectValue : RemoteValue public IReadOnlyList>? Value { get; set; } } -public record RemoteFunctionValue : RemoteValue +public record FunctionRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteRegExpValue(RemoteRegExpValue.RegExpValue Value) : RemoteValue +public record RegExpRemoteValue(RegExpRemoteValue.RegExpValue Value) : RemoteValue { public Handle? Handle { get; set; } @@ -153,14 +153,14 @@ public record RegExpValue(string Pattern) } } -public record RemoteDateValue(string Value) : RemoteValue +public record DateRemoteValue(string Value) : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteMapValue : RemoteValue +public record MapRemoteValue : RemoteValue { public Handle? Handle { get; set; } @@ -169,7 +169,7 @@ public record RemoteMapValue : RemoteValue public IReadOnlyList>? Value { get; set; } } -public record RemoteSetValue : RemoteValue +public record SetRemoteValue : RemoteValue { public Handle? Handle { get; set; } @@ -178,63 +178,63 @@ public record RemoteSetValue : RemoteValue public IReadOnlyList? Value { get; set; } } -public record RemoteWeakMapValue : RemoteValue +public record WeakMapRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteWeakSetValue : RemoteValue +public record WeakSetRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteGeneratorValue : RemoteValue +public record GeneratorRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteErrorValue : RemoteValue +public record ErrorRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteProxyValue : RemoteValue +public record ProxyRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemotePromiseValue : RemoteValue +public record PromiseRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteTypedArrayValue : RemoteValue +public record TypedArrayRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteArrayBufferValue : RemoteValue +public record ArrayBufferRemoteValue : RemoteValue { public Handle? Handle { get; set; } public InternalId? InternalId { get; set; } } -public record RemoteNodeListValue : RemoteValue +public record NodeListRemoteValue : RemoteValue { public Handle? Handle { get; set; } @@ -243,7 +243,7 @@ public record RemoteNodeListValue : RemoteValue public IReadOnlyList? Value { get; set; } } -public record RemoteHtmlCollectionValue : RemoteValue +public record HtmlCollectionRemoteValue : RemoteValue { public Handle? Handle { get; set; } @@ -252,7 +252,7 @@ public record RemoteHtmlCollectionValue : RemoteValue public IReadOnlyList? Value { get; set; } } -public record RemoteNodeValue : RemoteValue, ISharedReference +public record NodeRemoteValue : RemoteValue, ISharedReference { [JsonInclude] public string? SharedId { get; internal set; } @@ -265,7 +265,7 @@ public record RemoteNodeValue : RemoteValue, ISharedReference public NodeProperties? Value { get; internal set; } } -public record RemoteWindowProxyValue(RemoteWindowProxyValue.Properties Value) : RemoteValue +public record WindowProxyRemoteValue(WindowProxyRemoteValue.Properties Value) : RemoteValue { public Handle? Handle { get; set; } diff --git a/dotnet/test/common/BiDi/Log/LogTest.cs b/dotnet/test/common/BiDi/Log/LogTest.cs index f70c37940012f..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 dec93092e0f73..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 RemoteNumberValue).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 RemoteArrayValue).Value[0], Is.EqualTo("abc")); - Assert.That((int)(res.Result as RemoteArrayValue).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 RemoteWindowProxyValue).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 RemoteNodeValue).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 RemoteObjectValue).Handle, Is.Not.Null); - Assert.That((string)(res.Result as RemoteObjectValue).Value[0][0], Is.EqualTo("a")); - Assert.That((int)(res.Result as RemoteObjectValue).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 RemoteObjectValue).Handle, Is.Null); - Assert.That((string)(res.Result as RemoteObjectValue).Value[0][0], Is.EqualTo("a")); - Assert.That((int)(res.Result as RemoteObjectValue).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 RemoteNumberValue).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 ea7bebe6df275..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(((RemoteBooleanValue)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(((RemoteBooleanValue)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(((RemoteStringValue)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(((RemoteStringValue)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 RemoteDateValue(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 RemoteDateValue(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(((RemoteNumberValue)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(((RemoteNumberValue)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(((RemoteNumberValue)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 = ((RemoteNumberValue)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 = ((RemoteNumberValue)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 = ((RemoteNumberValue)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 = ((RemoteNumberValue)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 RemoteRegExpValue(new RemoteRegExpValue.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 RemoteArrayValue { Value = [new RemoteStringValue("hi")] }; - Assert.That(response.Result, Is.AssignableTo()); - Assert.That(((RemoteArrayValue)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 RemoteObjectValue + var expected = new ObjectRemoteValue { - Value = [[new RemoteStringValue("objKey"), new RemoteStringValue("objValue")]] + Value = [[new StringRemoteValue("objKey"), new StringRemoteValue("objValue")]] }; - Assert.That(((RemoteObjectValue)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 RemoteMapValue + var expected = new MapRemoteValue { - Value = [[new RemoteStringValue("mapKey"), new RemoteStringValue("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(((RemoteMapValue)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 RemoteSetValue { Value = [new RemoteStringValue("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(((RemoteSetValue)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 7bc0f840d3d82..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 RemoteNumberValue).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 RemoteObjectValue).Handle, Is.Not.Null); - Assert.That((string)(res.Result as RemoteObjectValue).Value[0][0], Is.EqualTo("a")); - Assert.That((int)(res.Result as RemoteObjectValue).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 RemoteNumberValue).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 e26a74d55e9d1..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()); } } From 49a0437d0c66392fe4176ae996d7837b1abb4f78 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Sat, 15 Mar 2025 12:27:09 -0400 Subject: [PATCH 5/6] Align `TypeInfoPropertyName` on remote value types --- .../Json/BiDiJsonSerializerContext.cs | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index e0efdade35d1b..d6d8dbfef9305 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -30,33 +30,33 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))] [JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))] -[JsonSerializable(typeof(Modules.Script.NumberRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Number")] -[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Boolean")] -[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_BigInt")] -[JsonSerializable(typeof(Modules.Script.StringRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_String")] -[JsonSerializable(typeof(Modules.Script.NullRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Null")] -[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Undefined")] -[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue))] -[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Array")] -[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Object")] -[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue))] -[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp")] -[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue.RegExpValue), TypeInfoPropertyName = "Script_RemoteValue_RegExp_RegExpValue")] -[JsonSerializable(typeof(Modules.Script.DateRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Date")] -[JsonSerializable(typeof(Modules.Script.MapRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Map")] -[JsonSerializable(typeof(Modules.Script.SetRemoteValue), TypeInfoPropertyName = "Script_RemoteValue_Set")] -[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.NumberRemoteValue), TypeInfoPropertyName = "Script_NumberRemoteValue")] +[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue), TypeInfoPropertyName = "Script_BooleanRemoteValue")] +[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue), TypeInfoPropertyName = "Script_BigIntRemoteValue")] +[JsonSerializable(typeof(Modules.Script.StringRemoteValue), TypeInfoPropertyName = "Script_StringRemoteValue")] +[JsonSerializable(typeof(Modules.Script.NullRemoteValue), TypeInfoPropertyName = "Script_NullRemoteValue")] +[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue), TypeInfoPropertyName = "Script_UndefinedRemoteValue")] +[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue), TypeInfoPropertyName = "Script_SymbolRemoteValue")] +[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue), TypeInfoPropertyName = "Script_ArrayRemoteValue")] +[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue), TypeInfoPropertyName = "Script_ObjectRemoteValue")] +[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue), TypeInfoPropertyName = "Script_FunctionRemoteValue")] +[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue), TypeInfoPropertyName = "Script_RegExpRemoteValue")] +[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue.RegExpValue), TypeInfoPropertyName = "Script_RegExpRemoteValue_RegExpValue")] +[JsonSerializable(typeof(Modules.Script.DateRemoteValue), TypeInfoPropertyName = "Script_DateRemoteValue")] +[JsonSerializable(typeof(Modules.Script.MapRemoteValue), TypeInfoPropertyName = "Script_MapRemoteValue")] +[JsonSerializable(typeof(Modules.Script.SetRemoteValue), TypeInfoPropertyName = "Script_SetRemoteValue")] +[JsonSerializable(typeof(Modules.Script.WeakMapRemoteValue), TypeInfoPropertyName = "Script_WeakMapRemoteValue")] +[JsonSerializable(typeof(Modules.Script.WeakSetRemoteValue), TypeInfoPropertyName = "Script_WeakSetRemoteValue")] +[JsonSerializable(typeof(Modules.Script.GeneratorRemoteValue), TypeInfoPropertyName = "Script_GeneratorRemoteValue")] +[JsonSerializable(typeof(Modules.Script.ErrorRemoteValue), TypeInfoPropertyName = "Script_ErrorRemoteValue")] +[JsonSerializable(typeof(Modules.Script.ProxyRemoteValue), TypeInfoPropertyName = "Script_ProxyRemoteValue")] +[JsonSerializable(typeof(Modules.Script.PromiseRemoteValue), TypeInfoPropertyName = "Script_PromiseRemoteValue")] +[JsonSerializable(typeof(Modules.Script.TypedArrayRemoteValue), TypeInfoPropertyName = "Script_TypedArrayRemoteValue")] +[JsonSerializable(typeof(Modules.Script.ArrayBufferRemoteValue), TypeInfoPropertyName = "Script_ArrayBufferRemoteValue")] +[JsonSerializable(typeof(Modules.Script.NodeListRemoteValue), TypeInfoPropertyName = "Script_NodeListRemoteValue")] +[JsonSerializable(typeof(Modules.Script.HtmlCollectionRemoteValue), TypeInfoPropertyName = "Script_HtmlCollectionRemoteValue")] +[JsonSerializable(typeof(Modules.Script.NodeRemoteValue), TypeInfoPropertyName = "Script_NodeRemoteValue")] +[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue), TypeInfoPropertyName = "Script_WindowProxyRemoteValue")] [JsonSerializable(typeof(Modules.Script.RealmInfo.Window))] [JsonSerializable(typeof(Modules.Script.RealmInfo.DedicatedWorker))] From 2e062f007c3d3c8906d4d07a4bd763a310b9d339 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Sun, 16 Mar 2025 13:52:25 +0300 Subject: [PATCH 6/6] Remove TypeInfoPropertyName --- .../Json/BiDiJsonSerializerContext.cs | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index d6d8dbfef9305..ed1e8e0347788 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -30,33 +30,33 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(Modules.Script.EvaluateResult.Success))] [JsonSerializable(typeof(Modules.Script.EvaluateResult.Exception))] -[JsonSerializable(typeof(Modules.Script.NumberRemoteValue), TypeInfoPropertyName = "Script_NumberRemoteValue")] -[JsonSerializable(typeof(Modules.Script.BooleanRemoteValue), TypeInfoPropertyName = "Script_BooleanRemoteValue")] -[JsonSerializable(typeof(Modules.Script.BigIntRemoteValue), TypeInfoPropertyName = "Script_BigIntRemoteValue")] -[JsonSerializable(typeof(Modules.Script.StringRemoteValue), TypeInfoPropertyName = "Script_StringRemoteValue")] -[JsonSerializable(typeof(Modules.Script.NullRemoteValue), TypeInfoPropertyName = "Script_NullRemoteValue")] -[JsonSerializable(typeof(Modules.Script.UndefinedRemoteValue), TypeInfoPropertyName = "Script_UndefinedRemoteValue")] -[JsonSerializable(typeof(Modules.Script.SymbolRemoteValue), TypeInfoPropertyName = "Script_SymbolRemoteValue")] -[JsonSerializable(typeof(Modules.Script.ArrayRemoteValue), TypeInfoPropertyName = "Script_ArrayRemoteValue")] -[JsonSerializable(typeof(Modules.Script.ObjectRemoteValue), TypeInfoPropertyName = "Script_ObjectRemoteValue")] -[JsonSerializable(typeof(Modules.Script.FunctionRemoteValue), TypeInfoPropertyName = "Script_FunctionRemoteValue")] -[JsonSerializable(typeof(Modules.Script.RegExpRemoteValue), TypeInfoPropertyName = "Script_RegExpRemoteValue")] +[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), TypeInfoPropertyName = "Script_DateRemoteValue")] -[JsonSerializable(typeof(Modules.Script.MapRemoteValue), TypeInfoPropertyName = "Script_MapRemoteValue")] -[JsonSerializable(typeof(Modules.Script.SetRemoteValue), TypeInfoPropertyName = "Script_SetRemoteValue")] -[JsonSerializable(typeof(Modules.Script.WeakMapRemoteValue), TypeInfoPropertyName = "Script_WeakMapRemoteValue")] -[JsonSerializable(typeof(Modules.Script.WeakSetRemoteValue), TypeInfoPropertyName = "Script_WeakSetRemoteValue")] -[JsonSerializable(typeof(Modules.Script.GeneratorRemoteValue), TypeInfoPropertyName = "Script_GeneratorRemoteValue")] -[JsonSerializable(typeof(Modules.Script.ErrorRemoteValue), TypeInfoPropertyName = "Script_ErrorRemoteValue")] -[JsonSerializable(typeof(Modules.Script.ProxyRemoteValue), TypeInfoPropertyName = "Script_ProxyRemoteValue")] -[JsonSerializable(typeof(Modules.Script.PromiseRemoteValue), TypeInfoPropertyName = "Script_PromiseRemoteValue")] -[JsonSerializable(typeof(Modules.Script.TypedArrayRemoteValue), TypeInfoPropertyName = "Script_TypedArrayRemoteValue")] -[JsonSerializable(typeof(Modules.Script.ArrayBufferRemoteValue), TypeInfoPropertyName = "Script_ArrayBufferRemoteValue")] -[JsonSerializable(typeof(Modules.Script.NodeListRemoteValue), TypeInfoPropertyName = "Script_NodeListRemoteValue")] -[JsonSerializable(typeof(Modules.Script.HtmlCollectionRemoteValue), TypeInfoPropertyName = "Script_HtmlCollectionRemoteValue")] -[JsonSerializable(typeof(Modules.Script.NodeRemoteValue), TypeInfoPropertyName = "Script_NodeRemoteValue")] -[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue), TypeInfoPropertyName = "Script_WindowProxyRemoteValue")] +[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))]