Skip to content

Commit f692ab2

Browse files
committed
FxCop/static analysis warning suppression. No functional changes
1 parent f2dddfa commit f692ab2

30 files changed

+363
-148
lines changed

dotnet/src/webdriver/Chrome/ChromeDriver.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options)
142142
/// <param name="options">The <see cref="ChromeOptions"/> to be used with the Chrome driver.</param>
143143
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
144144
public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
145-
: base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
145+
: base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
146146
{
147147
}
148148
#endregion
@@ -162,5 +162,15 @@ public override IFileDetector FileDetector
162162
get { return base.FileDetector; }
163163
set { }
164164
}
165+
166+
private static ICapabilities ConvertOptionsToCapabilities(ChromeOptions options)
167+
{
168+
if (options == null)
169+
{
170+
throw new ArgumentNullException("options", "options must not be null");
171+
}
172+
173+
return options.ToCapabilities();
174+
}
165175
}
166176
}

dotnet/src/webdriver/Edge/EdgeDriver.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,20 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options)
107107
/// <param name="options">The <see cref="EdgeOptions"/> to be used with the Edge driver.</param>
108108
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
109109
public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout)
110-
: base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
110+
: base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
111111
{
112112
}
113113
#endregion
114+
115+
private static ICapabilities ConvertOptionsToCapabilities(EdgeOptions options)
116+
{
117+
if (options == null)
118+
{
119+
throw new ArgumentNullException("options", "options must not be null");
120+
}
121+
122+
return options.ToCapabilities();
123+
}
114124
}
115125
}
116126

dotnet/src/webdriver/Edge/EdgeDriverService.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public sealed class EdgeDriverService : DriverService
3232
{
3333
private const string MicrosoftWebDriverServiceFileName = "MicrosoftWebDriver.exe";
3434
private static readonly Uri MicrosoftWebDriverDownloadUrl = new Uri("http://go.microsoft.com/fwlink/?LinkId=619687");
35-
private string logPath = string.Empty;
36-
private string urlPathPrefix = string.Empty;
37-
private string portServerAddress = string.Empty;
3835

3936

4037
/// <summary>
@@ -76,7 +73,7 @@ public static EdgeDriverService CreateDefaultService(string driverPath)
7673
/// <returns>A EdgeDriverService using a random port.</returns>
7774
public static EdgeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
7875
{
79-
return new EdgeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
76+
return CreateDefaultService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
8077
}
8178

8279
/// <summary>

dotnet/src/webdriver/Firefox/FirefoxBinary.cs

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace OpenQA.Selenium.Firefox
3535
/// </summary>
3636
/// <remarks>The <see cref="FirefoxBinary"/> class is responsible for instantiating the
3737
/// Firefox process, and the operating system environment in which it runs.</remarks>
38-
public class FirefoxBinary
38+
public class FirefoxBinary : IDisposable
3939
{
4040
#region Constants
4141
private const string NoFocusLibraryName = "x_ignore_nofocus.so";
@@ -46,6 +46,7 @@ public class FirefoxBinary
4646
private Executable executable;
4747
private Process process;
4848
private TimeSpan timeout = TimeSpan.FromSeconds(45);
49+
private bool isDisposed = false;
4950
#endregion
5051

5152
#region Constructors
@@ -140,28 +141,28 @@ public void StartProfile(FirefoxProfile profile, params string[] commandLineArgu
140141
commandLineArgs.Append(" ").Append(commandLineArg);
141142
}
142143

143-
Process builder = new Process();
144-
builder.StartInfo.FileName = this.BinaryExecutable.ExecutablePath;
145-
builder.StartInfo.Arguments = commandLineArgs.ToString();
146-
builder.StartInfo.UseShellExecute = false;
144+
this.process = new Process();
145+
this.process.StartInfo.FileName = this.BinaryExecutable.ExecutablePath;
146+
this.process.StartInfo.Arguments = commandLineArgs.ToString();
147+
this.process.StartInfo.UseShellExecute = false;
147148

148149
foreach (string environmentVar in this.extraEnv.Keys)
149150
{
150-
if (builder.StartInfo.EnvironmentVariables.ContainsKey(environmentVar))
151+
if (this.process.StartInfo.EnvironmentVariables.ContainsKey(environmentVar))
151152
{
152-
builder.StartInfo.EnvironmentVariables[environmentVar] = this.extraEnv[environmentVar];
153+
this.process.StartInfo.EnvironmentVariables[environmentVar] = this.extraEnv[environmentVar];
153154
}
154155
else
155156
{
156-
builder.StartInfo.EnvironmentVariables.Add(environmentVar, this.extraEnv[environmentVar]);
157+
this.process.StartInfo.EnvironmentVariables.Add(environmentVar, this.extraEnv[environmentVar]);
157158
}
158159
}
159160

160-
this.BinaryExecutable.SetLibraryPath(builder);
161+
this.BinaryExecutable.SetLibraryPath(this.process);
161162

162-
this.StartFirefoxProcess(builder);
163+
this.StartFirefoxProcess();
163164

164-
this.CopeWithTheStrangenessOfTheMac(builder);
165+
this.CopeWithTheStrangenessOfTheMac();
165166
}
166167

167168
/// <summary>
@@ -186,21 +187,6 @@ public void SetEnvironmentProperty(string propertyName, string value)
186187
}
187188
}
188189

