Skip to content
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
26 changes: 12 additions & 14 deletions dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,20 @@ public async Task<SetScrollbarTypeOverrideResult> SetScrollbarTypeOverrideAsync(
return await ExecuteAsync(SetScrollbarTypeOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public async Task<SetGeolocationOverrideResult> SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null, CancellationToken cancellationToken = default)
public async Task<SetGeolocationOverrideResult> SetGeolocationOverrideAsync(GeolocationOverride? geolocationOverride, SetGeolocationOverrideOptions? options = null, CancellationToken cancellationToken = default)
{
var coordinates = new GeolocationCoordinates(latitude, longitude, options?.Accuracy, options?.Altitude, options?.AltitudeAccuracy, options?.Heading, options?.Speed);
var @params = new SetGeolocationOverrideCoordinatesParameters(coordinates, options?.Contexts, options?.UserContexts);
return await ExecuteAsync(SetGeolocationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false);
}
SetGeolocationOverrideParameters @params = geolocationOverride switch
{
GeolocationCoordinatesOverride c => new SetGeolocationOverrideCoordinatesParameters(
new GeolocationCoordinates(c.Latitude, c.Longitude, c.Accuracy, c.Altitude, c.AltitudeAccuracy, c.Heading, c.Speed),
options?.Contexts, options?.UserContexts),
GeolocationPositionErrorOverride => new SetGeolocationOverridePositionErrorParameters(
new GeolocationPositionError(), options?.Contexts, options?.UserContexts),
null => new SetGeolocationOverrideCoordinatesParameters(
null, options?.Contexts, options?.UserContexts),
_ => throw new ArgumentException($"Unknown geolocation override type: {geolocationOverride.GetType()}", nameof(geolocationOverride))
};

public async Task<SetGeolocationOverrideResult> SetGeolocationCoordinatesOverrideAsync(SetGeolocationOverrideOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new SetGeolocationOverrideCoordinatesParameters(null, options?.Contexts, options?.UserContexts);
return await ExecuteAsync(SetGeolocationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public async Task<SetGeolocationOverrideResult> SetGeolocationPositionErrorOverrideAsync(SetGeolocationPositionErrorOverrideOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new SetGeolocationOverridePositionErrorParameters(new GeolocationPositionError(), options?.Contexts, options?.UserContexts);
return await ExecuteAsync(SetGeolocationOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false);
}
Comment thread
nvborisenko marked this conversation as resolved.

Expand Down
4 changes: 1 addition & 3 deletions dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ namespace OpenQA.Selenium.BiDi.Emulation;
public interface IEmulationModule
{
Task<SetForcedColorsModeThemeOverrideResult> SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme? theme, SetForcedColorsModeThemeOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetGeolocationOverrideResult> SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetGeolocationOverrideResult> SetGeolocationCoordinatesOverrideAsync(SetGeolocationOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetGeolocationOverrideResult> SetGeolocationPositionErrorOverrideAsync(SetGeolocationPositionErrorOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetGeolocationOverrideResult> SetGeolocationOverrideAsync(GeolocationOverride? geolocationOverride, SetGeolocationOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetLocaleOverrideResult> SetLocaleOverrideAsync(string? locale, SetLocaleOverrideOptions? options = null, CancellationToken cancellationToken = default);
Comment thread
nvborisenko marked this conversation as resolved.
Task<SetNetworkConditionsResult> SetNetworkConditionsAsync(NetworkConditions? networkConditions, SetNetworkConditionsOptions? options = null, CancellationToken cancellationToken = default);
Comment thread
nvborisenko marked this conversation as resolved.
Task<SetScreenOrientationOverrideResult> SetScreenOrientationOverrideAsync(ScreenOrientation? screenOrientation, SetScreenOrientationOverrideOptions? options = null, CancellationToken cancellationToken = default);
Expand Down
26 changes: 14 additions & 12 deletions dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@

namespace OpenQA.Selenium.BiDi.Emulation;

public abstract record GeolocationOverride;

public sealed record GeolocationCoordinatesOverride(double Latitude, double Longitude) : GeolocationOverride
{
public double? Accuracy { get; init; }
public double? Altitude { get; init; }
public double? AltitudeAccuracy { get; init; }
public double? Heading { get; init; }
public double? Speed { get; init; }
}

public sealed record GeolocationPositionErrorOverride : GeolocationOverride;

[JsonDerivedType(typeof(SetGeolocationOverrideCoordinatesParameters))]
[JsonDerivedType(typeof(SetGeolocationOverridePositionErrorParameters))]
internal abstract record SetGeolocationOverrideParameters(IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
Expand All @@ -37,22 +50,11 @@ internal sealed record GeolocationPositionError
internal string Type { get; } = "positionUnavailable";
}

public record SetGeolocationOverrideOptions : CommandOptions
public sealed record SetGeolocationOverrideOptions : CommandOptions
{
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; init; }

public IEnumerable<Browser.UserContext>? UserContexts { get; init; }
}

Comment thread
nvborisenko marked this conversation as resolved.
public sealed record SetGeolocationCoordinatesOverrideOptions : SetGeolocationOverrideOptions
Comment thread
nvborisenko marked this conversation as resolved.
{
public double? Accuracy { get; init; }
public double? Altitude { get; init; }
public double? AltitudeAccuracy { get; init; }
public double? Heading { get; init; }
public double? Speed { get; init; }
}

public sealed record SetGeolocationPositionErrorOverrideOptions : SetGeolocationOverrideOptions;

public sealed record SetGeolocationOverrideResult : EmptyResult;
6 changes: 3 additions & 3 deletions dotnet/test/webdriver/BiDi/Emulation/EmulationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void CanSetGeolocationCoordinatesOverride()
{
Assert.That(async () =>
{
await bidi.Emulation.SetGeolocationCoordinatesOverrideAsync(0, 0, new() { Contexts = [context] });
await bidi.Emulation.SetGeolocationOverrideAsync(new GeolocationCoordinatesOverride(0, 0), new() { Contexts = [context] });
},
Throws.Nothing);
}
Expand All @@ -208,7 +208,7 @@ public void CanSetGeolocationCoordinatesOverrideToDefault()
{
Assert.That(async () =>
{
await bidi.Emulation.SetGeolocationCoordinatesOverrideAsync(new() { Contexts = [context] });
await bidi.Emulation.SetGeolocationOverrideAsync(null, new() { Contexts = [context] });
},
Throws.Nothing);
}
Expand All @@ -219,7 +219,7 @@ public void CanSetGeolocationPositionErrorOverride()
{
Assert.That(async () =>
{
await bidi.Emulation.SetGeolocationPositionErrorOverrideAsync(new() { Contexts = [context] });
await bidi.Emulation.SetGeolocationOverrideAsync(new GeolocationPositionErrorOverride(), new() { Contexts = [context] });
},
Throws.Nothing);
}
Expand Down
Loading