Skip to content

Commit 6c76202

Browse files
committed
DevTools - Strongly typed enums
1 parent 61eea4a commit 6c76202

30 files changed

+133
-54
lines changed

CefSharp.OffScreen.Example/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static async void MainAsync(string cachePath, double zoomLevel)
8080
using (var devToolsClient = browser.GetDevToolsClient())
8181
{
8282
var response = await devToolsClient.Browser.GetVersionAsync();
83-
var jsVersion = response.JsVersion;
83+
var jsVersion = response.Revision;
8484
//var success = await devToolsClient.Network.ClearBrowserCacheAsync();
8585
}
8686

CefSharp.Test/CefSharp.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
</ItemGroup>
126126
<ItemGroup>
127127
<Compile Include="BindingRedirectAssemblyResolver.cs" />
128+
<Compile Include="DevTools\DevToolsClientFacts.cs" />
128129
<Compile Include="Framework\BinderFacts.cs" />
129130
<Compile Include="Framework\AsyncExtensionFacts.cs" />
130131
<Compile Include="Framework\ConcurrentMethodRunnerQueueFacts.cs" />
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright © 2017 The CefSharp Authors. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4+
5+
using System.Threading.Tasks;
6+
using CefSharp.DevTools.Browser;
7+
using CefSharp.OffScreen;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace CefSharp.Test.OffScreen
12+
{
13+
//NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
14+
[Collection(CefSharpFixtureCollection.Key)]
15+
public class DevToolsClientFacts
16+
{
17+
private readonly ITestOutputHelper output;
18+
private readonly CefSharpFixture fixture;
19+
20+
public DevToolsClientFacts(ITestOutputHelper output, CefSharpFixture fixture)
21+
{
22+
this.fixture = fixture;
23+
this.output = output;
24+
}
25+
26+
[Fact]
27+
public void CanConvertDevToolsObjectToDictionary()
28+
{
29+
var bounds = new Bounds
30+
{
31+
Height = 1,
32+
Width = 1,
33+
Left = 1,
34+
Top = 1,
35+
WindowState = WindowState.Fullscreen.ToString()
36+
};
37+
38+
var dict = bounds.ToDictionary();
39+
40+
Assert.Equal(bounds.Height, (int)dict["height"]);
41+
Assert.Equal(bounds.Width, (int)dict["width"]);
42+
Assert.Equal(bounds.Top, (int)dict["top"]);
43+
Assert.Equal(bounds.Left, (int)dict["left"]);
44+
Assert.Equal(bounds.WindowState, (string)dict["windowState"]);
45+
}
46+
47+
48+
[Fact]
49+
public async Task CanGetDevToolsProtocolVersion()
50+
{
51+
using (var browser = new ChromiumWebBrowser("www.google.com"))
52+
{
53+
await browser.LoadPageAsync();
54+
55+
using (var devToolsClient = browser.GetDevToolsClient())
56+
{
57+
var response = await devToolsClient.Browser.GetVersionAsync();
58+
var jsVersion = response.JsVersion;
59+
var revision = response.Revision;
60+
61+
Assert.NotNull(jsVersion);
62+
Assert.NotNull(revision);
63+
64+
output.WriteLine("DevTools Revision {0}", revision);
65+
}
66+
}
67+
}
68+
}
69+
}

