Skip to content
Permalink
Browse files

Fixed firefox binary path

Created find_binary_path to return binary path in _venv, earlier find_binary
only returned firefox installed to path.
Changed nightly uninstallation conditional.
Moved nightly to _venv/browsers for easier search when we use
mozinstall.get_binary()
Removed xfail for firefox run/installtion from test_wpt as it doesn't
fail anymore.
  • Loading branch information...
Cactusmachete
Cactusmachete committed Mar 7, 2018
1 parent 7743b48 commit 12461b2b0f5ce460cea15e04f34560444d458c94
Showing with 70 additions and 43 deletions.
  1. +60 −36 tools/wpt/browser.py
  2. +1 −1 tools/wpt/run.py
  3. +9 −6 tools/wpt/tests/test_wpt.py
@@ -65,29 +65,10 @@ class Firefox(Browser):
"""

product = "firefox"
binary = "firefox/firefox"
platform_ini = "firefox/platform.ini"
binary = "browsers/firefox/firefox"
platform_ini = "browsers/firefox/platform.ini"
requirements = "requirements_firefox.txt"

def platform_string(self):
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "mac"
}.get(uname[0])

if platform is None:
raise ValueError("Unable to construct a valid Firefox package name for current platform")

if platform == "linux":
bits = "-%s" % uname[4]
elif platform == "win":
bits = "64" if uname[4] == "x86_64" else "32"
else:
bits = ""

return "%s%s" % (platform, bits)

def platform_string_geckodriver(self):
platform = {
"Linux": "linux",
@@ -111,38 +92,69 @@ def install(self, dest=None):
from mozdownload import FactoryScraper
import mozinstall

platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "mac"
}.get(uname[0])

if platform is None:
raise ValueError("Unable to construct a valid Firefox package name for current platform")

if dest is None:
dest = os.getcwd()
# os.getcwd() doesn't include the venv path
dest = os.path.join(os.getcwd(), "_venv")

dest = os.path.join(dest, "browsers")

filename = FactoryScraper('daily', branch='mozilla-central', destination=dest).download()
filename = FactoryScraper("daily", branch="mozilla-central", destination=dest).download()

try:
mozinstall.install(filename, dest)
except mozinstall.mozinstall.InstallError as e:
if uname[0] == "Darwin":
# mozinstall will fail here if nightly is already installed in the venv
# This only occurs on macOS because shutil.copy_tree() is called in
# mozinstall._install_dmg and will fail if the file already exists.
# copytree isn't used while installing on Windows/linux, so the same error
# won't be thrown if we try to rewrite there.
mozinstall.uninstall(dest+'/Firefox Nightly.app')
if platform == "mac" and os.path.exists(os.path.join(dest, "Firefox Nightly.app")):
# mozinstall will fail if nightly is already installed in the venv because
# mac installation uses shutil.copy_tree
mozinstall.uninstall(os.path.join(dest, "Firefox Nightly.app"))
mozinstall.install(filename, dest)
else:
raise

os.remove(filename)
return find_executable("firefox", os.path.join(dest, "firefox"))
return self.find_binary_path(dest)

def find_binary_path(self, path=None):
"""Looks for the firefox binary in the virtual environment"""

def find_binary(self):
platform = {
"Linux": "linux",
"Windows": "win",
"Darwin": "macos"
"Darwin": "mac"
}.get(uname[0])

path = find_executable("firefox")
if path is None:
#os.getcwd() doesn't include the venv path
path = os.path.join(os.getcwd(), "_venv", "browsers")

binary = None

if not path and platform == "macos":
if platform == "linux":
binary = find_executable("firefox", os.path.join(path, "firefox"))
elif platform == "win":
import mozinstall
binary = mozinstall.get_binary(path, "firefox")
elif platform == "mac":
binary = find_executable("firefox", os.path.join(path, "Firefox Nightly.app", "Contents", "MacOS"))

return binary

def find_binary(self, venv_path=None):
if venv_path is None:
venv_path = os.path.join(os.getcwd(), venv_path)

binary = self.find_binary_path(os.path.join(venv_path, "browsers"))

if not binary and uname[0] == "Darwin":
macpaths = ["/Applications/FirefoxNightly.app/Contents/MacOS",
os.path.expanduser("~/Applications/FirefoxNightly.app/Contents/MacOS"),
"/Applications/Firefox Developer Edition.app/Contents/MacOS",
@@ -151,7 +163,10 @@ def find_binary(self):
os.path.expanduser("~/Applications/Firefox.app/Contents/MacOS")]
return find_executable("firefox", os.pathsep.join(macpaths))

return path
if binary is None:
return find_executable("firefox")

return binary

def find_certutil(self):
path = find_executable("certutil")
@@ -444,6 +459,7 @@ class Servo(Browser):
product = "servo"
requirements = "requirements_servo.txt"

<<<<<<< HEAD
def platform_components(self):
platform = {
"Linux": "linux",
@@ -475,6 +491,10 @@ def install(self, dest=None):
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IEXEC)
return path
=======
def install(self, dest=None):
raise NotImplementedError
>>>>>>> 67b22bb... Fixed duplicated code

def find_binary(self):
return find_executable("servo")
@@ -486,9 +506,13 @@ def install_webdriver(self, dest=None):
raise NotImplementedError

def version(self, root):
<<<<<<< HEAD
"""Retrieve the release version of the installed browser."""
output = call(self.binary, "--version")
return re.search(r"[0-9\.]+( [a-z]+)?$", output.strip()).group(0)
=======
return None
>>>>>>> 67b22bb... Fixed duplicated code


class Sauce(Browser):
@@ -163,7 +163,7 @@ class Firefox(BrowserSetup):

def setup_kwargs(self, kwargs):
if kwargs["binary"] is None:
binary = self.browser.find_binary()
binary = self.browser.find_binary(self.venv.path)
if binary is None:
raise WptrunError("""Firefox binary not found on $PATH.
@@ -65,8 +65,6 @@ def test_help():

