Skip to content

Commit f960916

Browse files
committed
Revert DevTools JSON handling by domains
1 parent e92ac14 commit f960916

File tree

10 files changed

+16
-269
lines changed

10 files changed

+16
-269
lines changed

dotnet/src/webdriver/DevTools/DevToolsDomains.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ public abstract class DevToolsDomains
7070
/// </summary>
7171
public abstract Log Log { get; }
7272

73-
internal abstract JsonNode SerializeToNode<TCommand>(TCommand command)
74-
where TCommand : ICommand;
75-
76-
internal abstract ICommandResponse<TCommand> DeserializeCommandResponse<TCommand>(JsonElement responseJson)
77-
where TCommand : ICommand;
78-
79-
internal abstract TCommandResponse Deserialize<TCommandResponse>(JsonElement responseJson)
80-
where TCommandResponse : ICommandResponse;
81-
8273
/// <summary>
8374
/// Initializes the supplied DevTools session's domains for the specified browser version.
8475
/// </summary>

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,19 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
157157
throw new ArgumentNullException(nameof(command));
158158
}
159159

160-
JsonNode serializedCommand = this.domains.SerializeToNode(command);
161-
162-
var result = await SendCommand(command.CommandName, serializedCommand, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
160+
var result = await SendCommand(command.CommandName, JsonSerializer.SerializeToNode(command), cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
163161

164162
if (result == null)
165163
{
166164
return null;
167165
}
168166

169-
return this.domains.DeserializeCommandResponse<TCommand>(result.Value);
167+
if (!this.domains.VersionSpecificDomains.ResponseTypeMap.TryGetCommandResponseType<TCommand>(out Type commandResponseType))
168+
{
169+
throw new InvalidOperationException($"Type {command.GetType()} does not correspond to a known command response type.");
170+
}
171+
172+
return result.Value.Deserialize(commandResponseType) as ICommandResponse<TCommand>;
170173
}
171174

172175
/// <summary>
@@ -187,16 +190,19 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
187190
throw new ArgumentNullException(nameof(command));
188191
}
189192

190-
JsonNode serializedCommand = this.domains.SerializeToNode(command);
191-
192-
var result = await SendCommand(command.CommandName, sessionId, serializedCommand, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
193+
var result = await SendCommand(command.CommandName, sessionId, JsonSerializer.SerializeToNode(command), cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
193194

194195
if (result == null)
195196
{
196197
return null;
197198
}
198199

199-
return this.domains.DeserializeCommandResponse<TCommand>(result.Value);
200+
if (!this.domains.VersionSpecificDomains.ResponseTypeMap.TryGetCommandResponseType(command, out Type commandResponseType))
201+
{
202+
throw new InvalidOperationException($"Type {typeof(TCommand)} does not correspond to a known command response type.");
203+
}
204+
205+
return result.Value.Deserialize(commandResponseType) as ICommandResponse<TCommand>;
200206
}
201207

202208
/// <summary>
@@ -218,16 +224,14 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
218224
throw new ArgumentNullException(nameof(command));
219225
}
220226

221-
JsonNode serializedCommand = this.domains.SerializeToNode(command);
222-
223-
var result = await SendCommand(command.CommandName, serializedCommand, cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
227+
var result = await SendCommand(command.CommandName, JsonSerializer.SerializeToNode(command), cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived).ConfigureAwait(false);
224228

225229
if (result == null)
226230
{
227231
return default(TCommandResponse);
228232
}
229233

230-
return this.domains.Deserialize<TCommandResponse>(result.Value);
234+
return result.Value.Deserialize<TCommandResponse>();
231235
}
232236

233237
/// <summary>

dotnet/src/webdriver/DevTools/v130/DevToolsSerializationContext.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

dotnet/src/webdriver/DevTools/v130/V130Domains.cs

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

20-
using System;
21-
using System.Text.Json;
22-
using System.Text.Json.Nodes;
23-
2420
namespace OpenQA.Selenium.DevTools.V130
2521
{
2622
/// <summary>
2723
/// Class containing the domain implementation for version 130 of the DevTools Protocol.
2824
/// </summary>
2925
public class V130Domains : DevToolsDomains
3026
{
31-
private static readonly JsonSerializerOptions jsonRequestSerializerOptions = new()
32-
{
33-
TypeInfoResolver = V130RequestSerializationContext.Default
34-
};
35-
36-
private static readonly JsonSerializerOptions jsonResponseSerializerOptions = new()
37-
{
38-
TypeInfoResolver = V130ResponseSerializationContext.Default
39-
};
40-
4127
private DevToolsSessionDomains domains;
4228

4329
/// <summary>
@@ -78,25 +64,5 @@ public V130Domains(DevToolsSession session)
7864
/// Gets the object used for manipulating the browser's logs.
7965
/// </summary>
8066
public override DevTools.Log Log => new V130Log(domains.Log);
81-
82-
internal override JsonNode SerializeToNode<TCommand>(TCommand command)
83-
{
84-
return JsonSerializer.SerializeToNode(command, jsonRequestSerializerOptions);
85-
}
86-
87-
internal override ICommandResponse<TCommand> DeserializeCommandResponse<TCommand>(JsonElement responseJson)
88-
{
89-
if (!this.VersionSpecificDomains.ResponseTypeMap.TryGetCommandResponseType<TCommand>(out Type commandResponseType))
90-
{
91-
throw new InvalidOperationException($"Type {typeof(TCommand)} does not correspond to a known command response type.");
92-
}
93-
94-
return (ICommandResponse<TCommand>)responseJson.Deserialize(commandResponseType, jsonResponseSerializerOptions);
95-
}
96-
97-
internal override TCommandResponse Deserialize<TCommandResponse>(JsonElement responseJson)
98-
{
99-
return responseJson.Deserialize<TCommandResponse>(jsonResponseSerializerOptions);
100-
}
10167
}
10268
}

