Skip to content

Commit 8104d28

Browse files
committed
Fixing location of Firefox no-focus library for .NET on non-Windows OS
Also removes a long-deprecated property on the FirefoxBinary class. Fixes issue #1010.
1 parent 005c5c9 commit 8104d28

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

dotnet/src/webdriver/Firefox/FirefoxBinary.cs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Text;
2727
using System.Threading;
2828
using OpenQA.Selenium.Firefox.Internal;
29+
using OpenQA.Selenium.Internal;
2930

3031
namespace OpenQA.Selenium.Firefox
3132
{
@@ -67,16 +68,6 @@ public FirefoxBinary(string pathToFirefoxBinary)
6768
#endregion
6869

6970
#region Public properties
70-
/// <summary>
71-
/// Gets or sets the timeout (in milliseconds) to wait for command execution.
72-
/// </summary>
73-
[Obsolete("Timeouts should be expressed as a TimeSpan. Use the Timeout property instead")]
74-
public long TimeoutInMilliseconds
75-
{
76-
get { return Convert.ToInt64(this.Timeout.TotalMilliseconds); }
77-
set { this.Timeout = TimeSpan.FromMilliseconds(value); }
78-
}
79-
8071
/// <summary>
8172
/// Gets or sets the timeout to wait for Firefox to be available for command execution.
8273
/// </summary>
@@ -299,28 +290,23 @@ private static string ExtractAndCheck(FirefoxProfile profile, string noFocusSoNa
299290
{
300291
string outSoPath = Path.Combine(profile.ProfileDirectory, path);
301292
string file = Path.Combine(outSoPath, noFocusSoName);
302-
303293
string resourceName = string.Format(CultureInfo.InvariantCulture, "WebDriver.FirefoxNoFocus.{0}.dll", path);
304-
Assembly executingAssembly = Assembly.GetExecutingAssembly();
305-
306-
List<string> resourceNames = new List<string>(executingAssembly.GetManifestResourceNames());
307-
if (resourceNames.Contains(resourceName))
294+
if (ResourceUtilities.IsValidResourceName(resourceName))
308295
{
309-
Stream libraryStream = executingAssembly.GetManifestResourceStream(resourceName);
310-
311-
Directory.CreateDirectory(outSoPath);
312-
using (FileStream outputStream = File.Create(file))
296+
using (Stream libraryStream = ResourceUtilities.GetResourceStream(noFocusSoName, resourceName))
313297
{
314-
byte[] buffer = new byte[1000];
315-
int bytesRead = libraryStream.Read(buffer, 0, buffer.Length);
316-
while (bytesRead > 0)
298+
Directory.CreateDirectory(outSoPath);
299+
using (FileStream outputStream = File.Create(file))
317300
{
318-
outputStream.Write(buffer, 0, bytesRead);
319-
bytesRead = libraryStream.Read(buffer, 0, buffer.Length);
301+
byte[] buffer = new byte[1000];
302+
int bytesRead = libraryStream.Read(buffer, 0, buffer.Length);
303+
while (bytesRead > 0)
304+
{
305+
outputStream.Write(buffer, 0, bytesRead);
306+
bytesRead = libraryStream.Read(buffer, 0, buffer.Length);
307+
}
320308
}
321309
}
322-
323-
libraryStream.Close();
324310
}
325311

326312
if (!File.Exists(file))
@@ -343,7 +329,7 @@ private void ModifyLinkLibraryPath(FirefoxProfile profile)
343329
string existingLdLibPath = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
344330

345331
// The returned new ld lib path is terminated with ':'
346-
string newLdLibPath = ExtractAndCheck(profile, NoFocusLibraryName, "x86", "amd64");
332+
string newLdLibPath = ExtractAndCheck(profile, NoFocusLibraryName, "x86", "x64");
347333
if (!string.IsNullOrEmpty(existingLdLibPath))
348334
{
349335
newLdLibPath += existingLdLibPath;

dotnet/src/webdriver/Internal/ResourceUtilities.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,17 @@ public static Stream GetResourceStream(string fileName, string resourceId)
7979

8080
return resourceStream;
8181
}
82+
83+
/// <summary>
84+
/// Returns a value indicating whether a resource exists with the specified ID.
85+
/// </summary>
86+
/// <param name="resourceId">ID of the embedded resource to check for.</param>
87+
/// <returns><see langword="true"/> if the resource exists in the calling assembly; otherwise <see langword="false"/>.</returns>
88+
public static bool IsValidResourceName(string resourceId)
89+
{
90+
Assembly executingAssembly = Assembly.GetCallingAssembly();
91+
List<string> resourceNames = new List<string>(executingAssembly.GetManifestResourceNames());
92+
return resourceNames.Contains(resourceId);
93+
}
8294
}
8395
}

0 commit comments

Comments
 (0)