Skip to content

Commit c6f9314

Browse files
committed
Use abstract classes for DevTools domains instead of interfaces in .NET
1 parent 60a8343 commit c6f9314

21 files changed

+428
-416
lines changed

dotnet/src/webdriver/DevTools/ConsoleApiCalledEventArgs.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Collections.ObjectModel;
2122
using System.Text;
2223

2324
namespace OpenQA.Selenium.DevTools
@@ -40,6 +41,6 @@ public class ConsoleApiCalledEventArgs : EventArgs
4041
/// <summary>
4142
/// Gets the arguments of the call to the browser's console API.
4243
/// </summary>
43-
public List<ConsoleApiArgument> Arguments { get; internal set; }
44+
public ReadOnlyCollection<ConsoleApiArgument> Arguments { get; internal set; }
4445
}
4546
}

dotnet/src/webdriver/DevTools/IDomains.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public interface IDomains
3434
/// <summary>
3535
/// Gets the object used for manipulating network information in the browser.
3636
/// </summary>
37-
INetwork Network { get; }
37+
Network Network { get; }
3838

3939
/// <summary>
4040
/// Gets the object used for manipulating the browser's JavaScript execution.
4141
/// </summary>
42-
IJavaScript JavaScript { get; }
42+
JavaScript JavaScript { get; }
4343

4444
/// <summary>
4545
/// Gets the object used for manipulating DevTools Protocol targets.
4646
/// </summary>
47-
ITarget Target { get; }
47+
Target Target { get; }
4848

4949
/// <summary>
5050
/// Gets the object used for manipulating the browser's logs.
5151
/// </summary>
52-
ILog Log { get; }
52+
Log Log { get; }
5353
}
5454
}

dotnet/src/webdriver/DevTools/IJavaScript.cs renamed to dotnet/src/webdriver/DevTools/JavaScript.cs