CefSharp/DevTools/Browser/Bounds.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public int? Height
5252
/// The window state. Default to normal.
5353
/// </summary>
5454
[System.Runtime.Serialization.DataMemberAttribute(Name = ("windowState"), IsRequired = (false))]
55-
public string WindowState
55+
public WindowState WindowState
5656
{
5757
get;
5858
set;

CefSharp/DevTools/DOM/Node.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public string Value
190190
/// Pseudo element type for this node.
191191
/// </summary>
192192
[System.Runtime.Serialization.DataMemberAttribute(Name = ("pseudoType"), IsRequired = (false))]
193-
public string PseudoType
193+
public PseudoType PseudoType
194194
{
195195
get;
196196
set;
@@ -200,7 +200,7 @@ public string PseudoType
200200
/// Shadow root type.
201201
/// </summary>
202202
[System.Runtime.Serialization.DataMemberAttribute(Name = ("shadowRootType"), IsRequired = (false))]
203-
public string ShadowRootType
203+
public ShadowRootType ShadowRootType
204204
{
205205
get;
206206
set;

CefSharp/DevTools/DOMDebugger/DOMDebugger.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public async System.Threading.Tasks.Task<GetEventListenersResponse> GetEventList
3939
/// <summary>
4040
/// Removes DOM breakpoint that was set using `setDOMBreakpoint`.
4141
/// </summary>
42-
public async System.Threading.Tasks.Task<DevToolsMethodResult> RemoveDOMBreakpointAsync(int nodeId, string type)
42+
public async System.Threading.Tasks.Task<DevToolsMethodResult> RemoveDOMBreakpointAsync(int nodeId, DOMBreakpointType type)
4343
{
4444
var dict = new System.Collections.Generic.Dictionary<string, object>();
4545
dict.Add("nodeId", nodeId);
46-
dict.Add("type", type);
46+
dict.Add("type", this.EnumToString(type));
4747
var result = await _client.ExecuteDevToolsMethodAsync("DOMDebugger.removeDOMBreakpoint", dict);
4848
return result;
4949
}
@@ -78,11 +78,11 @@ public async System.Threading.Tasks.Task<DevToolsMethodResult> RemoveXHRBreakpoi
7878
/// <summary>
7979
/// Sets breakpoint on particular operation with DOM.
8080
/// </summary>
81-
public async System.Threading.Tasks.Task<DevToolsMethodResult> SetDOMBreakpointAsync(int nodeId, string type)
81+
public async System.Threading.Tasks.Task<DevToolsMethodResult> SetDOMBreakpointAsync(int nodeId, DOMBreakpointType type)
8282
{
8383
var dict = new System.Collections.Generic.Dictionary<string, object>();
8484
dict.Add("nodeId", nodeId);
85-
dict.Add("type", type);
85+
dict.Add("type", this.EnumToString(type));
8686
var result = await _client.ExecuteDevToolsMethodAsync("DOMDebugger.setDOMBreakpoint", dict);
8787
return result;
8888
}

CefSharp/DevTools/DevToolsDomainBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

55

6+
using System;
7+
using System.Runtime.Serialization;
8+
69
namespace CefSharp.DevTools
710
{
811
public abstract class DevToolsDomainBase
912
{
13+
protected string EnumToString(Enum val)
14+
{
15+
var memInfo = val.GetType().GetMember(val.ToString());
16+
var dataMemberAttribute = (EnumMemberAttribute)Attribute.GetCustomAttribute(memInfo[0], typeof(EnumMemberAttribute), false);
1017

18+
return dataMemberAttribute.Value;
19+
}
1120
}
1221
}

CefSharp/DevTools/Input/Input.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async System.Threading.Tasks.Task<DevToolsMethodResult> DispatchKeyEventA
100100
/// <summary>
101101
/// Dispatches a mouse event to the page.
102102
/// </summary>
103-
public async System.Threading.Tasks.Task<DevToolsMethodResult> DispatchMouseEventAsync(string type, long x, long y, int? modifiers = null, long? timestamp = null, string button = null, int? buttons = null, int? clickCount = null, long? deltaX = null, long? deltaY = null, string pointerType = null)
103+
public async System.Threading.Tasks.Task<DevToolsMethodResult> DispatchMouseEventAsync(string type, long x, long y, int? modifiers = null, long? timestamp = null, MouseButton? button = null, int? buttons = null, int? clickCount = null, long? deltaX = null, long? deltaY = null, string pointerType = null)
104104
{
105105
var dict = new System.Collections.Generic.Dictionary<string, object>();
106106
dict.Add("type", type);
@@ -116,9 +116,9 @@ public async System.Threading.Tasks.Task<DevToolsMethodResult> DispatchMouseEven
116116
dict.Add("timestamp", timestamp.Value);
117117
}
118118

119-
if (!(string.IsNullOrEmpty(button)))
119+
if (button.HasValue)
120120
{
121-
dict.Add("button", button);
121+
dict.Add("button", this.EnumToString(button));
122122
}
123123

124124
if (buttons.HasValue)

CefSharp/DevTools/Network/BlockedCookieWithReason.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class BlockedCookieWithReason : CefSharp.DevTools.DevToolsDomainEntityBas
1212
/// The reason(s) the cookie was blocked.
1313
/// </summary>
1414
[System.Runtime.Serialization.DataMemberAttribute(Name = ("blockedReasons"), IsRequired = (true))]
15-
public string BlockedReasons
15+
public CookieBlockedReason BlockedReasons
1616
{
1717
get;
1818
set;

CefSharp/DevTools/Network/BlockedSetCookieWithReason.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class BlockedSetCookieWithReason : CefSharp.DevTools.DevToolsDomainEntity
1212
/// The reason(s) this cookie was blocked.
1313
/// </summary>
1414
[System.Runtime.Serialization.DataMemberAttribute(Name = ("blockedReasons"), IsRequired = (true))]
15-
public string BlockedReasons
15+
public SetCookieBlockedReason BlockedReasons
1616
{
1717
get;
1818
set;

0 commit comments

Comments
 (0)