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
11 changes: 11 additions & 0 deletions dotnet/src/webdriver/BiDi/Emulation/EmulationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ internal sealed class EmulationModule : Module, IEmulationModule
private static readonly Command<SetLocaleOverrideParameters, SetLocaleOverrideResult> SetLocaleOverrideCommand = new(
"emulation.setLocaleOverride", Default.SetLocaleOverrideParameters, Default.SetLocaleOverrideResult);

private static readonly Command<SetMediaFeaturesOverrideParameters, SetMediaFeaturesOverrideResult> SetMediaFeaturesOverrideCommand = new(
"emulation.setMediaFeaturesOverride", Default.SetMediaFeaturesOverrideParameters, Default.SetMediaFeaturesOverrideResult);

private static readonly Command<SetForcedColorsModeThemeOverrideParameters, SetForcedColorsModeThemeOverrideResult> SetForcedColorsModeThemeOverrideCommand = new(
"emulation.setForcedColorsModeThemeOverride", Default.SetForcedColorsModeThemeOverrideParameters, Default.SetForcedColorsModeThemeOverrideResult);

Expand Down Expand Up @@ -75,6 +78,12 @@ public async Task<SetLocaleOverrideResult> SetLocaleOverrideAsync(string? locale
return await ExecuteAsync(SetLocaleOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public async Task<SetMediaFeaturesOverrideResult> SetMediaFeaturesOverrideAsync(MediaFeatures? features, SetMediaFeaturesOverrideOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new SetMediaFeaturesOverrideParameters(features, options?.Contexts, options?.UserContexts);
return await ExecuteAsync(SetMediaFeaturesOverrideCommand, @params, options, cancellationToken).ConfigureAwait(false);
}

public async Task<SetForcedColorsModeThemeOverrideResult> SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme? theme, SetForcedColorsModeThemeOverrideOptions? options = null, CancellationToken cancellationToken = default)
{
var @params = new SetForcedColorsModeThemeOverrideParameters(theme, options?.Contexts, options?.UserContexts);
Expand Down Expand Up @@ -141,6 +150,8 @@ public async Task<SetNetworkConditionsResult> SetNetworkConditionsAsync(NetworkC
[JsonSerializable(typeof(SetUserAgentOverrideResult))]
[JsonSerializable(typeof(SetLocaleOverrideParameters))]
[JsonSerializable(typeof(SetLocaleOverrideResult))]
[JsonSerializable(typeof(SetMediaFeaturesOverrideParameters))]
[JsonSerializable(typeof(SetMediaFeaturesOverrideResult))]
[JsonSerializable(typeof(SetForcedColorsModeThemeOverrideParameters))]
[JsonSerializable(typeof(SetForcedColorsModeThemeOverrideResult))]
[JsonSerializable(typeof(SetScriptingEnabledParameters))]
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/webdriver/BiDi/Emulation/IEmulationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface IEmulationModule
Task<SetForcedColorsModeThemeOverrideResult> SetForcedColorsModeThemeOverrideAsync(ForcedColorsModeTheme? theme, SetForcedColorsModeThemeOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetGeolocationOverrideResult> SetGeolocationOverrideAsync(GeolocationOverride? geolocationOverride, SetGeolocationOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetLocaleOverrideResult> SetLocaleOverrideAsync(string? locale, SetLocaleOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetMediaFeaturesOverrideResult> SetMediaFeaturesOverrideAsync(MediaFeatures? features, SetMediaFeaturesOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetNetworkConditionsResult> SetNetworkConditionsAsync(NetworkConditions? networkConditions, SetNetworkConditionsOptions? options = null, CancellationToken cancellationToken = default);
Task<SetScreenOrientationOverrideResult> SetScreenOrientationOverrideAsync(ScreenOrientation? screenOrientation, SetScreenOrientationOverrideOptions? options = null, CancellationToken cancellationToken = default);
Task<SetScreenSettingsOverrideResult> SetScreenSettingsOverrideAsync(ScreenArea? screenArea, SetScreenSettingsOverrideOptions? options = null, CancellationToken cancellationToken = default);
Expand Down
338 changes: 338 additions & 0 deletions dotnet/src/webdriver/BiDi/Emulation/SetMediaFeaturesOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
// <copyright file="SetMediaFeaturesOverride.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.Text.Json.Serialization;
using OpenQA.Selenium.BiDi.Json.Converters;

namespace OpenQA.Selenium.BiDi.Emulation;

internal sealed record SetMediaFeaturesOverrideParameters(
[property: JsonIgnore(Condition = JsonIgnoreCondition.Never)] MediaFeatures? Features,
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
ImmutableArray<BrowsingContext.BrowsingContext>? Contexts,
ImmutableArray<Browser.UserContext>? UserContexts)
: Parameters;

public sealed record SetMediaFeaturesOverrideOptions : CommandOptions
{
public ImmutableArray<BrowsingContext.BrowsingContext>? Contexts { get; init; }

public ImmutableArray<Browser.UserContext>? UserContexts { get; init; }
}

public sealed record MediaFeatures
{
[JsonPropertyName("any-hover")]
[JsonConverter(typeof(OptionalConverter<AnyHover?>))]
public Optional<AnyHover?>? AnyHover { get; init; }

[JsonPropertyName("any-pointer")]
[JsonConverter(typeof(OptionalConverter<AnyPointer?>))]
public Optional<AnyPointer?>? AnyPointer { get; init; }

[JsonPropertyName("color")]
[JsonConverter(typeof(OptionalConverter<long?>))]
public Optional<long?>? Color { get; init; }

[JsonPropertyName("color-gamut")]
[JsonConverter(typeof(OptionalConverter<ColorGamut?>))]
public Optional<ColorGamut?>? ColorGamut { get; init; }

[JsonPropertyName("color-index")]
[JsonConverter(typeof(OptionalConverter<long?>))]
public Optional<long?>? ColorIndex { get; init; }

[JsonPropertyName("display-mode")]
[JsonConverter(typeof(OptionalConverter<DisplayMode?>))]
public Optional<DisplayMode?>? DisplayMode { get; init; }

[JsonPropertyName("dynamic-range")]
[JsonConverter(typeof(OptionalConverter<DynamicRange?>))]
public Optional<DynamicRange?>? DynamicRange { get; init; }

[JsonPropertyName("environment-blending")]
[JsonConverter(typeof(OptionalConverter<EnvironmentBlending?>))]
public Optional<EnvironmentBlending?>? EnvironmentBlending { get; init; }

[JsonPropertyName("forced-colors")]
[JsonConverter(typeof(OptionalConverter<ForcedColors?>))]
public Optional<ForcedColors?>? ForcedColors { get; init; }

[JsonPropertyName("grid")]
[JsonConverter(typeof(OptionalConverter<Grid?>))]
public Optional<Grid?>? Grid { get; init; }

[JsonPropertyName("horizontal-viewport-segments")]
[JsonConverter(typeof(OptionalConverter<long?>))]
public Optional<long?>? HorizontalViewportSegments { get; init; }

[JsonPropertyName("hover")]
[JsonConverter(typeof(OptionalConverter<Hover?>))]
public Optional<Hover?>? Hover { get; init; }

[JsonPropertyName("inverted-colors")]
[JsonConverter(typeof(OptionalConverter<InvertedColors?>))]
public Optional<InvertedColors?>? InvertedColors { get; init; }

[JsonPropertyName("monochrome")]
[JsonConverter(typeof(OptionalConverter<long?>))]
public Optional<long?>? Monochrome { get; init; }

[JsonPropertyName("nav-controls")]
[JsonConverter(typeof(OptionalConverter<NavControls?>))]
public Optional<NavControls?>? NavControls { get; init; }

[JsonPropertyName("overflow-block")]
[JsonConverter(typeof(OptionalConverter<OverflowBlock?>))]
public Optional<OverflowBlock?>? OverflowBlock { get; init; }

[JsonPropertyName("overflow-inline")]
[JsonConverter(typeof(OptionalConverter<OverflowInline?>))]
public Optional<OverflowInline?>? OverflowInline { get; init; }

[JsonPropertyName("pointer")]
[JsonConverter(typeof(OptionalConverter<Pointer?>))]
public Optional<Pointer?>? Pointer { get; init; }

[JsonPropertyName("prefers-color-scheme")]
[JsonConverter(typeof(OptionalConverter<PrefersColorScheme?>))]
public Optional<PrefersColorScheme?>? PrefersColorScheme { get; init; }

[JsonPropertyName("prefers-contrast")]
[JsonConverter(typeof(OptionalConverter<PrefersContrast?>))]
public Optional<PrefersContrast?>? PrefersContrast { get; init; }

[JsonPropertyName("prefers-reduced-data")]
[JsonConverter(typeof(OptionalConverter<PrefersReducedData?>))]
public Optional<PrefersReducedData?>? PrefersReducedData { get; init; }

[JsonPropertyName("prefers-reduced-motion")]
[JsonConverter(typeof(OptionalConverter<PrefersReducedMotion?>))]
public Optional<PrefersReducedMotion?>? PrefersReducedMotion { get; init; }

[JsonPropertyName("prefers-reduced-transparency")]
[JsonConverter(typeof(OptionalConverter<PrefersReducedTransparency?>))]
public Optional<PrefersReducedTransparency?>? PrefersReducedTransparency { get; init; }

[JsonPropertyName("scan")]
[JsonConverter(typeof(OptionalConverter<Scan?>))]
public Optional<Scan?>? Scan { get; init; }

[JsonPropertyName("scripting")]
[JsonConverter(typeof(OptionalConverter<Scripting?>))]
public Optional<Scripting?>? Scripting { get; init; }

[JsonPropertyName("update")]
[JsonConverter(typeof(OptionalConverter<Update?>))]
public Optional<Update?>? Update { get; init; }

[JsonPropertyName("vertical-viewport-segments")]
[JsonConverter(typeof(OptionalConverter<long?>))]
public Optional<long?>? VerticalViewportSegments { get; init; }

[JsonPropertyName("video-color-gamut")]
[JsonConverter(typeof(OptionalConverter<VideoColorGamut?>))]
public Optional<VideoColorGamut?>? VideoColorGamut { get; init; }

[JsonPropertyName("video-dynamic-range")]
[JsonConverter(typeof(OptionalConverter<VideoDynamicRange?>))]
public Optional<VideoDynamicRange?>? VideoDynamicRange { get; init; }
}

[JsonConverter(typeof(KebabCaseEnumConverter<AnyHover>))]
public enum AnyHover
{
None,
Hover
}

[JsonConverter(typeof(KebabCaseEnumConverter<AnyPointer>))]
public enum AnyPointer
{
None,
Coarse,
Fine
}

[JsonConverter(typeof(KebabCaseEnumConverter<ColorGamut>))]
public enum ColorGamut
{
Srgb,
P3,
Rec2020
}

[JsonConverter(typeof(KebabCaseEnumConverter<DisplayMode>))]
public enum DisplayMode
{
Fullscreen,
Standalone,
MinimalUi,
Browser,
PictureInPicture
}

[JsonConverter(typeof(KebabCaseEnumConverter<DynamicRange>))]
public enum DynamicRange
{
Standard,
High
}

[JsonConverter(typeof(KebabCaseEnumConverter<EnvironmentBlending>))]
public enum EnvironmentBlending
{
Opaque,
Additive,
Subtractive
}

[JsonConverter(typeof(KebabCaseEnumConverter<ForcedColors>))]
public enum ForcedColors
{
None,
Active
}

public enum Grid
{
Zero = 0,
One = 1
}

[JsonConverter(typeof(KebabCaseEnumConverter<Hover>))]
public enum Hover
{
None,
Hover
}

[JsonConverter(typeof(KebabCaseEnumConverter<InvertedColors>))]
public enum InvertedColors
{
None,
Inverted
}

[JsonConverter(typeof(KebabCaseEnumConverter<NavControls>))]
public enum NavControls
{
None,
Back
}

[JsonConverter(typeof(KebabCaseEnumConverter<OverflowBlock>))]
public enum OverflowBlock
{
None,
Scroll,
OptionalPaged,
Paged
}

[JsonConverter(typeof(KebabCaseEnumConverter<OverflowInline>))]
public enum OverflowInline
{
None,
Scroll
}

[JsonConverter(typeof(KebabCaseEnumConverter<Pointer>))]
public enum Pointer
{
None,
Coarse,
Fine
}

[JsonConverter(typeof(KebabCaseEnumConverter<PrefersColorScheme>))]
public enum PrefersColorScheme
{
Light,
Dark
}

[JsonConverter(typeof(KebabCaseEnumConverter<PrefersContrast>))]
public enum PrefersContrast
{
NoPreference,
More,
Less,
Custom
}

[JsonConverter(typeof(KebabCaseEnumConverter<PrefersReducedData>))]
public enum PrefersReducedData
{
NoPreference,
Reduce
}

[JsonConverter(typeof(KebabCaseEnumConverter<PrefersReducedMotion>))]
public enum PrefersReducedMotion
{
NoPreference,
Reduce
}

[JsonConverter(typeof(KebabCaseEnumConverter<PrefersReducedTransparency>))]
public enum PrefersReducedTransparency
{
NoPreference,
Reduce
}

[JsonConverter(typeof(KebabCaseEnumConverter<Scan>))]
public enum Scan
{
Interlace,
Progressive
}

[JsonConverter(typeof(KebabCaseEnumConverter<Scripting>))]
public enum Scripting
{
None,
InitialOnly,
Enabled
}

[JsonConverter(typeof(KebabCaseEnumConverter<Update>))]
public enum Update
{
None,
Slow,
Fast
}

[JsonConverter(typeof(KebabCaseEnumConverter<VideoColorGamut>))]
public enum VideoColorGamut
{
Srgb,
P3,
Rec2020
}

[JsonConverter(typeof(KebabCaseEnumConverter<VideoDynamicRange>))]
public enum VideoDynamicRange
{
Standard,
High
}

public sealed record SetMediaFeaturesOverrideResult : EmptyResult;
Loading