Skip to content

Commit

Permalink
Merge pull request #19 from svatal/master
Browse files Browse the repository at this point in the history
Update tooling and protocols
  • Loading branch information
brewdente authored Oct 25, 2017
2 parents 3207391 + 700d409 commit c4bdc6d
Show file tree
Hide file tree
Showing 953 changed files with 10,164 additions and 6,660 deletions.
59 changes: 0 additions & 59 deletions source/ChromeDevTools/ChromeProcess.cs

This file was deleted.

39 changes: 28 additions & 11 deletions source/ChromeDevTools/ChromeProcessFactory.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

namespace MasterDevs.ChromeDevTools
{
public class ChromeProcessFactory : IChromeProcessFactory
{
public IChromeProcess Create(int port)
public IDirectoryCleaner DirectoryCleaner { get; set; }
public string ChromePath { get; }

public ChromeProcessFactory(IDirectoryCleaner directoryCleaner, string chromePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
{
DirectoryCleaner = directoryCleaner;
ChromePath = chromePath;
}

public IChromeProcess Create(int port, bool headless)
{
string path = Path.GetRandomFileName();
var directoryInfo = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), path));
var remoteDebuggingArg = "--remote-debugging-port=" + port;
var userDirectoryArg = "--user-data-dir=\"" + directoryInfo.FullName + "\"";
var chromeProcessArgs = remoteDebuggingArg + " " + userDirectoryArg + " --bwsi --no-first-run";
var processStartInfo = new ProcessStartInfo(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", chromeProcessArgs);
var chromeProcess = Process.Start(processStartInfo);
return new ChromeProcess
var remoteDebuggingArg = $"--remote-debugging-port={port}";
var userDirectoryArg = $"--user-data-dir=\"{directoryInfo.FullName}\"";
const string headlessArg = "--headless --disable-gpu";
var chromeProcessArgs = new List<string>
{
Process = chromeProcess,
UserDirectory = directoryInfo,
RemoteDebuggingUri = "http://localhost:" + port
remoteDebuggingArg,
userDirectoryArg,
"--bwsi",
"--no-first-run"
};
if (headless)
chromeProcessArgs.Add(headlessArg);
var processStartInfo = new ProcessStartInfo(ChromePath, string.Join(" ", chromeProcessArgs));
var chromeProcess = Process.Start(processStartInfo);

string remoteDebuggingUrl = "http://localhost:" + port;
return new LocalChromeProcess(new Uri(remoteDebuggingUrl), () => DirectoryCleaner.Delete(directoryInfo), chromeProcess);
}
}
}
17 changes: 15 additions & 2 deletions source/ChromeDevTools/ChromeSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,23 @@ public Task<ICommandResponse> SendAsync<T>(CancellationToken cancellationToken)
return SendCommand(command, cancellationToken);
}

public Task<ICommandResponse> SendAsync<T>(T parameter, CancellationToken cancellationToken)
public Task<CommandResponse<T>> SendAsync<T>(ICommand<T> parameter, CancellationToken cancellationToken)
{
var command = _commandFactory.Create(parameter);
return SendCommand(command, cancellationToken);
var task = SendCommand(command, cancellationToken);
return CastTaskResult<ICommandResponse, CommandResponse<T>>(task);
}

private Task<TDerived> CastTaskResult<TBase, TDerived>(Task<TBase> task) where TDerived: TBase
{
var tcs = new TaskCompletionSource<TDerived>();
task.ContinueWith(t => tcs.SetResult((TDerived)t.Result),
TaskContinuationOptions.OnlyOnRanToCompletion);
task.ContinueWith(t => tcs.SetException(t.Exception.InnerExceptions),
TaskContinuationOptions.OnlyOnFaulted);
task.ContinueWith(t => tcs.SetCanceled(),
TaskContinuationOptions.OnlyOnCanceled);
return tcs.Task;
}

