Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ae2d622
[dotnet] Align `Scipt.LocalValue.Map` with spec
RenderMichael Mar 9, 2025
bd5aedc
Add test for Set
RenderMichael Mar 9, 2025
50f28b5
Remove obsolete assertion
RenderMichael Mar 9, 2025
9db00ab
Update new test name
RenderMichael Mar 9, 2025
d36e44e
Fix build
RenderMichael Mar 9, 2025
7e279bc
Replace TestCaseSource with individual tests
RenderMichael Mar 9, 2025
a91685b
Allow reading numbers from strings
RenderMichael Mar 9, 2025
83587d8
Separate CallFunction argument and return tests
RenderMichael Mar 10, 2025
9612f5f
Merge branch 'trunk' into bidi-map
RenderMichael Mar 10, 2025
e7a751d
Split tests into more classes
RenderMichael Mar 10, 2025
f51248e
remove unused imports
RenderMichael Mar 10, 2025
5c0f772
Properly serialize negative zero
RenderMichael Mar 10, 2025
d7c58f7
Fix variable name
RenderMichael Mar 10, 2025
45ecae9
fix formatting
RenderMichael Mar 10, 2025
0d8f906
Apply double converter directly to `RemoteValue.Number`
RenderMichael Mar 11, 2025
53310f7
Rename and clean up `DoubleConverter`
RenderMichael Mar 11, 2025
98cafd1
Clarify "is negative zero" check
RenderMichael Mar 11, 2025
6627a82
Merge branch 'trunk' into bidi-map
RenderMichael Mar 11, 2025
6c9c303
fix formatting
RenderMichael Mar 11, 2025
50abe67
Remove `BiDiDoubleConverter`
RenderMichael Mar 12, 2025
79b9274
Ignore failing tests
RenderMichael Mar 12, 2025
0a8d550
fix which tet is disabled
RenderMichael Mar 12, 2025
f2a615e
PR feedback
RenderMichael Mar 12, 2025
8c36bb2
PR feedback
RenderMichael Mar 12, 2025
034b533
Merge branch 'trunk' into bidi-map
RenderMichael Mar 12, 2025
1a7c7f3
PR test feedback
RenderMichael Mar 12, 2025
f4d3785
Rename local
RenderMichael Mar 12, 2025
d46e10f
fix further
RenderMichael Mar 12, 2025
d5c4954
Avoid magic of records for remote primitives
RenderMichael Mar 13, 2025
c51dc4c
Merge branch 'trunk' into bidi-map
RenderMichael Mar 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dotnet/src/webdriver/BiDi/Communication/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ internal Broker(BiDi bidi, ITransport transport)
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
Converters =
{
new BrowsingContextConverter(_bidi),
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Modules/Script/LocalValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public record Array(IEnumerable<LocalValue> Value) : LocalValue;

public record Date(string Value) : LocalValue;

public record Map(IDictionary<string, LocalValue> Value) : LocalValue; // seems to implement IDictionary
public record Map(IEnumerable<IEnumerable<LocalValue>> Value) : LocalValue;

public record Object(IEnumerable<IEnumerable<LocalValue>> Value) : LocalValue;

Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriver/BiDi/Modules/Script/RemoteValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public record Map : RemoteValue

public InternalId? InternalId { get; set; }

public IDictionary<string, RemoteValue>? Value { get; set; }
public IReadOnlyList<IReadOnlyList<RemoteValue>>? Value { get; set; }
}

public record Set : RemoteValue
Expand Down
153 changes: 153 additions & 0 deletions dotnet/test/common/BiDi/Script/CallFunctionParameterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

using NUnit.Framework;
using OpenQA.Selenium.BiDi.Modules.Script;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;

namespace OpenQA.Selenium.BiDi.Script;
Expand Down Expand Up @@ -219,4 +222,154 @@ public async Task CanCallFunctionInARealm()
Assert.That(res1, Is.EqualTo(3));
Assert.That(res2, Is.EqualTo(5));
}

