Skip to content

Commit f3361c3

Browse files
authored
[dotnet] [bidi] Make LogEntry as not nested (#15432)
1 parent 01c0ef4 commit f3361c3

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
6666
[JsonSerializable(typeof(Modules.Script.RealmInfo.AudioWorklet))]
6767
[JsonSerializable(typeof(Modules.Script.RealmInfo.Worklet))]
6868

69-
[JsonSerializable(typeof(Modules.Log.Entry.Console))]
70-
[JsonSerializable(typeof(Modules.Log.Entry.Javascript))]
69+
[JsonSerializable(typeof(Modules.Log.ConsoleLogEntry))]
70+
[JsonSerializable(typeof(Modules.Log.JavascriptLogEntry))]
7171
#endregion
7272

7373
[JsonSerializable(typeof(Command))]
@@ -153,7 +153,7 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
153153
[JsonSerializable(typeof(Modules.Script.RealmDestroyedEventArgs))]
154154
[JsonSerializable(typeof(IReadOnlyList<Modules.Script.RealmInfo>))]
155155

156-
[JsonSerializable(typeof(Modules.Log.Entry))]
156+
[JsonSerializable(typeof(Modules.Log.LogEntry))]
157157

158158
[JsonSerializable(typeof(Modules.Storage.GetCookiesCommand))]
159159
[JsonSerializable(typeof(Modules.Storage.GetCookiesResult))]

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@
2525
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Polymorphic;
2626

2727
// https://github.com/dotnet/runtime/issues/72604
28-
internal class LogEntryConverter : JsonConverter<Modules.Log.Entry>
28+
internal class LogEntryConverter : JsonConverter<Modules.Log.LogEntry>
2929
{
30-
public override Modules.Log.Entry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
30+
public override Modules.Log.LogEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3131
{
3232
var jsonDocument = JsonDocument.ParseValue(ref reader);
3333

3434
return jsonDocument.RootElement.GetProperty("type").ToString() switch
3535
{
36-
"console" => jsonDocument.Deserialize<Modules.Log.Entry.Console>(options),
37-
"javascript" => jsonDocument.Deserialize<Modules.Log.Entry.Javascript>(options),
36+
"console" => jsonDocument.Deserialize<ConsoleLogEntry>(options),
37+
"javascript" => jsonDocument.Deserialize<JavascriptLogEntry>(options),
3838
_ => null,
3939
};
4040
}
4141

42-
public override void Write(Utf8JsonWriter writer, Modules.Log.Entry value, JsonSerializerOptions options)
42+
public override void Write(Utf8JsonWriter writer, Modules.Log.LogEntry value, JsonSerializerOptions options)
4343
{
4444
throw new NotImplementedException();
4545
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace OpenQA.Selenium.BiDi.Modules.BrowsingContext;
2525

2626
public class BrowsingContextLogModule(BrowsingContext context, LogModule logModule)
2727
{
28-
public Task<Subscription> OnEntryAddedAsync(Func<Entry, Task> handler, SubscriptionOptions? options = null)
28+
public Task<Subscription> OnEntryAddedAsync(Func<Log.LogEntry, Task> handler, SubscriptionOptions? options = null)
2929
{
3030
return logModule.OnEntryAddedAsync(async args =>
3131
{
@@ -36,7 +36,7 @@ public Task<Subscription> OnEntryAddedAsync(Func<Entry, Task> handler, Subscript
3636
}, options);
3737
}
3838

39-
public Task<Subscription> OnEntryAddedAsync(Action<Entry> handler, SubscriptionOptions? options = null)
39+
public Task<Subscription> OnEntryAddedAsync(Action<Log.LogEntry> handler, SubscriptionOptions? options = null)
4040
{
4141
return logModule.OnEntryAddedAsync(args =>
4242
{

dotnet/src/webdriver/BiDi/Modules/Log/Entry.cs dotnet/src/webdriver/BiDi/Modules/Log/LogEntry.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="Entry.cs" company="Selenium Committers">
1+
// <copyright file="LogEntry.cs" company="Selenium Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -24,19 +24,19 @@ namespace OpenQA.Selenium.BiDi.Modules.Log;
2424

2525
// https://github.com/dotnet/runtime/issues/72604
2626
//[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
27-
//[JsonDerivedType(typeof(Console), "console")]
28-
//[JsonDerivedType(typeof(Javascript), "javascript")]
29-
public abstract record Entry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
27+
//[JsonDerivedType(typeof(ConsoleLogEntry), "console")]
28+
//[JsonDerivedType(typeof(JavascriptLogEntry), "javascript")]
29+
public abstract record LogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
3030
: EventArgs(BiDi)
3131
{
3232
public Script.StackTrace? StackTrace { get; set; }
33+
}
3334

34-
public record Console(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList<Script.RemoteValue> Args)
35-
: Entry(BiDi, Level, Source, Text, Timestamp);
35+
public record ConsoleLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp, string Method, IReadOnlyList<Script.RemoteValue> Args)
36+
: LogEntry(BiDi, Level, Source, Text, Timestamp);
3637

37-
public record Javascript(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
38-
: Entry(BiDi, Level, Source, Text, Timestamp);
39-
}
38+
public record JavascriptLogEntry(BiDi BiDi, Level Level, Script.Source Source, string Text, DateTimeOffset Timestamp)
39+
: LogEntry(BiDi, Level, Source, Text, Timestamp);
4040

4141
public enum Level
4242
{

dotnet/src/webdriver/BiDi/Modules/Log/LogModule.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ namespace OpenQA.Selenium.BiDi.Modules.Log;
2525

2626
public sealed class LogModule(Broker broker) : Module(broker)
2727
{
28-
public async Task<Subscription> OnEntryAddedAsync(Func<Entry, Task> handler, SubscriptionOptions? options = null)
28+
public async Task<Subscription> OnEntryAddedAsync(Func<LogEntry, Task> handler, SubscriptionOptions? options = null)
2929
{
3030
return await Broker.SubscribeAsync("log.entryAdded", handler, options).ConfigureAwait(false);
3131
}
3232

33-
public async Task<Subscription> OnEntryAddedAsync(Action<Entry> handler, SubscriptionOptions? options = null)
33+
public async Task<Subscription> OnEntryAddedAsync(Action<LogEntry> handler, SubscriptionOptions? options = null)
3434
{
3535
return await Broker.SubscribeAsync("log.entryAdded", handler, options).ConfigureAwait(false);
3636
}

dotnet/test/common/BiDi/Log/LogTest.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LogTest : BiDiTestFixture
2929
[Test]
3030
public async Task CanListenToConsoleLog()
3131
{
32-
TaskCompletionSource<Entry> tcs = new();
32+
TaskCompletionSource<Modules.Log.LogEntry> tcs = new();
3333

3434
await using var subscription = await context.Log.OnEntryAddedAsync(tcs.SetResult);
3535

@@ -44,9 +44,9 @@ public async Task CanListenToConsoleLog()
4444
Assert.That(logEntry.Source.Realm, Is.Not.Null);
4545
Assert.That(logEntry.Text, Is.EqualTo("Hello, world!"));
4646
Assert.That(logEntry.Level, Is.EqualTo(Level.Info));
47-
Assert.That(logEntry, Is.AssignableFrom<Entry.Console>());
47+
Assert.That(logEntry, Is.AssignableFrom<ConsoleLogEntry>());
4848

49-
var consoleLogEntry = logEntry as Entry.Console;
49+
var consoleLogEntry = logEntry as ConsoleLogEntry;
5050

5151
Assert.That(consoleLogEntry.Method, Is.EqualTo("log"));
5252

@@ -58,7 +58,7 @@ public async Task CanListenToConsoleLog()
5858
[Test]
5959
public async Task CanListenToJavascriptLog()
6060
{
61-
TaskCompletionSource<Entry> tcs = new();
61+
TaskCompletionSource<Modules.Log.LogEntry> tcs = new();
6262

6363
await using var subscription = await context.Log.OnEntryAddedAsync(tcs.SetResult);
6464

@@ -73,13 +73,13 @@ public async Task CanListenToJavascriptLog()
7373
Assert.That(logEntry.Source.Realm, Is.Not.Null);
7474
Assert.That(logEntry.Text, Is.EqualTo("Error: Not working"));
7575
Assert.That(logEntry.Level, Is.EqualTo(Level.Error));
76-
Assert.That(logEntry, Is.AssignableFrom<Entry.Javascript>());
76+
Assert.That(logEntry, Is.AssignableFrom<JavascriptLogEntry>());
7777
}
7878

7979
[Test]
8080
public async Task CanRetrieveStacktrace()
8181
{
82-
TaskCompletionSource<Entry> tcs = new();
82+
TaskCompletionSource<Modules.Log.LogEntry> tcs = new();
8383

8484
await using var subscription = await bidi.Log.OnEntryAddedAsync(tcs.SetResult);
8585

dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public async Task CanAddPreloadScript()
9393

9494
Assert.That(preloadScript, Is.Not.Null);
9595

96-
TaskCompletionSource<Modules.Log.Entry> tcs = new();
96+
TaskCompletionSource<Modules.Log.LogEntry> tcs = new();
9797

9898
await context.Log.OnEntryAddedAsync(tcs.SetResult);
9999

0 commit comments

Comments
 (0)