Skip to content

Commit 3ce647f

Browse files
authored
[dotnet] [bidi] AOT safe enums serialization (#16386)
1 parent 4db2c56 commit 3ce647f

26 files changed

+121
-127
lines changed

dotnet/src/webdriver/BiDi/Browser/ClientWindowInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
21+
using System.Text.Json.Serialization;
22+
2023
namespace OpenQA.Selenium.BiDi.Browser;
2124

2225
public sealed record ClientWindowInfo(bool Active, ClientWindow ClientWindow, ClientWindowState State, int Height, int Width, int X, int Y);
2326

27+
[JsonConverter(typeof(CamelCaseEnumConverter<ClientWindowState>))]
2428
public enum ClientWindowState
2529
{
2630
Fullscreen,

dotnet/src/webdriver/BiDi/BrowsingContext/CaptureScreenshotCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Communication;
21+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
2122
using System;
2223
using System.Text.Json.Serialization;
2324

@@ -37,6 +38,7 @@ public sealed class CaptureScreenshotOptions : CommandOptions
3738
public ClipRectangle? Clip { get; set; }
3839
}
3940

41+
[JsonConverter(typeof(CamelCaseEnumConverter<ScreenshotOrigin>))]
4042
public enum ScreenshotOrigin
4143
{
4244
Viewport,

dotnet/src/webdriver/BiDi/BrowsingContext/CreateCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Communication;
21+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
22+
using System.Text.Json.Serialization;
2123

2224
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2325

@@ -35,6 +37,7 @@ public sealed class CreateOptions : CommandOptions
3537
public Browser.UserContext? UserContext { get; set; }
3638
}
3739

40+
[JsonConverter(typeof(CamelCaseEnumConverter<ContextType>))]
3841
public enum ContextType
3942
{
4043
Tab,

dotnet/src/webdriver/BiDi/BrowsingContext/Locator.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
2021
using System.Text.Json.Serialization;
2122

2223
namespace OpenQA.Selenium.BiDi.BrowsingContext;
@@ -54,6 +55,7 @@ public sealed record AccessibilityValue
5455

5556
public sealed record ContextValue(BrowsingContext Context);
5657

58+
[JsonConverter(typeof(CamelCaseEnumConverter<MatchType>))]
5759
public enum MatchType
5860
{
5961
Full,

dotnet/src/webdriver/BiDi/BrowsingContext/NavigateCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Communication;
21+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
22+
using System.Text.Json.Serialization;
2123

2224
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2325

@@ -31,6 +33,7 @@ public sealed class NavigateOptions : CommandOptions
3133
public ReadinessState? Wait { get; set; }
3234
}
3335

36+
[JsonConverter(typeof(CamelCaseEnumConverter<ReadinessState>))]
3437
public enum ReadinessState
3538
{
3639
None,

dotnet/src/webdriver/BiDi/BrowsingContext/PrintCommand.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
// </copyright>
1919

2020
using OpenQA.Selenium.BiDi.Communication;
21+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
2122
using System;
2223
using System.Collections.Generic;
24+
using System.Text.Json.Serialization;
2325

2426
namespace OpenQA.Selenium.BiDi.BrowsingContext;
2527

@@ -56,6 +58,7 @@ public struct PrintMargin
5658
public double? Top { get; set; }
5759
}
5860

61+
[JsonConverter(typeof(CamelCaseEnumConverter<PrintOrientation>))]
5962
public enum PrintOrientation
6063
{
6164
Portrait,

dotnet/src/webdriver/BiDi/BrowsingContext/UserPromptOpenedEventArgs.cs

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

20+
using OpenQA.Selenium.BiDi.Communication.Json.Converters;
2021
using System.Text.Json.Serialization;
2122

2223
namespace OpenQA.Selenium.BiDi.BrowsingContext;
@@ -28,6 +29,7 @@ public sealed record UserPromptOpenedEventArgs(BiDi BiDi, BrowsingContext Contex
2829
public string? DefaultValue { get; internal set; }
2930
}
3031

32+
[JsonConverter(typeof(CamelCaseEnumConverter<UserPromptType>))]
3133
public enum UserPromptType
3234
{
3335
Alert,

dotnet/src/webdriver/BiDi/Communication/Broker.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,11 @@ internal Broker(BiDi bidi, Uri url)
8383
new InternalIdConverter(_bidi),
8484
new PreloadScriptConverter(_bidi),
8585
new RealmConverter(_bidi),
86-
new RealmTypeConverter(),
87-
new ScreenOrientationTypeConverter(),
8886
new DateTimeOffsetConverter(),
8987
new PrintPageRangeConverter(),
9088
new InputOriginConverter(),
9189
new WebExtensionConverter(_bidi),
9290
new SubscriptionConverter(),
93-
new JsonStringEnumConverter(JsonNamingPolicy.CamelCase),
9491

9592
// https://github.com/dotnet/runtime/issues/72604
9693
new Json.Converters.Polymorphic.EvaluateResultConverter(),
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// <copyright file="CamelCaseEnumConverter.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;
21+
using System.Text.Json;
22+
using System.Text.Json.Serialization;
23+
24+
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
25+
26+
public class CamelCaseEnumConverter<TEnum>() :
27+
JsonStringEnumConverter<TEnum>(JsonNamingPolicy.CamelCase) where TEnum : struct, Enum;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// <copyright file="KebabCaseEnumConverter.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;
21+
using System.Text.Json;
22+
using System.Text.Json.Serialization;
23+
24+
namespace OpenQA.Selenium.BiDi.Communication.Json.Converters;
25+
26+
public class KebabCaseEnumConverter<TEnum>() :
27+
JsonStringEnumConverter<TEnum>(JsonNamingPolicy.KebabCaseLower) where TEnum : struct, Enum;

0 commit comments

Comments
 (0)