Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] [bidi] Make RealmInfo as not nested #15444

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
[JsonSerializable(typeof(Modules.Script.NodeRemoteValue))]
[JsonSerializable(typeof(Modules.Script.WindowProxyRemoteValue))]

[JsonSerializable(typeof(Modules.Script.RealmInfo.Window))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.DedicatedWorker))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.SharedWorker))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.ServiceWorker))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.Worker))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.PaintWorklet))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.AudioWorklet))]
[JsonSerializable(typeof(Modules.Script.RealmInfo.Worklet))]
[JsonSerializable(typeof(Modules.Script.WindowRealmInfo))]
[JsonSerializable(typeof(Modules.Script.DedicatedWorkerRealmInfo))]
[JsonSerializable(typeof(Modules.Script.SharedWorkerRealmInfo))]
[JsonSerializable(typeof(Modules.Script.ServiceWorkerRealmInfo))]
[JsonSerializable(typeof(Modules.Script.WorkerRealmInfo))]
[JsonSerializable(typeof(Modules.Script.PaintWorkletRealmInfo))]
[JsonSerializable(typeof(Modules.Script.AudioWorkletRealmInfo))]
[JsonSerializable(typeof(Modules.Script.WorkletRealmInfo))]

[JsonSerializable(typeof(Modules.Log.ConsoleLogEntry))]
[JsonSerializable(typeof(Modules.Log.JavascriptLogEntry))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ internal class RealmInfoConverter : JsonConverter<RealmInfo>

return jsonDocument.RootElement.GetProperty("type").ToString() switch
{
"window" => jsonDocument.Deserialize<RealmInfo.Window>(options),
"dedicated-worker" => jsonDocument.Deserialize<RealmInfo.DedicatedWorker>(options),
"shared-worker" => jsonDocument.Deserialize<RealmInfo.SharedWorker>(options),
"service-worker" => jsonDocument.Deserialize<RealmInfo.ServiceWorker>(options),
"worker" => jsonDocument.Deserialize<RealmInfo.Worker>(options),
"paint-worklet" => jsonDocument.Deserialize<RealmInfo.PaintWorklet>(options),
"audio-worklet" => jsonDocument.Deserialize<RealmInfo.AudioWorklet>(options),
"worklet" => jsonDocument.Deserialize<RealmInfo.Worklet>(options),
"window" => jsonDocument.Deserialize<WindowRealmInfo>(options),
"dedicated-worker" => jsonDocument.Deserialize<DedicatedWorkerRealmInfo>(options),
"shared-worker" => jsonDocument.Deserialize<SharedWorkerRealmInfo>(options),
"service-worker" => jsonDocument.Deserialize<ServiceWorkerRealmInfo>(options),
"worker" => jsonDocument.Deserialize<WorkerRealmInfo>(options),
"paint-worklet" => jsonDocument.Deserialize<PaintWorkletRealmInfo>(options),
"audio-worklet" => jsonDocument.Deserialize<AudioWorkletRealmInfo>(options),
"worklet" => jsonDocument.Deserialize<WorkletRealmInfo>(options),
_ => null,
};
}
Expand Down
41 changes: 20 additions & 21 deletions dotnet/src/webdriver/BiDi/Modules/Script/RealmInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,31 @@ namespace OpenQA.Selenium.BiDi.Modules.Script;

// https://github.com/dotnet/runtime/issues/72604
//[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
//[JsonDerivedType(typeof(Window), "window")]
//[JsonDerivedType(typeof(DedicatedWorker), "dedicated-worker")]
//[JsonDerivedType(typeof(SharedWorker), "shared-worker")]
//[JsonDerivedType(typeof(ServiceWorker), "service-worker")]
//[JsonDerivedType(typeof(Worker), "worker")]
//[JsonDerivedType(typeof(PaintWorklet), "paint-worklet")]
//[JsonDerivedType(typeof(AudioWorklet), "audio-worklet")]
//[JsonDerivedType(typeof(Worklet), "worklet")]
public abstract record RealmInfo(BiDi BiDi, Realm Realm, string Origin) : EventArgs(BiDi)
//[JsonDerivedType(typeof(WindowRealmInfo), "window")]
//[JsonDerivedType(typeof(DedicatedWorkerRealmInfo), "dedicated-worker")]
//[JsonDerivedType(typeof(SharedWorkerRealmInfo), "shared-worker")]
//[JsonDerivedType(typeof(ServiceWorkerRealmInfo), "service-worker")]
//[JsonDerivedType(typeof(WorkerRealmInfo), "worker")]
//[JsonDerivedType(typeof(PaintWorkletRealmInfo), "paint-worklet")]
//[JsonDerivedType(typeof(AudioWorkletRealmInfo), "audio-worklet")]
//[JsonDerivedType(typeof(WorkletRealmInfo), "worklet")]
public abstract record RealmInfo(BiDi BiDi, Realm Realm, string Origin) : EventArgs(BiDi);

