Skip to content

Commit de30f4b

Browse files
committed
SetLocale
1 parent c97e8fc commit de30f4b

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

dotnet/src/webdriver/BiDi/Communication/Json/BiDiJsonSerializerContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
174174
[JsonSerializable(typeof(WebExtension.UninstallCommand))]
175175
[JsonSerializable(typeof(Emulation.SetTimezoneOverrideCommand))]
176176
[JsonSerializable(typeof(Emulation.SetUserAgentOverrideCommand))]
177+
[JsonSerializable(typeof(Emulation.SetLocaleOverrideCommand))]
177178

178179
internal partial class BiDiJsonSerializerContext : JsonSerializerContext;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ public async Task<EmptyResult> SetUserAgentOverrideAsync(string? userAgent, SetU
3737

3838
return await Broker.ExecuteCommandAsync<SetUserAgentOverrideCommand, EmptyResult>(new SetUserAgentOverrideCommand(@params), options).ConfigureAwait(false);
3939
}
40+
41+
public async Task<EmptyResult> SetLocaleOverrideAsync(string? locale, SetLocaleOverrideOptions? options = null)
42+
{
43+
var @params = new SetLocaleOverrideParameters(locale, options?.Contexts, options?.UserContexts);
44+
45+
return await Broker.ExecuteCommandAsync<SetLocaleOverrideCommand, EmptyResult>(new SetLocaleOverrideCommand(@params), options).ConfigureAwait(false);
46+
}
4047
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// <copyright file="SetLocaleOverrideCommand.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+
using OpenQA.Selenium.BiDi.Communication;
23+
24+
namespace OpenQA.Selenium.BiDi.Emulation;
25+
26+
internal sealed class SetLocaleOverrideCommand(SetLocaleOverrideParameters @params)
27+
: Command<SetLocaleOverrideParameters, EmptyResult>(@params, "emulation.setLocaleOverride");
28+
29+
internal sealed record SetLocaleOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? Locale, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
30+
31+
public sealed class SetLocaleOverrideOptions : CommandOptions
32+
{
33+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
34+
35+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
36+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
// under the License.
1818
// </copyright>
1919

20-
using System.Collections.Generic;
2120
using OpenQA.Selenium.BiDi.Communication;
21+
using System.Collections.Generic;
22+
using System.Text.Json.Serialization;
2223

2324
namespace OpenQA.Selenium.BiDi.Emulation;
2425

2526
internal sealed class SetTimezoneOverrideCommand(SetTimezoneOverrideParameters @params)
2627
: Command<SetTimezoneOverrideParameters, EmptyResult>(@params, "emulation.setTimezoneOverride");
2728

28-
internal sealed record SetTimezoneOverrideParameters(string? Timezone, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
29+
internal sealed record SetTimezoneOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? Timezone, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
2930

3031
public sealed class SetTimezoneOverrideOptions : CommandOptions
3132
{

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
// under the License.
1818
// </copyright>
1919

20-
using System.Collections.Generic;
2120
using OpenQA.Selenium.BiDi.Communication;
21+
using System.Collections.Generic;
22+
using System.Text.Json.Serialization;
2223

2324
namespace OpenQA.Selenium.BiDi.Emulation;
2425

2526
internal sealed class SetUserAgentOverrideCommand(SetUserAgentOverrideParameters @params)
2627
: Command<SetUserAgentOverrideParameters, EmptyResult>(@params, "emulation.setUserAgentOverride");
2728

28-
internal sealed record SetUserAgentOverrideParameters(string? UserAgent, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
29+
internal sealed record SetUserAgentOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] string? UserAgent, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
2930

3031
public sealed class SetUserAgentOverrideOptions : CommandOptions
3132
{

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ class EmulationTest : BiDiTestFixture
2727
public void CanSetTimezoneOverride()
2828
{
2929
Assert.That(async () => await bidi.Emulation.SetTimezoneOverrideAsync("UTC", new () { Contexts = [context] }), Throws.Nothing);
30+
Assert.That(async () => await bidi.Emulation.SetTimezoneOverrideAsync(null, new () { Contexts = [context] }), Throws.Nothing);
3031
}
3132

3233
[Test]
3334
public void CanSetUserAgentOverride()
3435
{
3536
Assert.That(async () => await bidi.Emulation.SetUserAgentOverrideAsync("MyUserAgent/1.0", new () { Contexts = [context] }), Throws.Nothing);
37+
Assert.That(async () => await bidi.Emulation.SetUserAgentOverrideAsync(null, new () { Contexts = [context] }), Throws.Nothing);
38+
}
39+
40+
[Test]
41+
public void CanSetLocaleOverride()
42+
{
43+
Assert.That(async () => await bidi.Emulation.SetLocaleOverrideAsync("en-US", new () { Contexts = [context] }), Throws.Nothing);
44+
Assert.That(async () => await bidi.Emulation.SetLocaleOverrideAsync(null, new () { Contexts = [context] }), Throws.Nothing);
3645
}
3746
}

0 commit comments

Comments
 (0)