Skip to content

[dotnet] [bidi] Make UrlPattern as not nested #15434

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

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 @@ -122,7 +122,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
[JsonSerializable(typeof(Modules.BrowsingContext.Origin), TypeInfoPropertyName = "BrowsingContext_Origin")]

[JsonSerializable(typeof(Modules.Network.BytesValue.String), TypeInfoPropertyName = "Network_BytesValue_String")]
[JsonSerializable(typeof(Modules.Network.UrlPattern.String), TypeInfoPropertyName = "Network_UrlPattern_String")]
[JsonSerializable(typeof(Modules.Network.ContinueWithAuthParameters.Default), TypeInfoPropertyName = "Network_ContinueWithAuthParameters_Default")]
[JsonSerializable(typeof(Modules.Network.AddInterceptCommand))]
[JsonSerializable(typeof(Modules.Network.AddInterceptResult))]
Expand Down
29 changes: 13 additions & 16 deletions dotnet/src/webdriver/BiDi/Modules/Network/UrlPattern.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,24 @@
namespace OpenQA.Selenium.BiDi.Modules.Network;

[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
[JsonDerivedType(typeof(Pattern), "pattern")]
[JsonDerivedType(typeof(String), "string")]
[JsonDerivedType(typeof(PatternUrlPattern), "pattern")]
[JsonDerivedType(typeof(StringUrlPattern), "string")]
public abstract record UrlPattern
{
public static implicit operator UrlPattern(string value) => new String(value);

public record Pattern : UrlPattern
{
public string? Protocol { get; set; }
public static implicit operator UrlPattern(string value) => new StringUrlPattern(value);
}

public string? Hostname { get; set; }
public record PatternUrlPattern : UrlPattern
{
public string? Protocol { get; set; }

public string? Port { get; set; }
public string? Hostname { get; set; }

public string? Pathname { get; set; }
public string? Port { get; set; }

public string? Search { get; set; }
}
public string? Pathname { get; set; }

public record String(string Pattern) : UrlPattern
{
public new string Pattern { get; } = Pattern;
}
public string? Search { get; set; }
}

public record StringUrlPattern(string Pattern) : UrlPattern;
4 changes: 2 additions & 2 deletions dotnet/test/common/BiDi/Network/NetworkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task CanAddInterceptStringUrlPattern()
await using var intercept = await bidi.Network.InterceptRequestAsync(e => Task.CompletedTask, new()
{
UrlPatterns = [
new UrlPattern.String("http://localhost:4444"),
new StringUrlPattern("http://localhost:4444"),
"http://localhost:4444/"
]
});
Expand All @@ -53,7 +53,7 @@ public async Task CanAddInterceptUrlPattern()
{
await using var intercept = await bidi.Network.InterceptRequestAsync(e => Task.CompletedTask, interceptOptions: new()
{
UrlPatterns = [new UrlPattern.Pattern()
UrlPatterns = [new PatternUrlPattern()
{
Hostname = "localhost",
Protocol = "http"
Expand Down
Loading