Skip to content

Commit 27566b8

Browse files
committed
Move .NET domain factory for DevTools into DevToolsDomains class
1 parent c6f9314 commit 27566b8

7 files changed

Lines changed: 58 additions & 89 deletions

File tree

dotnet/src/webdriver/DevTools/DevToolsDomainFactory.cs renamed to dotnet/src/webdriver/DevTools/DevToolsDomains.cs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="DevToolsomainFactory.cs" company="WebDriver Committers">
1+
// <copyright file="IDomains.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -14,7 +14,6 @@
1414
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
17-
// </copyright>
1817

1918
using System;
2019
using System.Collections.Generic;
@@ -24,9 +23,9 @@
2423
namespace OpenQA.Selenium.DevTools
2524
{
2625
/// <summary>
27-
/// Factory class used to create the set of DevTools Protocol domains specific to the specified version of the browser.
26+
/// Interface providing version-independent implementations of operations available using the DevTools Protocol.
2827
/// </summary>
29-
public static class DevToolsDomainFactory
28+
public abstract class DevToolsDomains
3029
{
3130
// By default, we will look for a supported version within this
3231
// number of versions, as that will most likely still work.
@@ -43,33 +42,57 @@ public static class DevToolsDomainFactory
4342
typeof(V84.V84Domains)
4443
};
4544

45+
/// <summary>
46+
/// Gets the version-specific domains for the DevTools session. This value must be cast to a version specific type to be at all useful.
47+
/// </summary>
48+
public abstract DevToolsSessionDomains VersionSpecificDomains { get; }
49+
50+
/// <summary>
51+
/// Gets the object used for manipulating network information in the browser.
52+
/// </summary>
53+
public abstract Network Network { get; }
54+
55+
/// <summary>
56+
/// Gets the object used for manipulating the browser's JavaScript execution.
57+
/// </summary>
58+
public abstract JavaScript JavaScript { get; }
59+
60+
/// <summary>
61+
/// Gets the object used for manipulating DevTools Protocol targets.
62+
/// </summary>
63+
public abstract Target Target { get; }
64+
65+
/// <summary>
66+
/// Gets the object used for manipulating the browser's logs.
67+
/// </summary>
68+
public abstract Log Log { get; }
69+
4670
/// <summary>
4771
/// Initializes the supplied DevTools session's domains for the specified browser version.
4872
/// </summary>
4973
/// <param name="versionInfo">The <see cref="DevToolsVersionInfo"/> object containing the browser version information.</param>
5074
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialiize the domains.</param>
51-
/// <returns>The <see cref="IDomains"/> object containing the version-specific domains.</returns>
52-
public static IDomains InitializeDomains(DevToolsVersionInfo versionInfo, DevToolsSession session)
75+
/// <returns>The <see cref="DevToolsDomains"/> object containing the version-specific domains.</returns>
76+
public static DevToolsDomains InitializeDomains(DevToolsVersionInfo versionInfo, DevToolsSession session)
5377
{
5478
return InitializeDomains(versionInfo, session, DefaultVersionRange);
5579
}
5680

57-
5881
/// <summary>
5982
/// Initializes the supplied DevTools session's domains for the specified browser version within the specified number of versions.
6083
/// </summary>
6184
/// <param name="versionInfo">The <see cref="DevToolsVersionInfo"/> object containing the browser version information.</param>
6285
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialiize the domains.</param>
6386
/// <param name="versionRange">The range of versions within which to match the provided version number. Defaults to 5 versions.</param>
64-
/// <returns>The <see cref="IDomains"/> object containing the version-specific domains.</returns>
65-
public static IDomains InitializeDomains(DevToolsVersionInfo versionInfo, DevToolsSession session, int versionRange)
87+
/// <returns>The <see cref="DevToolsDomains"/> object containing the version-specific domains.</returns>
88+
public static DevToolsDomains InitializeDomains(DevToolsVersionInfo versionInfo, DevToolsSession session, int versionRange)
6689
{
6790
if (versionRange < 0)
6891
{
6992
throw new ArgumentException("Version range must be positive", "versionRange");
7093
}
7194

72-
IDomains domains = null;
95+
DevToolsDomains domains = null;
7396
int browserMajorVersion = 0;
7497
bool versionParsed = int.TryParse(versionInfo.BrowserMajorVersion, out browserMajorVersion);
7598
if (versionParsed)
@@ -78,7 +101,7 @@ public static IDomains InitializeDomains(DevToolsVersionInfo versionInfo, DevToo
78101
ConstructorInfo constructor = domainType.GetConstructor(new Type[] { typeof(DevToolsSession) });
79102
if (constructor != null)
80103
{
81-
domains = constructor.Invoke(new object[] { session }) as IDomains;
104+
domains = constructor.Invoke(new object[] { session }) as DevToolsDomains;
82105
}
83106
}
84107

@@ -90,7 +113,7 @@ private static Type MatchDomainsVersion(int desiredVersion, int versionRange)
90113
// Use reflection to look for a DevToolsVersion static field on every known domain implementation type
91114
foreach (Type candidateType in SupportedDevToolsVersions)
92115
{
93-
FieldInfo info = candidateType.GetField("DevToolsVersion", BindingFlags.Static | BindingFlags.Public);
116+
PropertyInfo info = candidateType.GetProperty("DevToolsVersion", BindingFlags.Static | BindingFlags.Public);
94117
if (info != null)
95118
{
96119
object propertyValue = info.GetValue(null);

dotnet/src/webdriver/DevTools/DevToolsSession.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class DevToolsSession : IDevToolsSession
4444
private ConcurrentDictionary<long, DevToolsCommandData> pendingCommands = new ConcurrentDictionary<long, DevToolsCommandData>();
4545
private long currentCommandId = 0;
4646

47-
private IDomains domains;
47+
private DevToolsDomains domains;
4848

4949
private Task receiveTask;
5050

@@ -94,7 +94,7 @@ public DevToolsSession(string endpointAddress)
9494
/// <summary>
9595
/// Gets the version-independent domain implementation for this Developer Tools connection
9696
/// </summary>
97-
public IDomains Domains => this.domains;
97+
public DevToolsDomains Domains => this.domains;
9898

9999
/// <summary>
100100
/// Gets the version-specific implementation of domains for this DevTools session.
@@ -254,7 +254,7 @@ public async Task Start()
254254
var versionInfo = JsonConvert.DeserializeObject<DevToolsVersionInfo>(rawVersionInfo);
255255
websocketAddress = versionInfo.WebSocketDebuggerUrl;
256256

257-
this.domains = DevToolsDomainFactory.InitializeDomains(versionInfo, this);
257+
this.domains = DevToolsDomains.InitializeDomains(versionInfo, this);
258258

259259
string targetId = null;
260260
var targets = await this.domains.Target.GetTargets();

dotnet/src/webdriver/DevTools/IDomains.cs

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

dotnet/src/webdriver/DevTools/v84/V84Domains.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace OpenQA.Selenium.DevTools.V84
2424
/// <summary>
2525
/// Class containing the domain implementation for version 84 of the DevTools Protocol.
2626
/// </summary>
27-
public class V84Domains : IDomains
27+
public class V84Domains : DevToolsDomains
2828
{
2929
private DevToolsSessionDomains domains;
3030

@@ -45,26 +45,26 @@ public V84Domains(DevToolsSession session)
4545
/// <summary>
4646
/// Gets the version-specific domains for the DevTools session. This value must be cast to a version specific type to be at all useful.
4747
/// </summary>
48-
public DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
48+
public override DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
4949

5050
/// <summary>
5151
/// Gets the object used for manipulating network information in the browser.
5252
/// </summary>
53-
public DevTools.Network Network => new V84Network(domains.Network, domains.Fetch);
53+
public override DevTools.Network Network => new V84Network(domains.Network, domains.Fetch);
5454

5555
/// <summary>
5656
/// Gets the object used for manipulating the browser's JavaScript execution.
5757
/// </summary>
58-
public JavaScript JavaScript => new V84JavaScript(domains.Runtime, domains.Page);
58+
public override JavaScript JavaScript => new V84JavaScript(domains.Runtime, domains.Page);
5959

6060
/// <summary>
6161
/// Gets the object used for manipulating DevTools Protocol targets.
6262
/// </summary>
63-
public DevTools.Target Target => new V84Target(domains.Target);
63+
public override DevTools.Target Target => new V84Target(domains.Target);
6464

6565
/// <summary>
6666
/// Gets the object used for manipulating the browser's logs.
6767
/// </summary>
68-
public DevTools.Log Log => new V84Log(domains.Log);
68+
public override DevTools.Log Log => new V84Log(domains.Log);
6969
}
7070
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace OpenQA.Selenium.DevTools.V85
2424
/// <summary>
2525
/// Class containing the domain implementation for version 85 of the DevTools Protocol.
2626
/// </summary>
27-
public class V85Domains : IDomains
27+
public class V85Domains : DevToolsDomains
2828
{
2929
private DevToolsSessionDomains domains;
3030

@@ -41,26 +41,26 @@ public V85Domains(DevToolsSession session)
4141
/// <summary>
4242
/// Gets the version-specific domains for the DevTools session. This value must be cast to a version specific type to be at all useful.
4343
/// </summary>
44-
public DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
44+
public override DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
4545

4646
/// <summary>
4747
/// Gets the object used for manipulating network information in the browser.
4848
/// </summary>
49-
public DevTools.Network Network => new V85Network(domains.Network, domains.Fetch);
49+
public override DevTools.Network Network => new V85Network(domains.Network, domains.Fetch);
5050

5151
/// <summary>
5252
/// Gets the object used for manipulating the browser's JavaScript execution.
5353
/// </summary>
54-
public JavaScript JavaScript => new V85JavaScript(domains.Runtime, domains.Page);
54+
public override JavaScript JavaScript => new V85JavaScript(domains.Runtime, domains.Page);
5555

5656
/// <summary>
5757
/// Gets the object used for manipulating DevTools Protocol targets.
5858
/// </summary>
59-
public DevTools.Target Target => new V85Target(domains.Target);
59+
public override DevTools.Target Target => new V85Target(domains.Target);
6060

6161
/// <summary>
6262
/// Gets the object used for manipulating the browser's logs.
6363
/// </summary>
64-
public DevTools.Log Log => new V85Log(domains.Log);
64+
public override DevTools.Log Log => new V85Log(domains.Log);
6565
}
6666
}

dotnet/src/webdriver/DevTools/v86/V86Domains.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace OpenQA.Selenium.DevTools.V86
2424
/// <summary>
2525
/// Class containing the domain implementation for version 86 of the DevTools Protocol.
2626
/// </summary>
27-
public class V86Domains : IDomains
27+
public class V86Domains : DevToolsDomains
2828
{
2929
private DevToolsSessionDomains domains;
3030

@@ -41,26 +41,26 @@ public V86Domains(DevToolsSession session)
4141
/// <summary>
4242
/// Gets the version-specific domains for the DevTools session. This value must be cast to a version specific type to be at all useful.
4343
/// </summary>
44-
public DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
44+
public override DevTools.DevToolsSessionDomains VersionSpecificDomains => this.domains;
4545

4646
/// <summary>
4747
/// Gets the object used for manipulating network information in the browser.
4848
/// </summary>
49-
public DevTools.Network Network => new V86Network(domains.Network, domains.Fetch);
49+
public override DevTools.Network Network => new V86Network(domains.Network, domains.Fetch);
5050

5151
/// <summary>
5252
/// Gets the object used for manipulating the browser's JavaScript execution.
5353
/// </summary>
54-
public JavaScript JavaScript => new V86JavaScript(domains.Runtime, domains.Page);
54+
public override JavaScript JavaScript => new V86JavaScript(domains.Runtime, domains.Page);
5555

5656
/// <summary>
5757
/// Gets the object used for manipulating DevTools Protocol targets.
5858
/// </summary>
59-
public DevTools.Target Target => new V86Target(domains.Target);
59+
public override DevTools.Target Target => new V86Target(domains.Target);
6060

6161
/// <summary>
6262
/// Gets the object used for manipulating the browser's logs.
6363
/// </summary>
64-
public DevTools.Log Log => new V86Log(domains.Log);
64+
public override DevTools.Log Log => new V86Log(domains.Log);
6565
}
6666
}

dotnet/test/common/appconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"DriverServiceLocation": "",
2+
"DriverServiceLocation": "C:\\Projects\\WebDriverServers",
33
"ActiveDriverConfig": "Chrome",
4-
"ActiveWebsiteConfig": "Default",
4+
"ActiveWebsiteConfig": "HostsFileRedirect",
55
"TestWebServerConfig": {
66
"CaptureConsoleOutput": false,
77
"HideCommandPromptWindow": true,

0 commit comments

Comments
 (0)