+37-13
Original file line numberDiff line numberDiff line change
@@ -21,75 +21,99 @@
2121
namespace OpenQA.Selenium.DevTools
2222
{
2323
/// <summary>
24-
/// Interface representing the browser's JavaScript execution as referenced by the DevTools Protocol.
24+
/// Class representing the browser's JavaScript execution as referenced by the DevTools Protocol.
2525
/// </summary>
26-
public interface IJavaScript
26+
public abstract class JavaScript
2727
{
2828
/// <summary>
2929
/// Occurs when a JavaScript script binding is called.
3030
/// </summary>
31-
event EventHandler<BindingCalledEventArgs> BindingCalled;
31+
public event EventHandler<BindingCalledEventArgs> BindingCalled;
3232

3333
/// <summary>
3434
/// Occurs when the browser's JavaScript console API is called.
3535
/// </summary>
36-
event EventHandler<ConsoleApiCalledEventArgs> ConsoleApiCalled;
36+
public event EventHandler<ConsoleApiCalledEventArgs> ConsoleApiCalled;
3737

3838
/// <summary>
3939
/// Occurs when a JavaScript exception is thrown.
4040
/// </summary>
41-
event EventHandler<ExceptionThrownEventArgs> ExceptionThrown;
41+
public event EventHandler<ExceptionThrownEventArgs> ExceptionThrown;
4242

4343
/// <summary>
4444
/// Asynchronously enables the Runtime domain in the DevTools Protocol.
4545
/// </summary>
4646
/// <returns>A task that represents the asynchronous operation.</returns>
47-
Task EnableRuntime();
47+
public abstract Task EnableRuntime();
4848

4949
/// <summary>
5050
/// Asynchronously disables the Runtime domain in the DevTools Protocol.
5151
/// </summary>
5252
/// <returns>A task that represents the asynchronous operation.</returns>
53-
Task DisableRuntime();
53+
public abstract Task DisableRuntime();
5454

5555
/// <summary>
5656
/// Asynchronously enables the Page domain in the DevTools Protocol.
5757
/// </summary>
5858
/// <returns>A task that represents the asynchronous operation.</returns>
59-
Task EnablePage();
59+
public abstract Task EnablePage();
6060

6161
/// <summary>
6262
/// Asynchronously disables the Page domain in the DevTools Protocol.
6363
/// </summary>
6464
/// <returns>A task that represents the asynchronous operation.</returns>
65-
Task DisablePage();
65+
public abstract Task DisablePage();
6666

6767
/// <summary>
6868
/// Adds a binding to a specific JavaScript name.
6969
/// </summary>
7070
/// <param name="name">The name to which to bind to.</param>
7171
/// <returns>A task that represents the asynchronous operation.</returns>
72-
Task AddBinding(string name);
72+
public abstract Task AddBinding(string name);
7373

7474
/// <summary>
7575
/// Removes a binding from a specific JavaScript name.
7676
/// </summary>
7777
/// <param name="name">The name to which to remove the bind from.</param>
7878
/// <returns>A task that represents the asynchronous operation.</returns>
79-
Task RemoveBinding(string name);
79+
public abstract Task RemoveBinding(string name);
8080

8181
/// <summary>
8282
/// Adds a JavaScript snippet to evaluate when a new document is opened.
8383
/// </summary>
8484
/// <param name="script">The script to add to be evaluated when a new document is opened.</param>
8585
/// <returns>A task that represents the asynchronous operation. The task result contains the internal ID of the script.</returns>
86-
Task<string> AddScriptToEvaluateOnNewDocument(string script);
86+
public abstract Task<string> AddScriptToEvaluateOnNewDocument(string script);
8787

8888
/// <summary>
8989
/// Removes a JavaScript snippet from evaluate when a new document is opened.
9090
/// </summary>
9191
/// <param name="scriptId">The ID of the script to be removed.</param>
9292
/// <returns>A task that represents the asynchronous operation.</returns>
93-
Task RemoveScriptToEvaluateOnNewDocument(string scriptId);
93+
public abstract Task RemoveScriptToEvaluateOnNewDocument(string scriptId);
94+
95+
protected virtual void OnBindingCalled(BindingCalledEventArgs e)
96+
{
97+
if (this.BindingCalled != null)
98+
{
99+
this.BindingCalled(this, e);
100+
}
101+
}
102+
103+
protected virtual void OnConsoleApiCalled(ConsoleApiCalledEventArgs e)
104+
{
105+
if (this.ConsoleApiCalled != null)
106+
{
107+
this.ConsoleApiCalled(this, e);
108+
}
109+
}
110+
111+
protected virtual void OnExceptionThrown(ExceptionThrownEventArgs e)
112+
{
113+
if (this.ExceptionThrown != null)
114+
{
115+
this.ExceptionThrown(this, e);
116+
}
117+
}
94118
}
95119
}

dotnet/src/webdriver/DevTools/ILog.cs renamed to dotnet/src/webdriver/DevTools/Log.cs

+21-7
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,39 @@
2121
namespace OpenQA.Selenium.DevTools
2222
{
2323
/// <summary>
24-
/// Interface representing the browser's log as referenced by the DevTools Protocol.
24+
/// Class representing the browser's log as referenced by the DevTools Protocol.
2525
/// </summary>
26-
public interface ILog
26+
public abstract class Log
2727
{
2828
/// <summary>
2929
/// Occurs when an entry is added to the browser's log.
3030
/// </summary>
31-
event EventHandler<EntryAddedEventArgs> EntryAdded;
31+
public event EventHandler<EntryAddedEventArgs> EntryAdded;
3232

3333
/// <summary>
34-
/// Asynchrounously enables manipulation of the browser's log.
34+
/// Asynchronously enables manipulation of the browser's log.
3535
/// </summary>
3636
/// <returns>A task that represents the asynchronous operation.</returns>
37-
Task Enable();
37+
public abstract Task Enable();
3838

3939
/// <summary>
40-
/// Asynchrounously clears the browser's log.
40+
/// Asynchronously disables manipulation of the browser's log.
4141
/// </summary>
4242
/// <returns>A task that represents the asynchronous operation.</returns>
43-
Task Clear();
43+
public abstract Task Disable();
44+
45+
/// <summary>
46+
/// Asynchronously clears the browser's log.
47+
/// </summary>
48+
/// <returns>A task that represents the asynchronous operation.</returns>
49+
public abstract Task Clear();
50+
51+
protected virtual void OnEntryAdded(EntryAddedEventArgs e)
52+
{
53+
if (this.EntryAdded != null)
54+
{
55+
this.EntryAdded(this, e);
56+
}
57+
}
4458
}
4559
}

