diff --git a/testing/web-platform/tests/tools/wpt/browser.py b/testing/web-platform/tests/tools/wpt/browser.py index bde22b4c8ca7..6db3415a480c 100644 --- a/testing/web-platform/tests/tools/wpt/browser.py +++ b/testing/web-platform/tests/tools/wpt/browser.py @@ -680,13 +680,21 @@ class Chrome(Browser): else self._chromium_chromedriver_url(None) self.logger.info("Downloading ChromeDriver from %s" % url) unzip(get(url).raw, dest) + + # The two sources of ChromeDriver have different zip structures: + # * Chromium archives the binary inside a chromedriver_* directory; + # * Chrome archives the binary directly. + # We want to make sure the binary always ends up directly in bin/. chromedriver_dir = os.path.join( dest, 'chromedriver_%s' % self._chromedriver_platform_string()) - unzipped_path = find_executable("chromedriver", chromedriver_dir) - assert unzipped_path is not None - shutil.move(unzipped_path, dest) - rmtree(chromedriver_dir) - return find_executable("chromedriver", dest) + binary_path = find_executable("chromedriver", chromedriver_dir) + if binary_path is not None: + shutil.move(binary_path, dest) + rmtree(chromedriver_dir) + + binary_path = find_executable("chromedriver", dest) + assert binary_path is not None + return binary_path def install_webdriver(self, dest=None, channel=None, browser_binary=None): if channel == "nightly": diff --git a/testing/web-platform/tests/tools/wpt/tests/test_install.py b/testing/web-platform/tests/tools/wpt/tests/test_install.py new file mode 100644 index 000000000000..7d55d419c140 --- /dev/null +++ b/testing/web-platform/tests/tools/wpt/tests/test_install.py @@ -0,0 +1,86 @@ +import logging +import os +import sys + +import pytest + +from tools.wpt import browser, utils, wpt + + +@pytest.mark.slow +@pytest.mark.remote_network +def test_install_chromium(): + if sys.platform == "win32": + chromium_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "chrome-win") + elif sys.platform == "darwin": + chromium_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "chrome-mac") + else: + chromium_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "chrome-linux") + + if os.path.exists(chromium_path): + utils.rmtree(chromium_path) + with pytest.raises(SystemExit) as excinfo: + wpt.main(argv=["install", "chrome", "browser", "--channel=nightly"]) + assert excinfo.value.code == 0 + assert os.path.exists(chromium_path) + utils.rmtree(chromium_path) + + +@pytest.mark.slow +@pytest.mark.remote_network +def test_install_chromedriver_official(): + # This is not technically an integration test as we do not want to require Chrome Stable to run it. + chrome = browser.Chrome(logging.getLogger("Chrome")) + if sys.platform == "win32": + dest = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "Scripts") + chromedriver_path = os.path.join(dest, "chromedriver.exe") + else: + dest = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "bin") + chromedriver_path = os.path.join(dest, "chromedriver") + if os.path.exists(chromedriver_path): + os.unlink(chromedriver_path) + # This is a stable version. + binary_path = chrome.install_webdriver_by_version("84.0.4147.89", dest=dest) + assert binary_path == chromedriver_path + assert os.path.exists(chromedriver_path) + os.unlink(chromedriver_path) + + +@pytest.mark.slow +@pytest.mark.remote_network +def test_install_chromedriver_nightly(): + if sys.platform == "win32": + chromedriver_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "Scripts", "chromedriver.exe") + else: + chromedriver_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "bin", "chromedriver") + if os.path.exists(chromedriver_path): + os.unlink(chromedriver_path) + with pytest.raises(SystemExit) as excinfo: + wpt.main(argv=["install", "chrome", "webdriver"]) + assert excinfo.value.code == 0 + assert os.path.exists(chromedriver_path) + # FIXME: On Windows, this may sometimes fail (access denied), possibly + # because the file handler is not released immediately. + try: + os.unlink(chromedriver_path) + except OSError: + if sys.platform != "win32": + raise + + +@pytest.mark.slow +@pytest.mark.remote_network +@pytest.mark.xfail(sys.platform == "win32", + reason="https://github.com/web-platform-tests/wpt/issues/17074") +def test_install_firefox(): + if sys.platform == "darwin": + fx_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "Firefox Nightly.app") + else: + fx_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "firefox") + if os.path.exists(fx_path): + utils.rmtree(fx_path) + with pytest.raises(SystemExit) as excinfo: + wpt.main(argv=["install", "firefox", "browser", "--channel=nightly"]) + assert excinfo.value.code == 0 + assert os.path.exists(fx_path) + utils.rmtree(fx_path) diff --git a/testing/web-platform/tests/tools/wpt/tests/test_wpt.py b/testing/web-platform/tests/tools/wpt/tests/test_wpt.py index d2d0b541a379..b5ae79d13112 100644 --- a/testing/web-platform/tests/tools/wpt/tests/test_wpt.py +++ b/testing/web-platform/tests/tools/wpt/tests/test_wpt.py @@ -239,65 +239,6 @@ def test_run_verify_unstable(temp_test): assert excinfo.value.code == 0 -@pytest.mark.slow -@pytest.mark.remote_network -def test_install_chromium(): - if sys.platform == "win32": - chromium_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "chrome-win") - elif sys.platform == "darwin": - chromium_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "chrome-mac") - else: - chromium_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "chrome-linux") - - if os.path.exists(chromium_path): - utils.rmtree(chromium_path) - with pytest.raises(SystemExit) as excinfo: - wpt.main(argv=["install", "chrome", "browser", "--channel=nightly"]) - assert excinfo.value.code == 0 - assert os.path.exists(chromium_path) - utils.rmtree(chromium_path) - - -@pytest.mark.slow -@pytest.mark.remote_network -def test_install_chromedriver(): - if sys.platform == "win32": - chromedriver_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "Scripts", "chromedriver.exe") - else: - chromedriver_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "bin", "chromedriver") - if os.path.exists(chromedriver_path): - os.unlink(chromedriver_path) - with pytest.raises(SystemExit) as excinfo: - wpt.main(argv=["install", "chrome", "webdriver"]) - assert excinfo.value.code == 0 - assert os.path.exists(chromedriver_path) - # FIXME: On Windows, this may sometimes fail (access denied), possibly - # because the file handler is not released immediately. - try: - os.unlink(chromedriver_path) - except OSError: - if sys.platform != "win32": - raise - - -@pytest.mark.slow -@pytest.mark.remote_network -@pytest.mark.xfail(sys.platform == "win32", - reason="https://github.com/web-platform-tests/wpt/issues/17074") -def test_install_firefox(): - if sys.platform == "darwin": - fx_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "Firefox Nightly.app") - else: - fx_path = os.path.join(wpt.localpaths.repo_root, wpt.venv_dir(), "browsers", "nightly", "firefox") - if os.path.exists(fx_path): - utils.rmtree(fx_path) - with pytest.raises(SystemExit) as excinfo: - wpt.main(argv=["install", "firefox", "browser", "--channel=nightly"]) - assert excinfo.value.code == 0 - assert os.path.exists(fx_path) - utils.rmtree(fx_path) - - def test_files_changed(capsys): commit = "9047ac1d9f51b1e9faa4f9fad9c47d109609ab09" with pytest.raises(SystemExit) as excinfo: diff --git a/testing/web-platform/tests/tools/wpt/utils.py b/testing/web-platform/tests/tools/wpt/utils.py index 6608af754b2a..6556ff48b36f 100644 --- a/testing/web-platform/tests/tools/wpt/utils.py +++ b/testing/web-platform/tests/tools/wpt/utils.py @@ -107,7 +107,7 @@ def rmtree(path): # hasn't been fully released (a common issue). def handle_remove_readonly(func, path, exc): excvalue = exc[1] - if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES: + if func in (os.rmdir, os.remove, os.unlink) and excvalue.errno == errno.EACCES: os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777 func(path) else: