diff --git a/testing/web-platform/tests/tools/wpt/browser.py b/testing/web-platform/tests/tools/wpt/browser.py index 01b7b2ad2267a..271e6f898a760 100644 --- a/testing/web-platform/tests/tools/wpt/browser.py +++ b/testing/web-platform/tests/tools/wpt/browser.py @@ -13,6 +13,8 @@ from io import BytesIO from utils import call, get, untar, unzip +from mozdownload import FactoryScraper +import mozinstall logger = logging.getLogger(__name__) @@ -105,36 +107,29 @@ def platform_string_geckodriver(self): return "%s%s" % (platform, bits) - def latest_nightly_listing(self): - resp = get("https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/") - resp.raise_for_status() - return resp.text - - def get_nightly_link(self, index, platform): - pattern = re.compile("]*>(firefox-(\d+)\.\d(?:\w\d)?.en-US.%s\.tar\.bz2)" % platform) - max_version = None - for match in pattern.finditer(index): - try: - version = int(match.group(2)) - except ValueError: - continue - if max_version is None or version > max_version[0]: - max_version = (version, match.group(1)) - if not max_version: - raise ValueError("Failed to find version to download") - return ("https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/%s" % - max_version[1]) - def install(self, dest=None): """Install Firefox.""" + if dest is None: dest = os.getcwd() - nightly_link = self.get_nightly_link(self.latest_nightly_listing(), - self.platform_string()) - resp = get(nightly_link) - resp.raise_for_status() - untar(resp.raw, dest=dest) + 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') + mozinstall.install(filename, dest) + else: + raise + + os.remove(filename) return find_executable("firefox", os.path.join(dest, "firefox")) def find_binary(self): diff --git a/testing/web-platform/tests/tools/wpt/commands.json b/testing/web-platform/tests/tools/wpt/commands.json index 38cdd3a368736..89669cafe0885 100644 --- a/testing/web-platform/tests/tools/wpt/commands.json +++ b/testing/web-platform/tests/tools/wpt/commands.json @@ -1,6 +1,6 @@ { "run": {"path": "run.py", "script": "run", "parser": "create_parser", "help": "Run tests in a browser", - "virtualenv": true, "install": ["requests"], "requirements": ["../wptrunner/requirements.txt"]}, + "virtualenv": true, "install": ["requests", "mozinstall", "mozdownload"], "requirements": ["../wptrunner/requirements.txt"]}, "update-expectations": {"path": "update.py", "script": "update_expectations", "parser": "create_parser_update", "help": "Update expectations files from raw logs.", "virtualenv": true, "install": ["requests"], diff --git a/testing/web-platform/tests/tools/wpt/tests/test_browser.py b/testing/web-platform/tests/tools/wpt/tests/test_browser.py deleted file mode 100644 index 7a51a01fd7e6a..0000000000000 --- a/testing/web-platform/tests/tools/wpt/tests/test_browser.py +++ /dev/null @@ -1,13 +0,0 @@ -import os - -from tools.wpt import browser - -here = os.path.dirname(__file__) - - -def test_firefox_nightly_link(): - expected = ("https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/" - "firefox-60.0a1.en-US.linux-x86_64.tar.bz2") - with open(os.path.join(here, "latest_mozilla_central.txt")) as index: - fx = browser.Firefox() - assert fx.get_nightly_link(index.read(), "linux-x86_64") == expected diff --git a/testing/web-platform/tests/tools/wptrunner/requirements_firefox.txt b/testing/web-platform/tests/tools/wptrunner/requirements_firefox.txt index 43413cf553983..782a6a09221ce 100644 --- a/testing/web-platform/tests/tools/wptrunner/requirements_firefox.txt +++ b/testing/web-platform/tests/tools/wptrunner/requirements_firefox.txt @@ -4,3 +4,5 @@ mozprocess == 0.26 mozcrash == 1.0 mozrunner == 6.14 mozleak == 0.1 +mozinstall == 1.15 +mozdownload == 1.23