Skip to content

Commit 48cd353

Browse files
authored
Merge branch 'trunk' into renovate/io.lettuce-lettuce-core-6.x
2 parents 57b1c12 + e639050 commit 48cd353

File tree

94 files changed

+1158
-920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1158
-920
lines changed

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ internal Broker(BiDi bidi, ITransport transport)
7070
{
7171
new BrowsingContextConverter(_bidi),
7272
new BrowserUserContextConverter(bidi),
73+
new BrowserClientWindowConverter(),
7374
new NavigationConverter(),
7475
new InterceptConverter(_bidi),
7576
new RequestConverter(_bidi),
@@ -82,6 +83,7 @@ internal Broker(BiDi bidi, ITransport transport)
8283
new DateTimeOffsetConverter(),
8384
new PrintPageRangeConverter(),
8485
new InputOriginConverter(),
86+
new SubscriptionConverter(),
8587
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase),
8688

8789
// https://github.com/dotnet/runtime/issues/72604
@@ -97,6 +99,7 @@ internal Broker(BiDi bidi, ITransport transport)
9799
new Json.Converters.Enumerable.LocateNodesResultConverter(),
98100
new Json.Converters.Enumerable.InputSourceActionsConverter(),
99101
new Json.Converters.Enumerable.GetUserContextsResultConverter(),
102+
new Json.Converters.Enumerable.GetClientWindowsResultConverter(),
100103
new Json.Converters.Enumerable.GetRealmsResultConverter(),
101104
}
102105
};
@@ -109,15 +112,17 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
109112
await _transport.ConnectAsync(cancellationToken).ConfigureAwait(false);
110113

111114
_receiveMessagesCancellationTokenSource = new CancellationTokenSource();
112-
_receivingMessageTask = _myTaskFactory.StartNew(async () => await ReceiveMessagesAsync(_receiveMessagesCancellationTokenSource.Token), TaskCreationOptions.LongRunning).Unwrap();
113-
_eventEmitterTask = _myTaskFactory.StartNew(async () => await ProcessEventsAwaiterAsync(), TaskCreationOptions.LongRunning).Unwrap();
115+
_receivingMessageTask = _myTaskFactory.StartNew(async () => await ReceiveMessagesAsync(_receiveMessagesCancellationTokenSource.Token)).Unwrap();
116+
_eventEmitterTask = _myTaskFactory.StartNew(ProcessEventsAwaiterAsync).Unwrap();
114117
}
115118

116119
private async Task ReceiveMessagesAsync(CancellationToken cancellationToken)
117120
{
118121
while (!cancellationToken.IsCancellationRequested)
119122
{
120-
var message = await _transport.ReceiveAsJsonAsync<Message>(_jsonSerializerContext, cancellationToken);
123+
var data = await _transport.ReceiveAsync(cancellationToken).ConfigureAwait(false);
124+
125+
var message = JsonSerializer.Deserialize(new ReadOnlySpan<byte>(data), _jsonSerializerContext.Message);
121126

122127
switch (message)
123128
{
@@ -177,21 +182,21 @@ private async Task ProcessEventsAwaiterAsync()
177182
}
178183

179184
public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options)
180-
where TCommand: Command
185+
where TCommand : Command
181186
{
182187
var jsonElement = await ExecuteCommandCoreAsync(command, options).ConfigureAwait(false);
183188

184189
return (TResult)jsonElement.Deserialize(typeof(TResult), _jsonSerializerContext)!;
185190
}
186191

187192
public async Task ExecuteCommandAsync<TCommand>(TCommand command, CommandOptions? options)
188-
where TCommand: Command
193+
where TCommand : Command
189194
{
190195
await ExecuteCommandCoreAsync(command, options).ConfigureAwait(false);
191196
}
192197

193198
private async Task<JsonElement> ExecuteCommandCoreAsync<TCommand>(TCommand command, CommandOptions? options)
194-
where TCommand: Command
199+
where TCommand : Command
195200
{
196201
command.Id = Interlocked.Increment(ref _currentCommandId);
197202

@@ -205,7 +210,9 @@ private async Task<JsonElement> ExecuteCommandCoreAsync<TCommand>(TCommand comma
205210

206211
_pendingCommands[command.Id] = tcs;
207212

208-
await _transport.SendAsJsonAsync(command, _jsonSerializerContext, cts.Token).ConfigureAwait(false);
213+
var data = JsonSerializer.SerializeToUtf8Bytes(command, typeof(TCommand), _jsonSerializerContext);
214+
215+
await _transport.SendAsync(data, cts.Token).ConfigureAwait(false);
209216

210217
return await tcs.Task.ConfigureAwait(false);
211218
}
@@ -217,23 +224,23 @@ public async Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Act
217224

218225
if (options is BrowsingContextsSubscriptionOptions browsingContextsOptions)
219226
{
220-
await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = browsingContextsOptions.Contexts }).ConfigureAwait(false);
227+
var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = browsingContextsOptions.Contexts }).ConfigureAwait(false);
221228

