Skip to content

Commit b67ebbc

Browse files
committed
Smooth transition
1 parent 4ecab12 commit b67ebbc

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,27 @@ public async Task UnsubscribeAsync(Modules.Session.Subscription subscription, Ev
277277

278278
eventHandlers.Remove(eventHandler);
279279

280-
await _bidi.SessionModule.UnsubscribeAsync([subscription]).ConfigureAwait(false);
280+
if (subscription is not null)
281+
{
282+
await _bidi.SessionModule.UnsubscribeAsync([subscription]).ConfigureAwait(false);
283+
}
284+
else
285+
{
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
294+
{
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+
}
299+
}
300+
}
281301
}
282302

283303
public async ValueTask DisposeAsync()

dotnet/src/webdriver/BiDi/Modules/Session/SessionModule.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,22 @@ public async Task<SubscribeResult> SubscribeAsync(IEnumerable<string> events, Su
4444
return await Broker.ExecuteCommandAsync<SubscribeCommand, SubscribeResult>(new(@params), options).ConfigureAwait(false);
4545
}
4646

47-
public async Task UnsubscribeAsync(IEnumerable<Subscription> subscriptions, UnsubscribeOptions? options = null)
47+
public async Task UnsubscribeAsync(IEnumerable<Subscription> subscriptions, UnsubscribeByIdOptions? options = null)
4848
{
4949
var @params = new UnsubscribeByIdCommandParameters(subscriptions);
5050

5151
await Broker.ExecuteCommandAsync(new UnsubscribeByIdCommand(@params), options).ConfigureAwait(false);
5252
}
5353

54+
public async Task UnsubscribeAsync(IEnumerable<string> eventNames = null, UnsubscribeByAttributesOptions? options = null)
55+
{
56+
var @params = new UnsubscribeByAttributesCommandParameters(eventNames);
57+
58+
@params.Contexts = options?.Contexts;
59+
60+
await Broker.ExecuteCommandAsync(new UnsubscribeByAttributesCommand(@params), options).ConfigureAwait(false);
61+
}
62+
5463
public async Task<NewResult> NewAsync(CapabilitiesRequest capabilitiesRequest, NewOptions? options = null)
5564
{
5665
var @params = new NewCommandParameters(capabilitiesRequest);

dotnet/src/webdriver/BiDi/Modules/Session/UnsubscribeCommand.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Communication;
21+
using System;
2122
using System.Collections.Generic;
2223

2324
#nullable enable
@@ -32,6 +33,16 @@ internal class UnsubscribeByAttributesCommand(UnsubscribeByAttributesCommandPara
3233

3334
internal record UnsubscribeByIdCommandParameters(IEnumerable<Subscription> Subscriptions) : CommandParameters;
3435

35-
internal record UnsubscribeByAttributesCommandParameters : CommandParameters;
36+
public record UnsubscribeByIdOptions : CommandOptions;
3637

37-
public record UnsubscribeOptions : SubscribeOptions;
38+
internal record UnsubscribeByAttributesCommandParameters(IEnumerable<string> Events) : CommandParameters
39+
{
40+
[Obsolete("Contexts param is deprecated and will be removed in the future versions")]
41+
// https://w3c.github.io/webdriver-bidi/#type-session-UnsubscribeByAttributesRequest
42+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
43+
}
44+
45+
public record UnsubscribeByAttributesOptions : CommandOptions
46+
{
47+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
48+
}

0 commit comments

Comments
 (0)