Skip to content

Commit

Permalink
DavidBurns allowing Python to load the libnofocus library so that we …
Browse files Browse the repository at this point in the history
…can have have native events working correctly and not killing Firefox. This fixes issue 2633

r14778
  • Loading branch information
AutomatedTester committed Nov 17, 2011
1 parent 5c83c7e commit d353ba2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ recursive-include py/selenium/webdriver/common *.py
recursive-include py/selenium/common *.py
recursive-include py/selenium/webdriver/chrome *.py
recursive-include py/selenium/webdriver/firefox *.py *.xpi
recursive-include py/selenium/webdriver/firefox/x86 *.so
recursive-include py/selenium/webdriver/firefox/amd64 *.so
recursive-include py/selenium/webdriver/ie *.py
recursive-include py/selenium/webdriver/ie/win32 *.dll
recursive-include py/selenium/webdriver/ie/x64 *.dll
Expand Down
24 changes: 24 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,25 @@ task :test_firefox_py => [:webdriver_py, :firefox, "//javascript/firefox-driver:
if python? then
xpi_zip_build = 'build/javascript/firefox-driver/webdriver.xpi'
firefox_py_home = "py/selenium/webdriver/firefox/"
x86 = firefox_py_home + "x86/"
amd64 = firefox_py_home + "amd64/"
py_test_path = 'build/python/bin/py.test'
py_setup = "build/python/bin/python " + 'setup.py build'
if (windows?) then
xpi_zip_build = xpi_zip_build.gsub(/\//, "\\")
firefox_py_home = firefox_py_home .gsub(/\//, "\\")
py_test_path = 'build\\python\\Scripts\\py.test.exe'
py_setup = 'build\\python\\Scripts\\python ' + 'setup.py build'
x86 = x86.gsub(/\//,"\\")
amd64 = amd64.gsub(/\//,"\\")
end

mkdir_p x86 unless File.exists?(x86)
mkdir_p amd64 unless File.exists?(amd64)

cp "cpp/prebuilt/i386/libnoblur.so", x86+"x_ignore_nofocus.so", :verbose => true
cp "cpp/prebuilt/amd64/libnoblur64.so", amd64+"x_ignore_nofocus.so", :verbose => true

cp xpi_zip_build , firefox_py_home, :verbose => true

sh py_setup , :verbose => true
Expand All @@ -462,10 +472,14 @@ task :test_firefox_py => [:webdriver_py, :firefox, "//javascript/firefox-driver:
else
py_test = 'py.test'
end


test_dir = Dir.glob('build/lib**/selenium/test/selenium/webdriver/firefox').first
sh py_test, test_dir, :verbose => true
webdriver_zip = firefox_py_home + 'webdriver.xpi'
rm webdriver_zip , :verbose => true
rm_rf x86 , :verbose => true
rm_rf amd64 , :verbose => true
end
end

Expand Down Expand Up @@ -497,20 +511,30 @@ task :py_prep_for_install_release => ["//javascript/firefox-driver:webdriver", :

firefox_py_home = "py/selenium/webdriver/firefox/"
xpi_zip_build = 'build/javascript/firefox-driver/webdriver.xpi'
x86 = firefox_py_home + "x86/"
amd64 = firefox_py_home + "amd64/"

ie_driver_32 = 'cpp/prebuilt/Win32/Release/IEDriver.dll'
ie_driver_64 = 'cpp/prebuilt/x64/Release/IEDriver.dll'
ie_py_home = "py/selenium/webdriver/ie/"
if (windows?) then
xpi_zip_build = xpi_zip_build.gsub(/\//, "\\")
firefox_py_home = firefox_py_home .gsub(/\//, "\\")
x86 = x86.gsub(/\//,"\\")
amd64 = amd64.gsub(/\//,"\\")
ie_driver_32 = ie_driver_32.gsub(/\//, "\\")
ie_driver_64 = ie_driver_64.gsub(/\//, "\\")
ie_py_home = ie_py_home.gsub(/\//, "\\")
end

mkdir_p ie_py_home + "win32" unless File.exists?(ie_py_home + "win32")
mkdir_p ie_py_home + "x64" unless File.exists?(ie_py_home + "x64")
mkdir_p x86 unless File.exists?(x86)
mkdir_p amd64 unless File.exists?(amd64)

cp "cpp/prebuilt/i386/libnoblur.so", x86+"x_ignore_nofocus.so", :verbose => true
cp "cpp/prebuilt/amd64/libnoblur64.so", amd64+"x_ignore_nofocus.so", :verbose => true

cp xpi_zip_build , firefox_py_home, :verbose => true
cp ie_driver_32, ie_py_home + "win32", :verbose => true
cp ie_driver_64, ie_py_home + "x64", :verbose => true
Expand Down
34 changes: 34 additions & 0 deletions py/selenium/webdriver/firefox/firefox_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def _start_from_profile_path(self, path):
os.environ["MOZ_CRASHREPORTER_DISABLE"] = "1"
os.environ["MOZ_NO_REMOTE"] = "1"
os.environ["NO_EM_RESTART"] = "1"

if platform.system().lower() == 'linux':
self._modify_link_library_path()

Popen([self._start_cmd, "-silent"], stdout=PIPE, stderr=PIPE).wait()
self.process = Popen([self._start_cmd, "-foreground"], stdout=PIPE, stderr=PIPE)

Expand Down Expand Up @@ -110,6 +114,36 @@ def _default_windows_location(self):
program_files = os.getenv("PROGRAMFILES", r"\Program Files")
return os.path.join(program_files, "Mozilla Firefox\\firefox.exe")

def _modify_link_library_path(self):
existing_ld_lib_path = None
try:
existing_ld_lib_path = os.environ['LD_LIBRARY_PATH']
except:
pass

new_ld_lib_path = self._extract_and_check(self.profile, self.NO_FOCUS_LIBRARY_NAME,
"x86", "amd64")

if existing_ld_lib_path:
new_ld_lib_path += existing_ld_lib_path

os.environ["LD_LIBRARY_PATH"] = new_ld_lib_path
os.environ['LD_PRELOAD'] = self.NO_FOCUS_LIBRARY_NAME

def _extract_and_check(self, profile, no_focus_so_name, x86, amd64):

paths = [x86, amd64]
built_path = ""
for path in paths:
library_path = os.path.join(profile.path, path)
os.makedirs(library_path)
import shutil
shutil.copy(os.path.join(os.path.dirname(__file__), path, self.NO_FOCUS_LIBRARY_NAME),
library_path)
built_path += library_path + ":"

return built_path

def which(self, fname):
"""Returns the fully qualified path by searching Path of the given name"""
for pe in os.environ['PATH'].split(os.pathsep):
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def setup_python3():
'selenium.webdriver.firefox': ['*.xpi'],
},
data_files=[('selenium/webdriver/ie/win32',['py/selenium/webdriver/ie/win32/IEDriver.dll']),
('selenium/webdriver/ie/x64',['py/selenium/webdriver/ie/x64/IEDriver.dll'])],
('selenium/webdriver/ie/x64',['py/selenium/webdriver/ie/x64/IEDriver.dll']),
('selenium/webdriver/firefox/x86', ['py/selenium/webdriver/firefox/x86/x_ignore_nofocus.so']),
('selenium/webdriver/firefox/amd64', ['py/selenium/webdriver/firefox/amd64/x_ignore_nofocus.so'])],
include_package_data=True,
install_requires=['rdflib==3.1.0'],
zip_safe=False,
Expand Down

0 comments on commit d353ba2

Please sign in to comment.