From 49062764c4579807d8298491cf250a82149fbcb5 Mon Sep 17 00:00:00 2001 From: Ahilya Sinha Date: Mon, 26 Mar 2018 15:07:32 +0000 Subject: [PATCH] Bug 1442708 [wpt PR 9748] - Firefox browser install now uses mozdownload and mozinstall, a=testonly Automatic update from web-platform-testsFirefox browser install now uses mozdownload and mozinstall (#9748) Use mozinstall to install firefox into the virtualenv. This should work in a cross-platform way and reduce the amount of custom code we have to maintain. wpt-commits: c7c6f86d31f81bf6be181ae69b5556991c615021 wpt-pr: 9748 wpt-commits: c7c6f86d31f81bf6be181ae69b5556991c615021 wpt-pr: 9748 --- .../web-platform/tests/tools/wpt/browser.py | 45 +++++++++---------- .../tests/tools/wpt/commands.json | 2 +- .../tests/tools/wpt/tests/test_browser.py | 13 ------ .../tools/wptrunner/requirements_firefox.txt | 2 + 4 files changed, 23 insertions(+), 39 deletions(-) delete mode 100644 testing/web-platform/tests/tools/wpt/tests/test_browser.py 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