Skip to content

Commit 1af3dcb

Browse files
committed
SetForcedColorsModeTheme
1 parent de30f4b commit 1af3dcb

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,6 @@ namespace OpenQA.Selenium.BiDi.Communication.Json;
175175
[JsonSerializable(typeof(Emulation.SetTimezoneOverrideCommand))]
176176
[JsonSerializable(typeof(Emulation.SetUserAgentOverrideCommand))]
177177
[JsonSerializable(typeof(Emulation.SetLocaleOverrideCommand))]
178+
[JsonSerializable(typeof(Emulation.SetForcedColorsModeThemeOverrideCommand))]
178179

179180
internal partial class BiDiJsonSerializerContext : JsonSerializerContext;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
// http://www.apache.org/licenses/LICENSE-2.0
1111
//
12-
// Unless required by applicable law or agreed to in writing,
12+
// Unless required by applicable law or agreed in writing,
1313
// software distributed under the License is distributed on an
1414
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1515
// KIND, either express or implied. See the License for the
@@ -44,4 +44,11 @@ public async Task<EmptyResult> SetLocaleOverrideAsync(string? locale, SetLocaleO
4444

4545
return await Broker.ExecuteCommandAsync<SetLocaleOverrideCommand, EmptyResult>(new SetLocaleOverrideCommand(@params), options).ConfigureAwait(false);
4646
}
47+
48+
public async Task<EmptyResult> SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme? theme, SetForcedColorsModeThemeOverrideOptions? options = null)
49+
{
50+
var @params = new SetForcedColorsModeThemeOverrideParameters(theme, options?.Contexts, options?.UserContexts);
51+
52+
return await Broker.ExecuteCommandAsync<SetForcedColorsModeThemeOverrideCommand, EmptyResult>(new SetForcedColorsModeThemeOverrideCommand(@params), options).ConfigureAwait(false);
53+
}
4754
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// <copyright file="SetForcedColorsModeThemeOverrideCommand.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 SetForcedColorsModeThemeOverrideCommand(SetForcedColorsModeThemeOverrideParameters @params)
27+
: Command<SetForcedColorsModeThemeOverrideParameters, EmptyResult>(@params, "emulation.setForcedColorsModeThemeOverride");
28+
29+
internal sealed record SetForcedColorsModeThemeOverrideParameters([property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] ForcedColorsModeTheme? Theme, IEnumerable<BrowsingContext.BrowsingContext>? Contexts, IEnumerable<Browser.UserContext>? UserContexts) : Parameters;
30+
31+
public sealed class SetForcedColorsModeThemeOverrideOptions : CommandOptions
32+
{
33+
public IEnumerable<BrowsingContext.BrowsingContext>? Contexts { get; set; }
34+
35+
public IEnumerable<Browser.UserContext>? UserContexts { get; set; }
36+
}
37+
38+
public enum ForcedColorsModeTheme
39+
{
40+
Light,
41+
Dark
42+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,11 @@ public void CanSetLocaleOverride()
4343
Assert.That(async () => await bidi.Emulation.SetLocaleOverrideAsync("en-US", new () { Contexts = [context] }), Throws.Nothing);
4444
Assert.That(async () => await bidi.Emulation.SetLocaleOverrideAsync(null, new () { Contexts = [context] }), Throws.Nothing);
4545
}
46+
47+
[Test]
48+
public void CanSetForcedColorsModeThemeOverride()
49+
{
50+
Assert.That(async () => await bidi.Emulation.SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme.Light, new () { Contexts = [context] }), Throws.Nothing);
51+
Assert.That(async () => await bidi.Emulation.SetForcedColorsModeThemeOverrideAsync(null, new () { Contexts = [context] }), Throws.Nothing);
52+
}
4653
}

0 commit comments

Comments
 (0)