Bug 1461508 [wpt PR 11000] - Find Chrome binary on more platforms and fail gracefully, a=testonly
authorRobert Ma <bob1211@gmail.com>
Sat, 19 May 2018 20:32:50 +0000
changeset 419082 1b0def1ce2fb31395e4baa1f2e81fc82cdf8f146
parent 419081 69acdec7fe3390b4ff0b1dddf95ee369fd7b43f8
child 419083 f8c7a3a58dbd51c01ef30b024638228aaec58694
push id34026
push userapavel@mozilla.com
push dateMon, 21 May 2018 09:47:33 +0000
treeherdermozilla-central@dc1868d255be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1461508, 11000, 10992
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1461508 [wpt PR 11000] - Find Chrome binary on more platforms and fail gracefully, a=testonly Automatic update from web-platform-testsFind Chrome binary on more platforms and fail gracefully (#11000) Also make similar changes to Opera. Fixes #10992. -- wpt-commits: d516217b8c819b0ecafe1eff8868387892855858 wpt-pr: 11000
testing/web-platform/tests/tools/wpt/browser.py
--- a/testing/web-platform/tests/tools/wpt/browser.py
+++ b/testing/web-platform/tests/tools/wpt/browser.py
@@ -1,14 +1,15 @@
 import logging
 import os
 import platform
 import re
 import shutil
 import stat
+import subprocess
 import sys
 import tempfile
 from abc import ABCMeta, abstractmethod
 from ConfigParser import RawConfigParser
 from datetime import datetime, timedelta
 from distutils.spawn import find_executable
 from io import BytesIO
 
@@ -201,17 +202,16 @@ class Firefox(Browser):
                 # but to do better we need the actual build revision, which we
                 # can get if we have an application.ini file
                 tag = "tip"
 
         return "%s/archive/%s.zip/testing/profiles/" % (repo, tag)
 
     def install_prefs(self, binary, dest=None):
         version, channel = self.get_version_and_channel(binary)
-
         if dest is None:
             dest = os.pwd
 
         dest = os.path.join(dest, "profiles", channel, version)
         have_cache = False
         if os.path.exists(dest):
             if channel != "nightly":
                 have_cache = True
@@ -288,19 +288,28 @@ class Firefox(Browser):
 
 class Chrome(Browser):
     """Chrome-specific interface.
 
     Includes webdriver installation, and wptrunner setup methods.
     """
 
     product = "chrome"
-    binary = "/usr/bin/google-chrome"
     requirements = "requirements_chrome.txt"
 
+    @property
+    def binary(self):
+        if uname[0] == "Linux":
+            return "/usr/bin/google-chrome"
+        if uname[0] == "Darwin":
+            return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
+        # TODO Windows?
+        logger.warn("Unable to find the browser binary.")
+        return None
+
     def install(self, dest=None):
         raise NotImplementedError
 
     def platform_string(self):
         platform = {
             "Linux": "linux",
             "Windows": "win",
             "Darwin": "mac"
@@ -334,19 +343,24 @@ class Chrome(Browser):
 
         path = find_executable("chromedriver", dest)
         st = os.stat(path)
         os.chmod(path, st.st_mode | stat.S_IEXEC)
         return path
 
     def version(self, binary=None):
         binary = binary or self.binary
-        version_string = call(binary, "--version").strip()
+        try:
+            version_string = call(binary, "--version").strip()
+        except subprocess.CalledProcessError:
+            logger.warn("Failed to call %s", binary)
+            return None
         m = re.match(r"Google Chrome (.*)", version_string)
         if not m:
+            logger.warn("Failed to extract version from: s%", version_string)
             return None
         return m.group(1)
 
 
 class ChromeAndroid(Browser):
     """Chrome-specific interface for Android.
 
     Includes webdriver installation.
@@ -374,19 +388,26 @@ class ChromeAndroid(Browser):
 
 class Opera(Browser):
     """Opera-specific interface.
 
     Includes webdriver installation, and wptrunner setup methods.
     """
 
     product = "opera"
-    binary = "/usr/bin/opera"
     requirements = "requirements_opera.txt"
 
+    @property
+    def binary(self):
+        if uname[0] == "Linux":
+            return "/usr/bin/opera"
+        # TODO Windows, Mac?
+        logger.warn("Unable to find the browser binary.")
+        return None
+
     def install(self, dest=None):
         raise NotImplementedError
 
     def platform_string(self):
         platform = {
             "Linux": "linux",
             "Windows": "win",
             "Darwin": "mac"
@@ -425,17 +446,21 @@ class Opera(Browser):
         path = find_executable("operadriver")
         st = os.stat(path)
         os.chmod(path, st.st_mode | stat.S_IEXEC)
         return path
 
     def version(self, binary):
         """Retrieve the release version of the installed browser."""
         binary = binary or self.binary
-        output = call(binary, "--version")
+        try:
+            output = call(binary, "--version")
+        except subprocess.CalledProcessError:
+            logger.warn("Failed to call %s", binary)
+            return None
         return re.search(r"[0-9\.]+( [a-z]+)?$", output.strip()).group(0)
 
 
 class Edge(Browser):
     """Edge-specific interface."""
 
     product = "edge"
     requirements = "requirements_edge.txt"