189-
/// <summary>
190-
/// Creates a named profile for Firefox.
191-
/// </summary>
192-
/// <param name="profileName">The name of the profile to create.</param>
193-
[SecurityPermission(SecurityAction.Demand)]
194-
public void CreateProfile(string profileName)
195-
{
196-
Process builder = new Process();
197-
builder.StartInfo.FileName = this.executable.ExecutablePath;
198-
builder.StartInfo.Arguments = "--verbose -CreateProfile " + profileName;
199-
builder.StartInfo.EnvironmentVariables.Add("MOZ_NO_REMOTE", "1");
200-
201-
this.StartFirefoxProcess(builder);
202-
}
203-
204190
/// <summary>
205191
/// Waits for the process to complete execution.
206192
/// </summary>
@@ -211,30 +197,12 @@ public void WaitForProcessExit()
211197
}
212198

213199
/// <summary>
214-
/// Stops the execution of this <see cref="FirefoxBinary"/>, terminating the process if necessary.
200+
/// Releases all resources used by the <see cref="FirefoxBinary"/>.
215201
/// </summary>
216-
[SecurityPermission(SecurityAction.Demand)]
217-
public void Quit()
202+
public void Dispose()
218203
{
219-
// Suicide watch: First, a second to see if the process will die on
220-
// it's own (we will likely have asked the process to kill itself just
221-
// before calling this method).
222-
if (this.process != null)
223-
{
224-
if (!this.process.HasExited)
225-
{
226-
System.Threading.Thread.Sleep(1000);
227-
}
228-
229-
// Murder option: The process is still alive, so kill it.
230-
if (!this.process.HasExited)
231-
{
232-
this.process.Kill();
233-
}
234-
235-
this.process.Dispose();
236-
this.process = null;
237-
}
204+
this.Dispose(true);
205+
GC.SuppressFinalize(this);
238206
}
239207

240208
/// <summary>
@@ -249,17 +217,48 @@ public override string ToString()
249217
/// <summary>
250218
/// Starts the Firefox process.
251219
/// </summary>
252-
/// <param name="builder">A <see cref="Process"/> object used to start Firefox.</param>
253220
[SecurityPermission(SecurityAction.Demand)]
254-
protected void StartFirefoxProcess(Process builder)
221+
protected void StartFirefoxProcess()
222+
{
223+
this.process.Start();
224+
}
225+
226+
/// <summary>
227+
/// Releases the unmanaged resources used by the <see cref="FirefoxBinary"/> and optionally
228+
/// releases the managed resources.
229+
/// </summary>
230+
/// <param name="disposing"><see langword="true"/> to release managed and resources;
231+
/// <see langword="false"/> to only release unmanaged resources.</param>
232+
[SecurityPermission(SecurityAction.Demand)]
233+
protected virtual void Dispose(bool disposing)
255234
{
256-
if (builder == null)
235+
if (!this.isDisposed)
257236
{
258-
throw new ArgumentNullException("builder", "builder cannot be null");
259-
}
237+
if (disposing)
238+
{
239+
// Suicide watch: First, a second to see if the process will die on
240+
// it's own (we will likely have asked the process to kill itself just
241+
// before calling this method).
242+
if (this.process != null)
243+
{
244+
if (!this.process.HasExited)
245+
{
246+
System.Threading.Thread.Sleep(1000);
247+
}
260248

261-
this.process = builder;
262-
this.process.Start();
249+
// Murder option: The process is still alive, so kill it.
250+
if (!this.process.HasExited)
251+
{
252+
this.process.Kill();
253+
}
254+
255+
this.process.Dispose();
256+
this.process = null;
257+
}
258+
}
259+
260+
this.isDisposed = true;
261+
}
263262
}
264263

265264
private static void Sleep(int timeInMilliseconds)
@@ -343,7 +342,7 @@ private void ModifyLinkLibraryPath(FirefoxProfile profile)
343342
}
344343