222229
var eventHandler = new SyncEventHandler<TEventArgs>(eventName, action, browsingContextsOptions?.Contexts);
223230

224231
handlers.Add(eventHandler);
225232

226-
return new Subscription(this, eventHandler);
233+
return new Subscription(subscribeResult.Subscription, this, eventHandler);
227234
}
228235
else
229236
{
230-
await _bidi.SessionModule.SubscribeAsync([eventName]).ConfigureAwait(false);
237+
var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName]).ConfigureAwait(false);
231238

232239
var eventHandler = new SyncEventHandler<TEventArgs>(eventName, action);
233240

234241
handlers.Add(eventHandler);
235242

236-
return new Subscription(this, eventHandler);
243+
return new Subscription(subscribeResult.Subscription, this, eventHandler);
237244
}
238245
}
239246

@@ -244,44 +251,51 @@ public async Task<Subscription> SubscribeAsync<TEventArgs>(string eventName, Fun
244251

245252
if (options is BrowsingContextsSubscriptionOptions browsingContextsOptions)
246253
{
247-
await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = browsingContextsOptions.Contexts }).ConfigureAwait(false);
254+
var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName], new() { Contexts = browsingContextsOptions.Contexts }).ConfigureAwait(false);
248255

249256
var eventHandler = new AsyncEventHandler<TEventArgs>(eventName, func, browsingContextsOptions.Contexts);
250257

251258
handlers.Add(eventHandler);
252259

253-
return new Subscription(this, eventHandler);
260+
return new Subscription(subscribeResult.Subscription, this, eventHandler);
254261
}
255262
else
256263
{
257-
await _bidi.SessionModule.SubscribeAsync([eventName]).ConfigureAwait(false);
264+
var subscribeResult = await _bidi.SessionModule.SubscribeAsync([eventName]).ConfigureAwait(false);
258265

259266
var eventHandler = new AsyncEventHandler<TEventArgs>(eventName, func);
260267

261268
handlers.Add(eventHandler);
262269

263-
return new Subscription(this, eventHandler);
270+
return new Subscription(subscribeResult.Subscription, this, eventHandler);
264271
}
265272
}
266273

