Skip to content

Commit 3b1b226

Browse files
authored
[dotnet] [bidi] Support SetScreenSettingsOverrideAsync method in Emulation module (#16704)
1 parent e453a9f commit 3b1b226

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public async Task<SetScreenOrientationOverrideResult> SetScreenOrientationOverri
7070
return await Broker.ExecuteCommandAsync(new SetScreenOrientationOverrideCommand(@params), options, _jsonContext.SetScreenOrientationOverrideCommand, _jsonContext.SetScreenOrientationOverrideResult).ConfigureAwait(false);
7171
}
7272

73+
public async Task<SetScreenSettingsOverrideResult> SetScreenSettingsOverrideAsync(ScreenArea? screenArea, SetScreenSettingsOverrideOptions? options = null)
74+
{
75+
var @params = new SetScreenSettingsOverrideParameters(screenArea, options?.Contexts, options?.UserContexts);
76+
77+
return await Broker.ExecuteCommandAsync(new SetScreenSettingsOverrideCommand(@params), options, _jsonContext.SetScreenSettingsOverrideCommand, _jsonContext.SetScreenSettingsOverrideResult).ConfigureAwait(false);
78+
}
79+
7380
public async Task<SetGeolocationOverrideResult> SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null)
7481
{
7582
var coordinates = new GeolocationCoordinates(latitude, longitude, options?.Accuracy, options?.Altitude, options?.AltitudeAccuracy, options?.Heading, options?.Speed);
@@ -114,6 +121,8 @@ protected override void Initialize(JsonSerializerOptions jsonSerializerOptions)
114121
[JsonSerializable(typeof(SetScriptingEnabledResult))]
115122
[JsonSerializable(typeof(SetScreenOrientationOverrideCommand))]
116123
[JsonSerializable(typeof(SetScreenOrientationOverrideResult))]
124+
[JsonSerializable(typeof(SetScreenSettingsOverrideCommand))]
125+
[JsonSerializable(typeof(SetScreenSettingsOverrideResult))]
117126
[JsonSerializable(typeof(SetGeolocationOverrideCommand))]
118127
[JsonSerializable(typeof(SetGeolocationOverrideResult))]
119128

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// <copyright file="SetScreenSettingsOverrideCommand.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.Collections.Generic;
21+
using System.Text.Json.Serialization;
22+
23+
namespace OpenQA.Selenium.BiDi.Emulation;
24+
25+
internal sealed class SetScreenSettingsOverrideCommand(SetScreenSettingsOverrideParameters @params)
26+
: Command<SetScreenSettingsOverrideParameters, SetScreenSettingsOverrideResult>(@params, "emulation.setScreenSettingsOverride");
27+
28+
internal sealed record SetScreenSettingsOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScreenArea? ScreenArea, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
29+
30+
public sealed class SetScreenSettingsOverrideOptions : CommandOptions
31+
{
32+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
33+
34+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
35+
}
36+
37+
public sealed record ScreenArea(long Width, long Height);
38+
39+
public sealed record SetScreenSettingsOverrideResult : EmptyResult;

dotnet/test/common/BiDi/Emulation/EmulationTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ public void CanSetScreenOrientationOverrideToDefault()
167167
Throws.Nothing);
168168
}
169169

170+
[Test]
171+
[IgnoreBrowser(Selenium.Browser.Chrome, "Not supported yet?")]
172+
[IgnoreBrowser(Selenium.Browser.Edge, "Not supported yet?")]
173+
[IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")]
174+
public void CanSetScreenSettingsOverride()
175+
{
176+
var screenArea = new ScreenArea(300, 200);
177+
178+
Assert.That(async () =>
179+
{
180+
await bidi.Emulation.SetScreenSettingsOverrideAsync(screenArea, new() { Contexts = [context] });
181+
},
182+
Throws.Nothing);
183+
}
184+
170185
[Test]
171186
public void CanSetGeolocationCoordinatesOverride()
172187
{

0 commit comments

Comments
 (0)