dotnet/src/webdriver/DevTools/v131/DevToolsSerializationContext.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

dotnet/src/webdriver/DevTools/v131/V131Domains.cs

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

20-
using System;
21-
using System.Text.Json;
22-
using System.Text.Json.Nodes;
23-
2420
namespace OpenQA.Selenium.DevTools.V131
2521
{
2622
/// <summary>
2723
/// Class containing the domain implementation for version 131 of the DevTools Protocol.
2824
/// </summary>
2925
public class V131Domains : DevToolsDomains
3026
{
31-
private static readonly JsonSerializerOptions jsonRequestSerializerOptions = new()
32-
{
33-
TypeInfoResolver = V131RequestSerializationContext.Default
34-
};
35-
36-
private static readonly JsonSerializerOptions jsonResponseSerializerOptions = new()
37-
{
38-
TypeInfoResolver = V131ResponseSerializationContext.Default
39-
};
40-
4127
private DevToolsSessionDomains domains;
4228

4329
/// <summary>
@@ -78,25 +64,5 @@ public V131Domains(DevToolsSession session)
7864
/// Gets the object used for manipulating the browser's logs.
7965
/// </summary>
8066
public override DevTools.Log Log => new V131Log(domains.Log);
81-
82-
internal override JsonNode SerializeToNode<TCommand>(TCommand command)
83-
{
84-
return JsonSerializer.SerializeToNode(command, jsonRequestSerializerOptions);
85-
}
86-
87-
internal override ICommandResponse<TCommand> DeserializeCommandResponse<TCommand>(JsonElement responseJson)
88-
{
89-
if (!this.VersionSpecificDomains.ResponseTypeMap.TryGetCommandResponseType<TCommand>(out Type commandResponseType))
90-
{
91-
throw new InvalidOperationException($"Type {typeof(TCommand)} does not correspond to a known command response type.");
92-
}
93-
94-
return (ICommandResponse<TCommand>)responseJson.Deserialize(commandResponseType, jsonResponseSerializerOptions);
95-
}
96-
97-
internal override TCommandResponse Deserialize<TCommandResponse>(JsonElement responseJson)
98-
{
99-
return responseJson.Deserialize<TCommandResponse>(jsonResponseSerializerOptions);
100-
}
10167
}
10268
}

dotnet/src/webdriver/DevTools/v132/DevToolsSerializationContext.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

dotnet/src/webdriver/DevTools/v132/V132Domains.cs

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

20-
using System;
21-
using System.Text.Json;
22-
using System.Text.Json.Nodes;
23-
2420
namespace OpenQA.Selenium.DevTools.V132
2521
{
2622
/// <summary>
2723
/// Class containing the domain implementation for version 132 of the DevTools Protocol.
2824
/// </summary>
2925
public class V132Domains : DevToolsDomains
3026
{
31-
private static readonly JsonSerializerOptions jsonRequestSerializerOptions = new()
32-
{
33-
TypeInfoResolver = V132RequestSerializationContext.Default
34-
};
35-
36-
private static readonly JsonSerializerOptions jsonResponseSerializerOptions = new()
37-
{
38-
TypeInfoResolver = V132ResponseSerializationContext.Default
39-
};
40-
4127
private DevToolsSessionDomains domains;
4228

4329
/// <summary>
@@ -78,25 +64,5 @@ public V132Domains(DevToolsSession session)
7864
/// Gets the object used for manipulating the browser's logs.
7965
/// </summary>
8066
public override DevTools.Log Log => new V132Log(domains.Log);
81-
82-
internal override JsonNode SerializeToNode<TCommand>(TCommand command)
83-
{
84-
return JsonSerializer.SerializeToNode(command, jsonRequestSerializerOptions);
85-
}
86-
87-
internal override ICommandResponse<TCommand> DeserializeCommandResponse<TCommand>(JsonElement responseJson)
88-
{
89-
if (!this.VersionSpecificDomains.ResponseTypeMap.TryGetCommandResponseType<TCommand>(out Type commandResponseType))
90-
{
91-
throw new InvalidOperationException($"Type {typeof(TCommand)} does not correspond to a known command response type.");
92-
}
93-
94-
return (ICommandResponse<TCommand>)responseJson.Deserialize(commandResponseType, jsonResponseSerializerOptions);
95-
}
96-
97-
internal override TCommandResponse Deserialize<TCommandResponse>(JsonElement responseJson)
98-
{
99-
return responseJson.Deserialize<TCommandResponse>(jsonResponseSerializerOptions);
100-
}
10167
}
10268
}

dotnet/src/webdriver/DevTools/v85/DevToolsSerializationContext.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)