public record WindowRealmInfo(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : RealmInfo(BiDi, Realm, Origin)
{
public record Window(BiDi BiDi, Realm Realm, string Origin, BrowsingContext.BrowsingContext Context) : RealmInfo(BiDi, Realm, Origin)
{
public string? Sandbox { get; set; }
}
public string? Sandbox { get; set; }
}

public record DedicatedWorker(BiDi BiDi, Realm Realm, string Origin, IReadOnlyList<Realm> Owners) : RealmInfo(BiDi, Realm, Origin);
public record DedicatedWorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin, IReadOnlyList<Realm> Owners) : RealmInfo(BiDi, Realm, Origin);

public record SharedWorker(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
public record SharedWorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);

public record ServiceWorker(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
public record ServiceWorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);

public record Worker(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
public record WorkerRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);

public record PaintWorklet(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
public record PaintWorkletRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);

public record AudioWorklet(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
public record AudioWorkletRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);

public record Worklet(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
}
public record WorkletRealmInfo(BiDi BiDi, Realm Realm, string Origin) : RealmInfo(BiDi, Realm, Origin);
12 changes: 6 additions & 6 deletions dotnet/test/common/BiDi/Script/ScriptCommandsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public async Task CanGetAllRealms()
Assert.That(realms, Is.Not.Null);
Assert.That(realms, Has.Count.EqualTo(2));

Assert.That(realms[0], Is.AssignableFrom<RealmInfo.Window>());
Assert.That(realms[0], Is.AssignableFrom<WindowRealmInfo>());
Assert.That(realms[0].Realm, Is.Not.Null);

Assert.That(realms[1], Is.AssignableFrom<RealmInfo.Window>());
Assert.That(realms[1], Is.AssignableFrom<WindowRealmInfo>());
Assert.That(realms[1].Realm, Is.Not.Null);
}

Expand All @@ -53,10 +53,10 @@ public async Task CanGetAllRealmsByType()
Assert.That(realms, Is.Not.Null);
Assert.That(realms, Has.Count.EqualTo(2));

Assert.That(realms[0], Is.AssignableFrom<RealmInfo.Window>());
Assert.That(realms[0], Is.AssignableFrom<WindowRealmInfo>());
Assert.That(realms[0].Realm, Is.Not.Null);

Assert.That(realms[1], Is.AssignableFrom<RealmInfo.Window>());
Assert.That(realms[1], Is.AssignableFrom<WindowRealmInfo>());
Assert.That(realms[1].Realm, Is.Not.Null);
}

Expand All @@ -67,7 +67,7 @@ public async Task CanGetRealmInBrowsingContext()

var realms = await tab.Script.GetRealmsAsync();

var tabRealm = realms[0] as RealmInfo.Window;
var tabRealm = realms[0] as WindowRealmInfo;

Assert.That(tabRealm, Is.Not.Null);
Assert.That(tabRealm.Context, Is.EqualTo(tab));
Expand All @@ -80,7 +80,7 @@ public async Task CanGetRealmInBrowsingContextByType()

var realms = await tab.Script.GetRealmsAsync(new() { Type = RealmType.Window });

var tabRealm = realms[0] as RealmInfo.Window;
var tabRealm = realms[0] as WindowRealmInfo;

Assert.That(tabRealm, Is.Not.Null);
Assert.That(tabRealm.Context, Is.EqualTo(tab));
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/BiDi/Script/ScriptEventsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task CanListenToRealmCreatedEvent()
var realmInfo = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));

Assert.That(realmInfo, Is.Not.Null);
Assert.That(realmInfo, Is.AssignableFrom<RealmInfo.Window>());
Assert.That(realmInfo, Is.AssignableFrom<WindowRealmInfo>());
Assert.That(realmInfo.Realm, Is.Not.Null);
}

Expand Down
Loading