345344
[SecurityPermission(SecurityAction.Demand)]
346-
private void CopeWithTheStrangenessOfTheMac(Process builder)
345+
private void CopeWithTheStrangenessOfTheMac()
347346
{
348347
if (Platform.CurrentPlatform.IsPlatformType(PlatformType.Mac))
349348
{
@@ -363,7 +362,7 @@ private void CopeWithTheStrangenessOfTheMac(Process builder)
363362
// TODO(simon): This is utterly bogus. We should do something far smarter
364363
System.Threading.Thread.Sleep(10000);
365364

366-
this.StartFirefoxProcess(builder);
365+
this.StartFirefoxProcess();
367366
}
368367
catch (ThreadStateException)
369368
{
@@ -382,7 +381,7 @@ private void CopeWithTheStrangenessOfTheMac(Process builder)
382381

383382
StringBuilder message = new StringBuilder("Unable to start firefox cleanly.\n");
384383
message.Append("Exit value: ").Append(this.process.ExitCode.ToString(CultureInfo.InvariantCulture)).Append("\n");
385-
message.Append("Ran from: ").Append(builder.StartInfo.FileName).Append("\n");
384+
message.Append("Ran from: ").Append(this.process.StartInfo.FileName).Append("\n");
386385
throw new WebDriverException(message.ToString());
387386
}
388387
catch (ThreadStateException)

dotnet/src/webdriver/Firefox/FirefoxDriver.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public FirefoxDriver(FirefoxDriverService service)
191191
/// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
192192
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
193193
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
194-
: base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
194+
: base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
195195
{
196196
}
197197
#endregion
@@ -357,6 +357,16 @@ private static ICapabilities RemoveUnneededCapabilities(ICapabilities capabiliti
357357
caps.CapabilitiesDictionary.Remove(FirefoxDriver.BinaryCapabilityName);
358358
return caps;
359359
}
360+
361+
private static ICapabilities ConvertOptionsToCapabilities(FirefoxOptions options)
362+
{
363+
if (options == null)
364+
{
365+
throw new ArgumentNullException("options", "options must not be null");
366+
}
367+
368+
return options.ToCapabilities();
369+
}
360370
#endregion
361371
}
362372
}

dotnet/src/webdriver/Firefox/FirefoxDriverCommandExecutor.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ namespace OpenQA.Selenium.Firefox
2828
/// <summary>
2929
/// Provides a way of executing Commands using the FirefoxDriver.
3030
/// </summary>
31-
public class FirefoxDriverCommandExecutor : ICommandExecutor
31+
public class FirefoxDriverCommandExecutor : ICommandExecutor, IDisposable
3232
{
3333
private FirefoxDriverServer server;
3434
private HttpCommandExecutor internalExecutor;
3535
private TimeSpan commandTimeout;
36+
private bool isDisposed;
3637

3738
/// <summary>
3839
/// Initializes a new instance of the <see cref="FirefoxDriverCommandExecutor"/> class.
@@ -84,11 +85,39 @@ public Response Execute(Command commandToExecute)
8485
{
8586
if (commandToExecute.Name == DriverCommand.Quit)
8687
{
87-
this.server.Dispose();
88+
this.Dispose();
8889
}
8990
}
9091

9192
return toReturn;
9293
}
94+
95+
/// <summary>
96+
/// Releases all resources used by the <see cref="FirefoxDriverCommandExecutor"/>.
97+
/// </summary>
98+
public void Dispose()
99+
{
100+
Dispose(true);
101+
GC.SuppressFinalize(this);
102+
}
103+
104+
/// <summary>
105+
/// Releases the unmanaged resources used by the <see cref="FirefoxDriverCommandExecutor"/> and
106+
/// optionally releases the managed resources.
107+
/// </summary>
108+
/// <param name="disposing"><see langword="true"/> to release managed and resources;
109+
/// <see langword="false"/> to only release unmanaged resources.</param>
110+
protected virtual void Dispose(bool disposing)
111+
{
112+
if (!this.isDisposed)
113+
{
114+
if (disposing)
115+
{
116+
this.server.Dispose();
117+
}
118+
119+
this.isDisposed = true;
120+
}
121+
}
93122
}
94123
}

dotnet/src/webdriver/Firefox/FirefoxDriverServer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ protected virtual void Dispose(bool disposing)
125125
{
126126
// This should only be called after the QUIT command has been sent,
127127
// so go ahead and clean up our process and profile.
128-
this.process.Quit();
128+
this.process.Dispose();
129129
this.profile.Clean();
130130
}
131-
132-
GC.SuppressFinalize(this);
133131
}
134132

135133
private static int DetermineNextFreePort(string host, int port)

0 commit comments

Comments
 (0)