dotnet/src/webdriver/DevTools/INetwork.cs renamed to dotnet/src/webdriver/DevTools/Network.cs

+28-12
Original file line numberDiff line numberDiff line change
@@ -22,58 +22,58 @@
2222
namespace OpenQA.Selenium.DevTools
2323
{
2424
/// <summary>
25-
/// Interface providing functionality for manipulating network calls using DevTools Protocol commands
25+
/// Class providing functionality for manipulating network calls using DevTools Protocol commands
2626
/// </summary>
27-
public interface INetwork
27+
public abstract class Network
2828
{
2929
/// <summary>
3030
/// Occurs when a network request requires authorization.
3131
/// </summary>
32-
event EventHandler<AuthRequiredEventArgs> AuthRequired;
32+
public event EventHandler<AuthRequiredEventArgs> AuthRequired;
3333

3434
/// <summary>
3535
/// Occurs when a network request is intercepted.
3636
/// </summary>
37-
event EventHandler<RequestPausedEventArgs> RequestPaused;
37+
public event EventHandler<RequestPausedEventArgs> RequestPaused;
3838

3939
/// <summary>
4040
/// Asynchronously disables network caching.
4141
/// </summary>
4242
/// <returns>A task that represents the asynchronous operation.</returns>
43-
Task DisableNetworkCaching();
43+
public abstract Task DisableNetworkCaching();
4444

4545
/// <summary>
4646
/// Asynchronously enables network caching.
4747
/// </summary>
4848
/// <returns>A task that represents the asynchronous operation.</returns>
49-
Task EnableNetworkCaching();
49+
public abstract Task EnableNetworkCaching();
5050

5151
/// <summary>
5252
/// Asynchronously enables the fetch domain for all URL patterns.
5353
/// </summary>
5454
/// <returns>A task that represents the asynchronous operation.</returns>
55-
Task EnableFetchForAllPatterns();
55+
public abstract Task EnableFetchForAllPatterns();
5656

5757
/// <summary>
5858
/// Asynchronously diables the fetch domain.
5959
/// </summary>
6060
/// <returns>A task that represents the asynchronous operation.</returns>
61-
Task DisableFetch();
61+
public abstract Task DisableFetch();
6262

6363
/// <summary>
6464
/// Asynchronously continues an intercepted network request.
6565
/// </summary>
6666
/// <param name="requestData">The <see cref="HttpRequestData"/> of the request.</param>
6767
/// <param name="responseData">The <see cref="HttpResponseData"/> with which to respond to the request</param>
6868
/// <returns>A task that represents the asynchronous operation.</returns>
69-
Task ContinueRequest(HttpRequestData requestData, HttpResponseData responseData);
69+
public abstract Task ContinueRequest(HttpRequestData requestData, HttpResponseData responseData);
7070

7171
/// <summary>
7272
/// Asynchronously contines an intercepted network call without modification.
7373
/// </summary>
7474
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
7575
/// <returns>A task that represents the asynchronous operation.</returns>
76-
Task ContinueWithoutModification(HttpRequestData requestData);
76+
public abstract Task ContinueWithoutModification(HttpRequestData requestData);
7777

7878
/// <summary>
7979
/// Asynchronously continues an intercepted network call using authentication.
@@ -82,13 +82,29 @@ public interface INetwork
8282
/// <param name="userName">The user name with which to authenticate.</param>
8383
/// <param name="password">The password with which to authenticate.</param>
8484
/// <returns>A task that represents the asynchronous operation.</returns>
85-
Task ContinueWithAuth(HttpRequestData requestData, string userName, string password);
85+
public abstract Task ContinueWithAuth(HttpRequestData requestData, string userName, string password);
8686

8787
/// <summary>
8888
/// Asynchronously cancels authorization of an intercepted network request.
8989
/// </summary>
9090
/// <param name="requestData">The <see cref="HttpRequestData"/> of the network request.</param>
9191
/// <returns>A task that represents the asynchronous operation.</returns>
92-
Task CancelAuth(HttpRequestData requestData);
92+
public abstract Task CancelAuth(HttpRequestData requestData);
93+
94+
protected virtual void OnAuthRequired(AuthRequiredEventArgs e)
95+
{
96+
if (this.AuthRequired != null)
97+
{
98+
this.AuthRequired(this, e);
99+
}
100+
}
101+
102+
protected virtual void OnRequestPaused(RequestPausedEventArgs e)
103+
{
104+
if (this.RequestPaused != null)
105+
{
106+
this.RequestPaused(this, e);
107+
}
108+
}
93109
}
94110
}

