diff --git a/dotnet/src/webdriver/BiDi/BiDi.cs b/dotnet/src/webdriver/BiDi/BiDi.cs index 0ffc7b8fdeaf2..3edb8edac2401 100644 --- a/dotnet/src/webdriver/BiDi/BiDi.cs +++ b/dotnet/src/webdriver/BiDi/BiDi.cs @@ -37,6 +37,7 @@ public sealed class BiDi : IAsyncDisposable private Log.LogModule? _logModule; private Storage.StorageModule? _storageModule; private WebExtension.WebExtensionModule? _webExtensionModule; + private Emulation.EmulationModule? _emulationModule; private readonly object _moduleLock = new(); @@ -164,6 +165,19 @@ public WebExtension.WebExtensionModule WebExtension } } + public Emulation.EmulationModule Emulation + { + get + { + if (_emulationModule is not null) return _emulationModule; + lock (_moduleLock) + { + _emulationModule ??= new Emulation.EmulationModule(_broker); + } + return _emulationModule; + } + } + public Task StatusAsync() { return SessionModule.StatusAsync(); diff --git a/dotnet/src/webdriver/BiDi/Communication/Broker.cs b/dotnet/src/webdriver/BiDi/Communication/Broker.cs index 77b592968b850..4292af05177d6 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Broker.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Broker.cs @@ -84,6 +84,7 @@ internal Broker(BiDi bidi, Uri url) new PreloadScriptConverter(_bidi), new RealmConverter(_bidi), new RealmTypeConverter(), + new ScreenOrientationTypeConverter(), new DateTimeOffsetConverter(), new PrintPageRangeConverter(), new InputOriginConverter(), diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs index b2510f252dbc2..4a74468315f4c 100644 --- a/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs +++ b/dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs @@ -172,5 +172,12 @@ namespace OpenQA.Selenium.BiDi.Communication.Json; [JsonSerializable(typeof(WebExtension.InstallCommand))] [JsonSerializable(typeof(WebExtension.InstallResult))] [JsonSerializable(typeof(WebExtension.UninstallCommand))] +[JsonSerializable(typeof(Emulation.SetTimezoneOverrideCommand))] +[JsonSerializable(typeof(Emulation.SetUserAgentOverrideCommand))] +[JsonSerializable(typeof(Emulation.SetLocaleOverrideCommand))] +[JsonSerializable(typeof(Emulation.SetForcedColorsModeThemeOverrideCommand))] +[JsonSerializable(typeof(Emulation.SetScriptingEnabledCommand))] +[JsonSerializable(typeof(Emulation.SetScreenOrientationOverrideCommand))] +[JsonSerializable(typeof(Emulation.SetGeolocationOverrideCommand))] internal partial class BiDiJsonSerializerContext : JsonSerializerContext; diff --git a/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ScreenOrientationTypeConverter.cs b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ScreenOrientationTypeConverter.cs new file mode 100644 index 0000000000000..6027288f60278 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Communication/Json/Converters/ScreenOrientationTypeConverter.cs @@ -0,0 +1,55 @@ +// +// 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. +// + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Emulation; + +namespace OpenQA.Selenium.BiDi.Communication.Json.Converters; + +internal class ScreenOrientationTypeConverter : JsonConverter +{ + public override ScreenOrientationType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var str = reader.GetString(); + return str switch + { + "portrait-primary" => ScreenOrientationType.PortraitPrimary, + "portrait-secondary" => ScreenOrientationType.PortraitSecondary, + "landscape-primary" => ScreenOrientationType.LandscapePrimary, + "landscape-secondary" => ScreenOrientationType.LandscapeSecondary, + _ => throw new JsonException($"Unrecognized '{str}' value of {typeof(ScreenOrientationType)}."), + }; + } + + public override void Write(Utf8JsonWriter writer, ScreenOrientationType value, JsonSerializerOptions options) + { + var str = value switch + { + ScreenOrientationType.PortraitPrimary => "portrait-primary", + ScreenOrientationType.PortraitSecondary => "portrait-secondary", + ScreenOrientationType.LandscapePrimary => "landscape-primary", + ScreenOrientationType.LandscapeSecondary => "landscape-secondary", + _ => throw new JsonException($"Unrecognized '{value}' value of {typeof(ScreenOrientationType)}."), + }; + + writer.WriteStringValue(str); + } +} diff --git a/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs new file mode 100644 index 0000000000000..69e48d464085d --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs @@ -0,0 +1,92 @@ +// +// 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. +// + +using System; +using System.Threading.Tasks; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Emulation; + +public sealed class EmulationModule(Broker broker) : Module(broker) +{ + public async Task SetTimezoneOverrideAsync(string? timezone, SetTimezoneOverrideOptions? options = null) + { + var @params = new SetTimezoneOverrideParameters(timezone, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetTimezoneOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetUserAgentOverrideAsync(string? userAgent, SetUserAgentOverrideOptions? options = null) + { + var @params = new SetUserAgentOverrideParameters(userAgent, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetUserAgentOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetLocaleOverrideAsync(string? locale, SetLocaleOverrideOptions? options = null) + { + var @params = new SetLocaleOverrideParameters(locale, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetLocaleOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme? theme, SetForcedColorsModeThemeOverrideOptions? options = null) + { + var @params = new SetForcedColorsModeThemeOverrideParameters(theme, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetForcedColorsModeThemeOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetScriptingEnabledAsync(bool? enabled, SetScriptingEnabledOptions? options = null) + { + var @params = new SetScriptingEnabledParameters(enabled, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetScriptingEnabledCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetScreenOrientationOverrideAsync(ScreenOrientation? screenOrientation, SetScreenOrientationOverrideOptions? options = null) + { + var @params = new SetScreenOrientationOverrideParameters(screenOrientation, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetScreenOrientationOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetGeolocationCoordinatesOverrideAsync(double latitude, double longitude, SetGeolocationCoordinatesOverrideOptions? options = null) + { + 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 Broker.ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetGeolocationCoordinatesOverrideAsync(SetGeolocationOverrideOptions? options = null) + { + var @params = new SetGeolocationOverrideCoordinatesParameters(null, options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options).ConfigureAwait(false); + } + + public async Task SetGeolocationPositionErrorOverrideAsync(SetGeolocationPositionErrorOverrideOptions? options = null) + { + var @params = new SetGeolocationOverridePositionErrorParameters(new GeolocationPositionError(), options?.Contexts, options?.UserContexts); + + return await Broker.ExecuteCommandAsync(new SetGeolocationOverrideCommand(@params), options).ConfigureAwait(false); + } +} diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs new file mode 100644 index 0000000000000..eceb0920a0d98 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetForcedColorsModeThemeOverrideCommand.cs @@ -0,0 +1,42 @@ +// +// 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. +// + +using System.Collections.Generic; +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetForcedColorsModeThemeOverrideCommand(SetForcedColorsModeThemeOverrideParameters @params) + : Command(@params, "emulation.setForcedColorsModeThemeOverride"); + +internal sealed record SetForcedColorsModeThemeOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ForcedColorsModeTheme? Theme, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetForcedColorsModeThemeOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} + +public enum ForcedColorsModeTheme +{ + Light, + Dark +} diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs new file mode 100644 index 0000000000000..00ff55da79319 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetGeolocationOverrideCommand.cs @@ -0,0 +1,61 @@ +// +// 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. +// + +using System.Collections.Generic; +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetGeolocationOverrideCommand(SetGeolocationOverrideParameters @params) + : Command(@params, "emulation.setGeolocationOverride"); + +[JsonDerivedType(typeof(SetGeolocationOverrideCoordinatesParameters))] +[JsonDerivedType(typeof(SetGeolocationOverridePositionErrorParameters))] +internal abstract record SetGeolocationOverrideParameters(IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +internal sealed record SetGeolocationOverrideCoordinatesParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] GeolocationCoordinates? Coordinates, IEnumerable? Contexts, IEnumerable? UserContexts) : SetGeolocationOverrideParameters(Contexts, UserContexts); + +internal sealed record SetGeolocationOverridePositionErrorParameters(GeolocationPositionError Error, IEnumerable? Contexts, IEnumerable? UserContexts) : SetGeolocationOverrideParameters(Contexts, UserContexts); + +internal sealed record GeolocationCoordinates(double Latitude, double Longitude, double? Accuracy, double? Altitude, double? AltitudeAccuracy, double? Heading, double? Speed); + +internal sealed record GeolocationPositionError +{ + [JsonInclude] + internal string Type { get; } = "positionUnavailable"; +} + +public class SetGeolocationOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} + +public sealed class SetGeolocationCoordinatesOverrideOptions : SetGeolocationOverrideOptions +{ + public double? Accuracy { get; set; } + public double? Altitude { get; set; } + public double? AltitudeAccuracy { get; set; } + public double? Heading { get; set; } + public double? Speed { get; set; } +} + +public sealed class SetGeolocationPositionErrorOverrideOptions : SetGeolocationOverrideOptions; diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs new file mode 100644 index 0000000000000..900178c9090e1 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetLocaleOverrideCommand.cs @@ -0,0 +1,36 @@ +// +// 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. +// + +using System.Collections.Generic; +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetLocaleOverrideCommand(SetLocaleOverrideParameters @params) + : Command(@params, "emulation.setLocaleOverride"); + +internal sealed record SetLocaleOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? Locale, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetLocaleOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs new file mode 100644 index 0000000000000..3e638d8ebb61b --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScreenOrientationOverrideCommand.cs @@ -0,0 +1,52 @@ +// +// 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. +// + +using System.Collections.Generic; +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetScreenOrientationOverrideCommand(SetScreenOrientationOverrideParameters @params) + : Command(@params, "emulation.setScreenOrientationOverride"); + +internal sealed record SetScreenOrientationOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ScreenOrientation? ScreenOrientation, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetScreenOrientationOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} + +public enum ScreenOrientationNatural +{ + Portrait, + Landscape +} + +public enum ScreenOrientationType +{ + PortraitPrimary, + PortraitSecondary, + LandscapePrimary, + LandscapeSecondary +} + +public sealed record ScreenOrientation(ScreenOrientationNatural Natural, ScreenOrientationType Type); diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs new file mode 100644 index 0000000000000..d19a9dfa4bf90 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetScriptingEnabledCommand.cs @@ -0,0 +1,36 @@ +// +// 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. +// + +using System.Collections.Generic; +using System.Text.Json.Serialization; +using OpenQA.Selenium.BiDi.Communication; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetScriptingEnabledCommand(SetScriptingEnabledParameters @params) + : Command(@params, "emulation.setScriptingEnabled"); + +internal sealed record SetScriptingEnabledParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] bool? Enabled, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetScriptingEnabledOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs new file mode 100644 index 0000000000000..a3c24c25ff530 --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetTimezoneOverrideCommand.cs @@ -0,0 +1,36 @@ +// +// 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. +// + +using OpenQA.Selenium.BiDi.Communication; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetTimezoneOverrideCommand(SetTimezoneOverrideParameters @params) + : Command(@params, "emulation.setTimezoneOverride"); + +internal sealed record SetTimezoneOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? Timezone, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetTimezoneOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} diff --git a/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs b/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs new file mode 100644 index 0000000000000..69467d6d5f9db --- /dev/null +++ b/dotnet/src/webdriver/BiDi/Emulation/SetUserAgentOverrideCommand.cs @@ -0,0 +1,36 @@ +// +// 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. +// + +using OpenQA.Selenium.BiDi.Communication; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace OpenQA.Selenium.BiDi.Emulation; + +internal sealed class SetUserAgentOverrideCommand(SetUserAgentOverrideParameters @params) + : Command(@params, "emulation.setUserAgentOverride"); + +internal sealed record SetUserAgentOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? UserAgent, IEnumerable? Contexts, IEnumerable? UserContexts) : Parameters; + +public sealed class SetUserAgentOverrideOptions : CommandOptions +{ + public IEnumerable? Contexts { get; set; } + + public IEnumerable? UserContexts { get; set; } +} diff --git a/dotnet/test/common/BiDi/Emulation/EmulationTest.cs b/dotnet/test/common/BiDi/Emulation/EmulationTest.cs new file mode 100644 index 0000000000000..03d42b5822d4a --- /dev/null +++ b/dotnet/test/common/BiDi/Emulation/EmulationTest.cs @@ -0,0 +1,200 @@ +// +// 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. +// + +using NUnit.Framework; + +namespace OpenQA.Selenium.BiDi.Emulation; + +class EmulationTest : BiDiTestFixture +{ + [Test] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] + public void CanSetTimezoneOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetTimezoneOverrideAsync("UTC", new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] + public void CanSetTimezoneOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetTimezoneOverrideAsync(null, new() { Contexts = [context] }); + }, + 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 CanSetUserAgentOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetUserAgentOverrideAsync("MyUserAgent/1.0", new() { Contexts = [context] }); + }, + 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 CanSetUserAgentOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetUserAgentOverrideAsync(null, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + public void CanSetLocaleOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetLocaleOverrideAsync("en-US", new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + public void CanSetLocaleOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetLocaleOverrideAsync(null, new() { Contexts = [context] }); + }, + 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 CanSetForcedColorsModeThemeOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme.Light, new() { Contexts = [context] }); + }, + 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 CanSetForcedColorsModeThemeOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetForcedColorsModeThemeOverrideAsync(null, new() { Contexts = [context] }); + }, + 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 CanSetScriptingEnabled() + { + Assert.That(async () => + { + await bidi.Emulation.SetScriptingEnabledAsync(false, new() { Contexts = [context] }); + }, + 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 CanSetScriptingEnabledToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetScriptingEnabledAsync(null, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] + public void CanSetScreenOrientationOverride() + { + var orientation = new ScreenOrientation(ScreenOrientationNatural.Portrait, ScreenOrientationType.PortraitPrimary); + + Assert.That(async () => + { + await bidi.Emulation.SetScreenOrientationOverrideAsync(orientation, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + [IgnoreBrowser(Selenium.Browser.Firefox, "Not supported yet?")] + public void CanSetScreenOrientationOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetScreenOrientationOverrideAsync(null, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + public void CanSetGeolocationCoordinatesOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetGeolocationCoordinatesOverrideAsync(0, 0, new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + public void CanSetGeolocationCoordinatesOverrideToDefault() + { + Assert.That(async () => + { + await bidi.Emulation.SetGeolocationCoordinatesOverrideAsync(new() { Contexts = [context] }); + }, + Throws.Nothing); + } + + [Test] + [IgnoreBrowser(Selenium.Browser.Firefox, "invalid argument: Expected \"coordinates\" to be an object, got [object Undefined] undefined")] + public void CanSetGeolocationPositionErrorOverride() + { + Assert.That(async () => + { + await bidi.Emulation.SetGeolocationPositionErrorOverrideAsync(new() { Contexts = [context] }); + }, + Throws.Nothing); + } +}