@pytest.mark.slow
@pytest.mark.remote_network
@pytest.mark.xfail(sys.platform == "darwin",
reason="https://github.com/w3c/web-platform-tests/issues/9090")
@pytest.mark.xfail(sys.platform == "win32",
reason="Tests currently don't work on Windows for path reasons")
def test_run_firefox(manifest_dir):
@@ -77,7 +75,10 @@ def test_run_firefox(manifest_dir):

os.environ["MOZ_HEADLESS"] = "1"
try:
fx_path = os.path.join(wpt.localpaths.repo_root, "_venv", "firefox")
if sys.platform == "darwin":
fx_path = os.path.join(wpt.localpaths.repo_root, "_venv", "browsers", "Firefox Nightly.app")
else:
fx_path = os.path.join(wpt.localpaths.repo_root, "_venv", "browsers", "firefox")
if os.path.exists(fx_path):
shutil.rmtree(fx_path)
with pytest.raises(SystemExit) as excinfo:
@@ -122,12 +123,14 @@ def test_install_chromedriver():

@pytest.mark.slow
@pytest.mark.remote_network
@pytest.mark.xfail(sys.platform == "darwin",
reason="https://github.com/w3c/web-platform-tests/issues/9090")
@pytest.mark.xfail(sys.platform == "win32",
reason="Tests currently don't work on Windows for path reasons")
def test_install_firefox():
fx_path = os.path.join(wpt.localpaths.repo_root, "_venv", "firefox")

if sys.platform == "darwin":
fx_path = os.path.join(wpt.localpaths.repo_root, "_venv", "browsers", "Firefox Nightly.app")
else:
fx_path = os.path.join(wpt.localpaths.repo_root, "_venv", "browsers", "firefox")
if os.path.exists(fx_path):
shutil.rmtree(fx_path)
with pytest.raises(SystemExit) as excinfo:

0 comments on commit 12461b2

Please sign in to comment.
You can’t perform that action at this time.