dotnet/src/webdriver/DevTools/ITarget.cs renamed to dotnet/src/webdriver/DevTools/Target.cs

+16-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
// </copyright>
1818

1919
using System.Collections.Generic;
20+
using System.Collections.ObjectModel;
2021
using System.Threading.Tasks;
2122

2223
namespace OpenQA.Selenium.DevTools
2324
{
2425
/// <summary>
25-
/// Interface representing a target for DevTools Protocol commands
26+
/// Class representing a target for DevTools Protocol commands
2627
/// </summary>
27-
public interface ITarget
28+
public abstract class Target
2829
{
2930
/// <summary>
3031
/// Asynchronously gets the targets available for this session.
@@ -34,7 +35,7 @@ public interface ITarget
3435
/// contains the list of <see cref="TargetInfo"/> objects describing the
3536
/// targets available for this session.
3637
/// </returns>
37-
Task<List<TargetInfo>> GetTargets();
38+
public abstract Task<ReadOnlyCollection<TargetInfo>> GetTargets();
3839

3940
/// <summary>
4041
/// Asynchronously attaches to a target.
@@ -44,12 +45,22 @@ public interface ITarget
4445
/// A task representing the asynchronous attach operation. The task result contains the
4546
/// session ID established for commands to the target attached to.
4647
/// </returns>
47-
Task<string> AttachToTarget(string TargetId);
48+
public abstract Task<string> AttachToTarget(string targetId);
49+
50+
/// <summary>
51+
/// Asynchronously detaches from a target.
52+
/// </summary>
53+
/// <param name="sessionId">The ID of the session of the target from which to detach.</param>
54+
/// <param name="targetId">The ID of the target from which to detach.</param>
55+
/// <returns>
56+
/// A task representing the asynchronous detach operation.
57+
/// </returns>
58+
public abstract Task DetachFromTarget(string sessionId = null, string targetId = null);
4859

4960
/// <summary>
5061
/// Asynchronously sets the DevTools Protocol connection to automatically attach to new targets.
5162
/// </summary>
5263
/// <returns>A task that represents the asynchronous operation.</returns>
53-
Task SetAutoAttach();
64+
public abstract Task SetAutoAttach();
5465
}
5566
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ public V84Domains(DevToolsSession session)
5050
/// <summary>
5151
/// Gets the object used for manipulating network information in the browser.
5252
/// </summary>
53-
public INetwork Network => new V84Network(domains.Network, domains.Fetch);
53+
public 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 IJavaScript JavaScript => new V84JavaScript(domains.Runtime, domains.Page);
58+
public 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 ITarget Target => new V84Target(domains.Target);
63+
public 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 ILog Log => new V84Log(domains.Log);
68+
public DevTools.Log Log => new V84Log(domains.Log);
6969
}
7070
}

0 commit comments

Comments
 (0)