Skip to content

Commit

Permalink
Merge branch 'trunk' into async-http-client
Browse files Browse the repository at this point in the history
  • Loading branch information
VietND96 authored Oct 29, 2024
2 parents 86fc08a + f391cd0 commit f83ad29
Show file tree
Hide file tree
Showing 206 changed files with 4,229 additions and 1,444 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ maven.install(
"com.github.spotbugs:spotbugs:4.8.6",
"com.github.stephenc.jcip:jcip-annotations:1.0-1",
"com.google.code.gson:gson:2.11.0",
"com.google.guava:guava:33.3.0-jre",
"com.google.guava:guava:33.3.1-jre",
"com.google.auto:auto-common:1.2.2",
"com.google.auto.service:auto-service:1.1.1",
"com.google.auto.service:auto-service-annotations:1.1.1",
Expand Down
57 changes: 4 additions & 53 deletions dotnet/src/webdriver/BiDi/BiDi.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenQA.Selenium.BiDi.Communication;
using OpenQA.Selenium.BiDi.Communication.Transport;

#nullable enable

namespace OpenQA.Selenium.BiDi;

public class BiDi : IAsyncDisposable
Expand Down Expand Up @@ -38,11 +39,11 @@ internal BiDi(string url)
}

internal Modules.Session.SessionModule SessionModule => _sessionModule.Value;
internal Modules.BrowsingContext.BrowsingContextModule BrowsingContextModule => _browsingContextModule.Value;
internal Modules.BrowsingContext.BrowsingContextModule BrowsingContext => _browsingContextModule.Value;
public Modules.Browser.BrowserModule Browser => _browserModule.Value;
public Modules.Network.NetworkModule Network => _networkModule.Value;
internal Modules.Input.InputModule InputModule => _inputModule.Value;
internal Modules.Script.ScriptModule ScriptModule => _scriptModule.Value;
public Modules.Script.ScriptModule Script => _scriptModule.Value;
public Modules.Log.LogModule Log => _logModule.Value;
public Modules.Storage.StorageModule Storage => _storageModule.Value;

Expand All @@ -60,16 +61,6 @@ public static async Task<BiDi> ConnectAsync(string url)
return bidi;
}

public Task<Modules.BrowsingContext.BrowsingContext> CreateContextAsync(Modules.BrowsingContext.ContextType type, Modules.BrowsingContext.CreateOptions? options = null)
{
return BrowsingContextModule.CreateAsync(type, options);
}

public Task<IReadOnlyList<Modules.BrowsingContext.BrowsingContextInfo>> GetTreeAsync(Modules.BrowsingContext.GetTreeOptions? options = null)
{
return BrowsingContextModule.GetTreeAsync(options);
}

public Task EndAsync(Modules.Session.EndOptions? options = null)
{
return SessionModule.EndAsync(options);
Expand All @@ -81,44 +72,4 @@ public async ValueTask DisposeAsync()

_transport?.Dispose();
}

public Task<Subscription> OnContextCreatedAsync(Func<Modules.BrowsingContext.BrowsingContextInfo, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnContextCreatedAsync(handler, options);
}

public Task<Subscription> OnContextCreatedAsync(Action<Modules.BrowsingContext.BrowsingContextInfo> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnContextCreatedAsync(handler, options);
}

public Task<Subscription> OnContextDestroyedAsync(Func<Modules.BrowsingContext.BrowsingContextInfo, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnContextDestroyedAsync(handler, options);
}

public Task<Subscription> OnContextDestroyedAsync(Action<Modules.BrowsingContext.BrowsingContextInfo> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnContextDestroyedAsync(handler, options);
}

public Task<Subscription> OnUserPromptOpenedAsync(Func<Modules.BrowsingContext.UserPromptOpenedEventArgs, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnUserPromptOpenedAsync(handler, options);
}

public Task<Subscription> OnUserPromptOpenedAsync(Action<Modules.BrowsingContext.UserPromptOpenedEventArgs> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnUserPromptOpenedAsync(handler, options);
}

public Task<Subscription> OnUserPromptClosedAsync(Func<Modules.BrowsingContext.UserPromptClosedEventArgs, Task> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnUserPromptClosedAsync(handler, options);
}

public Task<Subscription> OnUserPromptClosedAsync(Action<Modules.BrowsingContext.UserPromptClosedEventArgs> handler, BrowsingContextsSubscriptionOptions? options = null)
{
return BrowsingContextModule.OnUserPromptClosedAsync(handler, options);
}
}
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/BiDi/BiDiException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;

#nullable enable

namespace OpenQA.Selenium.BiDi;

public class BiDiException : Exception
Expand Down
14 changes: 12 additions & 2 deletions dotnet/src/webdriver/BiDi/Communication/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Threading;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication;

public class Broker : IAsyncDisposable
Expand All @@ -34,7 +36,7 @@ public class Broker : IAsyncDisposable

private readonly JsonSerializerOptions _jsonSerializerOptions;