[Test]
[TestCaseSource(nameof(RoundtripOptions))]
public async Task CanCallFunctionAndRoundtrip_Five(LocalValue local, RemoteValue expected, string javaScriptAssert)
{
var response = await context.Script.CallFunctionAsync($$"""
(arg) => {
if ({{javaScriptAssert}}) {
return arg;
}

throw new Error("Assert failed: " + arg);
}
""", false, new() { Arguments = [local] });

if (response.Result is RemoteValue.Array actualArray && expected is RemoteValue.Array expectedArray)
{
Assert.That(actualArray.Value, Is.EqualTo(expectedArray.Value));
}
else if (response.Result is RemoteValue.Object actualObject && expected is RemoteValue.Object expectedObject)
{
Assert.That(actualObject.Value, Is.EqualTo(expectedObject.Value));
}
else if (response.Result is RemoteValue.Map actualMap && expected is RemoteValue.Map expectedMap)
{
Assert.That(actualMap.Value, Is.EqualTo(expectedMap.Value));
}
else if (response.Result is RemoteValue.Set actualSet && expected is RemoteValue.Set expectedSet)
{
Assert.That(actualSet.Value, Is.EqualTo(expectedSet.Value));
}
else if (response.Result is RemoteValue.Date actualDate && expected is RemoteValue.Date expectedDate)
{
var actualDateParsed = DateTime.SpecifyKind(DateTime.Parse(actualDate.Value, CultureInfo.InvariantCulture), DateTimeKind.Utc);
Assert.That(actualDateParsed, Is.EqualTo(DateTime.Parse(expectedDate.Value)).Within(TimeSpan.FromMilliseconds(1)));
}
else
{
Assert.That(response.Result, Is.EqualTo(expected));
}
}
private const string PinnedDateTimeString = "2025-03-09T00:30:33.083Z";
private static IEnumerable<TestCaseData> RoundtripOptions()
{

yield return new TestCaseData(new LocalValue.Null(), new RemoteValue.Null(), "arg === null")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Null)"
};
yield return new TestCaseData(new LocalValue.Undefined(), new RemoteValue.Undefined(), "typeof arg === 'undefined'")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Undefined)",
};
//yield return new TestCaseData(new LocalValue.Boolean(true), new RemoteValue.Boolean(true), "typeof arg === true")
//{
// TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(true)",
//};
//yield return new TestCaseData(new LocalValue.Boolean(false), new RemoteValue.Boolean(false), "typeof arg === false")
//{
// TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(false)",
//};
yield return new TestCaseData(new LocalValue.String("whoa"), new RemoteValue.String("whoa"), "arg === 'whoa'")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(String('whoa'))",
};
yield return new TestCaseData(new LocalValue.String(string.Empty), new RemoteValue.String(string.Empty), "arg === ''")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(String(''))",
};
yield return new TestCaseData(new LocalValue.Date(PinnedDateTimeString), new RemoteValue.Date(PinnedDateTimeString), $"arg.toISOString() === '{PinnedDateTimeString}'")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Date)",
};
yield return new TestCaseData(new LocalValue.Number(5), new RemoteValue.Number(5), "arg === 5")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Number(5))",
};
yield return new TestCaseData(new LocalValue.Number(0), new RemoteValue.Number(0), "arg === 0")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Number(0))",
};
yield return new TestCaseData(new LocalValue.Number(-5), new RemoteValue.Number(-5), "arg === -5")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Number(-5))",
};
yield return new TestCaseData(new LocalValue.Number(double.PositiveInfinity), new RemoteValue.Number(double.PositiveInfinity), "arg === Number.POSITIVE_INFINITY")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Number(Infinity))",
};
yield return new TestCaseData(new LocalValue.Number(double.NegativeInfinity), new RemoteValue.Number(double.NegativeInfinity), "arg === Number.NEGATIVE_INFINITY")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Number(-Infinity))",
};
yield return new TestCaseData(new LocalValue.Number(double.NegativeZero), new RemoteValue.Number(double.NegativeZero), "arg === -0")
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Number(-0))",
};
yield return new TestCaseData(
new LocalValue.RegExp(new LocalValue.RegExp.RegExpValue("foo*") { Flags = "g" }),
new RemoteValue.RegExp(new RemoteValue.RegExp.RegExpValue("foo*") { Flags = "g" }),
"arg.test('foo') && arg.source === 'foo*' && arg.global"
)
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(RegExp(/foo/g))",
};
yield return new TestCaseData(

new LocalValue.Array([new LocalValue.String("hi")]),
new RemoteValue.Array { Value = [new RemoteValue.String("hi")] },
"arg.length === 1 && arg[0] === 'hi'"
)
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Array(['hi']))",
};
yield return new TestCaseData
(
new LocalValue.Object([[new LocalValue.String("key"), new LocalValue.String("value")]]),
new RemoteValue.Object
{
Value = [[new RemoteValue.String("key"), new RemoteValue.String("value")]]
},
"arg.key === 'value' && Object.keys(arg).length === 1"
)
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Object({key: 'value'}))",
};
yield return new TestCaseData
(
new LocalValue.Map([[new LocalValue.String("key"), new LocalValue.String("value")]]),
new RemoteValue.Map
{
Value = [[new RemoteValue.String("key"), new RemoteValue.String("value")]]
},
"arg.get('key') === 'value' && arg.size === 1"
)
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Map({'key': 'value'}))",
};

yield return new TestCaseData
(
new LocalValue.Set([new LocalValue.String("key")]),
new RemoteValue.Set { Value = [new RemoteValue.String("key")] },
"arg.has('key') && arg.size === 1"
)
{
TestName = nameof(CanCallFunctionAndRoundtrip_Five) + "(Set({'key'}))",

};
}
}
Loading