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
9 changes: 9 additions & 0 deletions dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public async Task<SetScreenOrientationOverrideResult> SetScreenOrientationOverri
return await Broker.ExecuteCommandAsync(new SetScreenOrientationOverrideCommand(@params), options, _jsonContext.SetScreenOrientationOverrideCommand, _jsonContext.SetScreenOrientationOverrideResult).ConfigureAwait(false);
}

public async Task<SetScreenSettingsOverrideResult> SetScreenSettingsOverrideAsync(ScreenArea? screenArea, SetScreenSettingsOverrideOptions? options = null)
{
var @params = new SetScreenSettingsOverrideParameters(screenArea, options?.Contexts, options?.UserContexts);

return await Broker.ExecuteCommandAsync(new SetScreenSettingsOverrideCommand(@params), options, _jsonContext.SetScreenSettingsOverrideCommand, _jsonContext.SetScreenSettingsOverrideResult).ConfigureAwait(false);
}

public async Task<SetGeolocationOverrideResult> SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null)
{
var coordinates = new GeolocationCoordinates(latitude, longitude, options?.Accuracy, options?.Altitude, options?.AltitudeAccuracy, options?.Heading, options?.Speed);
Expand Down Expand Up @@ -114,6 +121,8 @@ protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
[JsonSerializable(typeof(SetScriptingEnabledResult))]
[JsonSerializable(typeof(SetScreenOrientationOverrideCommand))]
[JsonSerializable(typeof(SetScreenOrientationOverrideResult))]
[JsonSerializable(typeof(SetScreenSettingsOverrideCommand))]
[JsonSerializable(typeof(SetScreenSettingsOverrideResult))]
[JsonSerializable(typeof(SetGeolocationOverrideCommand))]
[JsonSerializable(typeof(SetGeolocationOverrideResult))]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// <copyright file="SetScreenSettingsOverrideCommand.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// </copyright>

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace OpenQA.Selenium.BiDi.Emulation;

internal sealed class SetScreenSettingsOverrideCommand(SetScreenSettingsOverrideParameters @params)
: Command<SetScreenSettingsOverrideParameters, SetScreenSettingsOverrideResult>(@params, "emulation.setScreenSettingsOverride");

internal sealed record SetScreenSettingsOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScreenArea? ScreenArea, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;

public sealed class SetScreenSettingsOverrideOptions : CommandOptions
{
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }

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

public sealed record ScreenArea(long Width, long Height);

public sealed record SetScreenSettingsOverrideResult : EmptyResult;
15 changes: 15 additions & 0 deletions dotnet/test/common/BiDi/Emulation/EmulationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,21 @@ public void CanSetScreenOrientationOverrideToDefault()
Throws.Nothing);
}

[Test]
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
public void CanSetScreenSettingsOverride()
{
var screenArea = new ScreenArea(300, 200);

Assert.That(async () =>
{
await bidi.Emulation.SetScreenSettingsOverrideAsync(screenArea, new() { Contexts = [context] });
},
Throws.Nothing);
}

[Test]
public void CanSetGeolocationCoordinatesOverride()
{
Expand Down