public Broker(BiDi bidi, ITransport transport)
internal Broker(BiDi bidi, ITransport transport)
{
_bidi = bidi;
_transport = transport;
Expand All @@ -51,14 +53,15 @@ public Broker(BiDi bidi, ITransport transport)
new NavigationConverter(),
new InterceptConverter(_bidi),
new RequestConverter(_bidi),
new ChannelConverter(_bidi),
new ChannelConverter(),
new HandleConverter(_bidi),
new InternalIdConverter(_bidi),
new PreloadScriptConverter(_bidi),
new RealmConverter(_bidi),
new RealmTypeConverter(),
new DateTimeOffsetConverter(),
new PrintPageRangeConverter(),
new InputOriginConverter(),
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase),

// https://github.com/dotnet/runtime/issues/72604
Expand All @@ -68,6 +71,13 @@ public Broker(BiDi bidi, ITransport transport)
new Json.Converters.Polymorphic.RealmInfoConverter(),
new Json.Converters.Polymorphic.LogEntryConverter(),
//

// Enumerable
new Json.Converters.Enumerable.GetCookiesResultConverter(),
new Json.Converters.Enumerable.LocateNodesResultConverter(),
new Json.Converters.Enumerable.InputSourceActionsConverter(),
new Json.Converters.Enumerable.GetUserContextsResultConverter(),
new Json.Converters.Enumerable.GetRealmsResultConverter(),
}
};
}
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/BiDi/Communication/Command.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication;

[JsonPolymorphic(TypeDiscriminatorPropertyName = "method")]
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/BiDi/Communication/CommandOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication;

public record CommandOptions
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/BiDi/Communication/EventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication;

public abstract class EventHandler(string eventName, Type eventArgsType, IEnumerable<BrowsingContext>? contexts = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;

internal class BrowserUserContextConverter : JsonConverter<UserContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;

internal class BrowsingContextConverter : JsonConverter<BrowsingContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;

internal class ChannelConverter : JsonConverter<Channel>
{
private readonly BiDi _bidi;

public ChannelConverter(BiDi bidi)
{
_bidi = bidi;
}

public override Channel? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var id = reader.GetString();

return new Channel(_bidi, id!);
return new Channel(id!);
}

public override void Write(Utf8JsonWriter writer, Channel value, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;

internal class DateTimeOffsetConverter : JsonConverter<DateTimeOffset>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using OpenQA.Selenium.BiDi.Modules.Storage;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;

internal class GetCookiesResultConverter : JsonConverter<GetCookiesResult>
{
public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var doc = JsonDocument.ParseValue(ref reader);
var cookies = doc.RootElement.GetProperty("cookies").Deserialize<IReadOnlyList<Modules.Network.Cookie>>(options);
var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize<PartitionKey>(options);

return new GetCookiesResult(cookies!, partitionKey!);
}

public override void Write(Utf8JsonWriter writer, GetCookiesResult value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using OpenQA.Selenium.BiDi.Modules.Script;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;

internal class GetRealmsResultConverter : JsonConverter<GetRealmsResult>
{
public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var doc = JsonDocument.ParseValue(ref reader);
var realms = doc.RootElement.GetProperty("realms").Deserialize<IReadOnlyList<RealmInfo>>(options);

return new GetRealmsResult(realms!);
}

public override void Write(Utf8JsonWriter writer, GetRealmsResult value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using OpenQA.Selenium.BiDi.Modules.Browser;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;

internal class GetUserContextsResultConverter : JsonConverter<GetUserContextsResult>
{
public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var doc = JsonDocument.ParseValue(ref reader);
var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize<IReadOnlyList<UserContextInfo>>(options);

return new GetUserContextsResult(userContexts!);
}

public override void Write(Utf8JsonWriter writer, GetUserContextsResult value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using OpenQA.Selenium.BiDi.Modules.Input;
using System;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;

internal class InputSourceActionsConverter : JsonConverter<SourceActions>
{
public override SourceActions Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
}

public override void Write(Utf8JsonWriter writer, SourceActions value, JsonSerializerOptions options)
{
writer.WriteStartObject();

writer.WriteString("id", value.Id);

switch (value)
{
case KeyActions keys:
writer.WriteString("type", "key");
writer.WritePropertyName("actions");
JsonSerializer.Serialize(writer, keys.Actions.Select(a => a as IKeySourceAction), options);

break;
case PointerActions pointers:
writer.WriteString("type", "pointer");
if (pointers.Options is not null)
{
writer.WritePropertyName("parameters");
JsonSerializer.Serialize(writer, pointers.Options, options);
}

writer.WritePropertyName("actions");
JsonSerializer.Serialize(writer, pointers.Actions.Select(a => a as IPointerSourceAction), options);

break;
case WheelActions wheels:
writer.WriteString("type", "wheel");
writer.WritePropertyName("actions");
JsonSerializer.Serialize(writer, wheels.Actions.Select(a => a as IWheelSourceAction), options);

break;
case NoneActions none:
writer.WriteString("type", "none");
writer.WritePropertyName("actions");
JsonSerializer.Serialize(writer, none.Actions.Select(a => a as INoneSourceAction), options);

break;
}

writer.WriteEndObject();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using OpenQA.Selenium.BiDi.Modules.BrowsingContext;
using OpenQA.Selenium.BiDi.Modules.Script;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable enable

namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;

internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
{
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var doc = JsonDocument.ParseValue(ref reader);
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<RemoteValue.Node>>(options);

return new LocateNodesResult(nodes!);
}

public override void Write(Utf8JsonWriter writer, LocateNodesResult value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
Loading

0 comments on commit f83ad29

Please sign in to comment.