267-
public async Task UnsubscribeAsync(EventHandler eventHandler)
274+
public async Task UnsubscribeAsync(Modules.Session.Subscription subscription, EventHandler eventHandler)
268275
{
269276
var eventHandlers = _eventHandlers[eventHandler.EventName];
270277

271278
eventHandlers.Remove(eventHandler);
272279

273-
if (eventHandler.Contexts is not null)
280+
if (subscription is not null)
274281
{
275-
if (!eventHandlers.Any(h => eventHandler.Contexts.Equals(h.Contexts)) && !eventHandlers.Any(h => h.Contexts is null))
276-
{
277-
await _bidi.SessionModule.UnsubscribeAsync([eventHandler.EventName], new() { Contexts = eventHandler.Contexts }).ConfigureAwait(false);
278-
}
282+
await _bidi.SessionModule.UnsubscribeAsync([subscription]).ConfigureAwait(false);
279283
}
280284
else
281285
{
282-
if (!eventHandlers.Any(h => h.Contexts is not null) && !eventHandlers.Any(h => h.Contexts is null))
286+
if (eventHandler.Contexts is not null)
287+
{
288+
if (!eventHandlers.Any(h => eventHandler.Contexts.Equals(h.Contexts)) && !eventHandlers.Any(h => h.Contexts is null))
289+
{
290+
await _bidi.SessionModule.UnsubscribeAsync([eventHandler.EventName], new() { Contexts = eventHandler.Contexts }).ConfigureAwait(false);
291+
}
292+
}
293+
else
283294
{
284-
await _bidi.SessionModule.UnsubscribeAsync([eventHandler.EventName]).ConfigureAwait(false);
295+
if (!eventHandlers.Any(h => h.Contexts is not null) && !eventHandlers.Any(h => h.Contexts is null))
296+
{
297+
await _bidi.SessionModule.UnsubscribeAsync([eventHandler.EventName]).ConfigureAwait(false);
298+
}
285299
}
286300
}
287301
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
7979
[JsonSerializable(typeof(Modules.Session.NewResult))]
8080
[JsonSerializable(typeof(Modules.Session.EndCommand))]
8181
[JsonSerializable(typeof(Modules.Session.SubscribeCommand))]
82-
[JsonSerializable(typeof(Modules.Session.UnsubscribeCommand))]
82+
[JsonSerializable(typeof(Modules.Session.SubscribeResult))]
83+
[JsonSerializable(typeof(Modules.Session.UnsubscribeByIdCommand))]
84+
[JsonSerializable(typeof(Modules.Session.UnsubscribeByAttributesCommand))]
8385

8486
[JsonSerializable(typeof(Modules.Browser.CloseCommand), TypeInfoPropertyName = "Browser_CloseCommand")]
8587
[JsonSerializable(typeof(Modules.Browser.CreateUserContextCommand))]
8688
[JsonSerializable(typeof(Modules.Browser.GetUserContextsCommand))]
8789
[JsonSerializable(typeof(Modules.Browser.GetUserContextsResult))]
8890
[JsonSerializable(typeof(Modules.Browser.RemoveUserContextCommand))]
91+
[JsonSerializable(typeof(Modules.Browser.GetClientWindowsCommand))]
92+
[JsonSerializable(typeof(Modules.Browser.GetClientWindowsResult))]
8993
[JsonSerializable(typeof(Modules.Browser.UserContextInfo))]
9094
[JsonSerializable(typeof(IReadOnlyList<Modules.Browser.UserContextInfo>))]
95+
[JsonSerializable(typeof(IReadOnlyList<Modules.Browser.ClientWindowInfo>))]
9196

9297

9398
[JsonSerializable(typeof(Modules.BrowsingContext.ActivateCommand))]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// <copyright file="BrowserClientWindowConverter.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using OpenQA.Selenium.BiDi.Modules.Browser;
21+
using System;
22+
using System.Text.Json;
23+
using System.Text.Json.Serialization;
24+
25+
#nullable enable
26+
27+
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
28+
29+
internal class BrowserClientWindowConverter : JsonConverter<ClientWindow>
30+
{
31+
public override ClientWindow? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
32+
{
33+
var id = reader.GetString();
34+
35+
return new ClientWindow(id!);
36+
}
37+
38+
public override void Write(Utf8JsonWriter writer, ClientWindow value, JsonSerializerOptions options)
39+
{
40+
writer.WriteStringValue(value.Id);
41+
}
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// <copyright file="GetClientWindowsResultConverter.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using OpenQA.Selenium.BiDi.Modules.Browser;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Text.Json;
24+
using System.Text.Json.Serialization;
25+
26+
#nullable enable
27+
28+
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters.Enumerable;
29+
30+
internal class GetClientWindowsResultConverter : JsonConverter<GetClientWindowsResult>
31+
{
32+
public override GetClientWindowsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
33+
{
34+
using var doc = JsonDocument.ParseValue(ref reader);
35+
var clientWindows = doc.RootElement.GetProperty("clientWindows").Deserialize<IReadOnlyList<ClientWindowInfo>>(options);
36+
37+
return new GetClientWindowsResult(clientWindows!);
38+
}
39+
40+
public override void Write(Utf8JsonWriter writer, GetClientWindowsResult value, JsonSerializerOptions options)
41+
{
42+
throw new NotImplementedException();
43+
}
44+
}

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetCookiesResultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class GetCookiesResultConverter : JsonConverter<GetCookiesResult>
3131
{
3232
public override GetCookiesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3333
{
34-
var doc = JsonDocument.ParseValue(ref reader);
34+
using var doc = JsonDocument.ParseValue(ref reader);
3535
var cookies = doc.RootElement.GetProperty("cookies").Deserialize<IReadOnlyList<Modules.Network.Cookie>>(options);
3636
var partitionKey = doc.RootElement.GetProperty("partitionKey").Deserialize<PartitionKey>(options);
3737

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetRealmsResultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class GetRealmsResultConverter : JsonConverter<GetRealmsResult>
3131
{
3232
public override GetRealmsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3333
{
34-
var doc = JsonDocument.ParseValue(ref reader);
34+
using var doc = JsonDocument.ParseValue(ref reader);
3535
var realms = doc.RootElement.GetProperty("realms").Deserialize<IReadOnlyList<RealmInfo>>(options);
3636

3737
return new GetRealmsResult(realms!);

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/GetUserContextsResultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal class GetUserContextsResultConverter : JsonConverter<GetUserContextsRes
3131
{
3232
public override GetUserContextsResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3333
{
34-
var doc = JsonDocument.ParseValue(ref reader);
34+
using var doc = JsonDocument.ParseValue(ref reader);
3535
var userContexts = doc.RootElement.GetProperty("userContexts").Deserialize<IReadOnlyList<UserContextInfo>>(options);
3636

3737
return new GetUserContextsResult(userContexts!);

dotnet/src/webdriver/BiDi/Communication/Json/Converters/Enumerable/LocateNodesResultConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal class LocateNodesResultConverter : JsonConverter<LocateNodesResult>
3232
{
3333
public override LocateNodesResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
3434
{
35-
var doc = JsonDocument.ParseValue(ref reader);
35+
using var doc = JsonDocument.ParseValue(ref reader);
3636
var nodes = doc.RootElement.GetProperty("nodes").Deserialize<IReadOnlyList<RemoteValue.Node>>(options);
3737

3838
return new LocateNodesResult(nodes!);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// <copyright file="SubscriptionConverter.cs" company="Selenium Committers">
2+
// Licensed to the Software Freedom Conservancy (SFC) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The SFC licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
// </copyright>
19+
20+
using System;
21+
using System.Text.Json;
22+
using System.Text.Json.Serialization;
23+
24+
#nullable enable
25+
26+
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
27+
28+
internal class SubscriptionConverter : JsonConverter<Modules.Session.Subscription>
29+
{
30+
public override Modules.Session.Subscription? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
31+
{
32+
var id = reader.GetString();
33+
34+
return new Modules.Session.Subscription(id!);
35+
}
36+
37+
public override void Write(Utf8JsonWriter writer, Modules.Session.Subscription value, JsonSerializerOptions options)
38+
{
39+
writer.WriteStringValue(value.Id);
40+
}
41+
}

dotnet/src/webdriver/BiDi/Communication/Transport/ITransport.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using System.Threading.Tasks;
2121
using System.Threading;
2222
using System;
23-
using System.Text.Json.Serialization;
2423

2524
#nullable enable
2625

@@ -30,8 +29,7 @@ interface ITransport : IDisposable
3029
{
3130
Task ConnectAsync(CancellationToken cancellationToken);
3231

33-
Task<T> ReceiveAsJsonAsync<T>(JsonSerializerContext jsonSerializerContext, CancellationToken cancellationToken);
32+
Task<byte[]> ReceiveAsync(CancellationToken cancellationToken);
3433

35-
Task SendAsJsonAsync<TCommand>(TCommand command, JsonSerializerContext jsonSerializerContext, CancellationToken cancellationToken)
36-
where TCommand : Command;
34+
Task SendAsync(byte[] data, CancellationToken cancellationToken);
3735
}

0 commit comments

Comments
 (0)