public void Subscribe<T>(Action<T> handler) where T : class
Expand Down
4 changes: 2 additions & 2 deletions source/ChromeDevTools/ChromeSessionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace MasterDevs.ChromeDevTools
{
public static class ChromeSessionExtensions
{
public static Task<ICommandResponse> SendAsync<T>(this IChromeSession session, T parameter)
public static Task<CommandResponse<T>> SendAsync<T>(this IChromeSession session, ICommand<T> parameter)
{
return session.SendAsync<T>(parameter, CancellationToken.None);
return session.SendAsync(parameter, CancellationToken.None);
}

public static Task<ICommandResponse> SendAsync<T>(this IChromeSession session)
Expand Down
5 changes: 5 additions & 0 deletions source/ChromeDevTools/ChromeSessionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ namespace MasterDevs.ChromeDevTools
{
public class ChromeSessionFactory : IChromeSessionFactory
{
public IChromeSession Create(ChromeSessionInfo sessionInfo)
{
return Create(sessionInfo.WebSocketDebuggerUrl);
}

public IChromeSession Create(string endpointUrl)
{
// Sometimes binding to localhost might resolve wrong AddressFamily, force IPv4
Expand Down
14 changes: 14 additions & 0 deletions source/ChromeDevTools/ChromeSessionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MasterDevs.ChromeDevTools
{
public class ChromeSessionInfo
{
public string Description { get; set; }

public string DevtoolsFrontendUrl { get; set; }
public string Id { get; set; }
public string Title { get; set; }
public string Type { get; set; }
public string Url { get; set; }
public string WebSocketDebuggerUrl { get; set; }
}
}
10 changes: 3 additions & 7 deletions source/ChromeDevTools/IChromeProcess.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;

namespace MasterDevs.ChromeDevTools
{
public interface IChromeProcess : IDisposable
{
Task<string[]> GetSessions();
Task<ChromeSessionInfo[]> GetSessionInfo();

DirectoryInfo UserDirectory { get; }
Task<ChromeSessionInfo> StartNewSession();

Process Process { get; }

string RemoteDebuggingUri { get; }
Uri RemoteDebuggingUri { get; }
}
}
2 changes: 1 addition & 1 deletion source/ChromeDevTools/IChromeProcessFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public interface IChromeProcessFactory
{
IChromeProcess Create(int port);
IChromeProcess Create(int port, bool headless);
}
}
6 changes: 5 additions & 1 deletion source/ChromeDevTools/IChromeSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

namespace MasterDevs.ChromeDevTools
{
public interface ICommand<T>
{

}
public interface IChromeSession
{
Task<ICommandResponse> SendAsync<T>(T parameter, CancellationToken cancellationToken);
Task<CommandResponse<TResponse>> SendAsync<TResponse>(ICommand<TResponse> parameter, CancellationToken cancellationToken);

Task<ICommandResponse> SendAsync<T>(CancellationToken cancellationToken);

Expand Down
9 changes: 9 additions & 0 deletions source/ChromeDevTools/IDirectoryCleaner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.IO;

namespace MasterDevs.ChromeDevTools
{
public interface IDirectoryCleaner
{
void Delete(DirectoryInfo dir);
}
}
28 changes: 28 additions & 0 deletions source/ChromeDevTools/LocalChromeProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics;

namespace MasterDevs.ChromeDevTools
{
public class LocalChromeProcess : RemoteChromeProcess
{
public LocalChromeProcess(Uri remoteDebuggingUri, Action disposeUserDirectory, Process process)
: base(remoteDebuggingUri)
{
DisposeUserDirectory = disposeUserDirectory;
Process = process;
}

public Action DisposeUserDirectory { get; set; }
public Process Process { get; set; }

public override void Dispose()
{
base.Dispose();

Process.Kill();
Process.WaitForExit();
// Process.Close();
DisposeUserDirectory();
}
}
}
6 changes: 5 additions & 1 deletion source/ChromeDevTools/MasterDevs.ChromeDevTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ChromeProcessFactory.cs" />
<Compile Include="ChromeProcess.cs" />
<Compile Include="IDirectoryCleaner.cs" />
<Compile Include="LocalChromeProcess.cs" />
<Compile Include="ChromeSession.cs" />
<Compile Include="ChromeSessionExtensions.cs" />
<Compile Include="ChromeSessionFactory.cs" />
<Compile Include="ChromeSessionInfo.cs" />
<Compile Include="Command.cs" />
<Compile Include="CommandAttribute.cs" />
<Compile Include="Extensions\JTokenExtensions.cs" />
Expand All @@ -90,7 +92,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProtocolNameAttribute.cs" />
<Compile Include="Protocol\**\*.cs" />
<Compile Include="RemoteChromeProcess.cs" />
<Compile Include="Serialization\MessageContractResolver.cs" />
<Compile Include="StubbornDirectoryCleaner.cs" />
<Compile Include="SupportedByAttribute.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public enum AXGlobalStates
Hidden,
HiddenRoot,
Invalid,
Keyshortcuts,
Roledescription,
}
}
24 changes: 20 additions & 4 deletions source/ChromeDevTools/Protocol/Chrome/Accessibility/AXNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ public class AXNode
/// </summary>
public string NodeId { get; set; }
/// <summary>
/// Gets or sets Whether this node is ignored for accessibility
/// </summary>
public bool Ignored { get; set; }
/// <summary>
/// Gets or sets Collection of reasons why this node is hidden.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public AXProperty[] IgnoredReasons { get; set; }
/// <summary>
/// Gets or sets This <code>Node</code>'s role, whether explicit or implicit.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public AXValue Role { get; set; }
/// <summary>
/// Gets or sets The accessible name for this <code>Node</code>.
Expand All @@ -34,13 +44,19 @@ public class AXNode
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public AXValue Value { get; set; }
/// <summary>
/// Gets or sets Help.
/// Gets or sets All other properties
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public AXProperty[] Properties { get; set; }
/// <summary>
/// Gets or sets IDs for each of this node's child nodes.
/// </summary>
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public AXValue Help { get; set; }
public string[] ChildIds { get; set; }
/// <summary>
/// Gets or sets All other properties
/// Gets or sets The backend ID for the associated DOM node, if any.
/// </summary>
public AXProperty[] Properties { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public long? BackendDOMNodeId { get; set; }
}
}

This file was deleted.

Loading

0 comments on commit c4bdc6d

Please sign in to comment.