| #!/usr/bin/env python3 |
| # Copyright 2019 The ChromiumOS Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Run mocha-headless-chrome with the right settings. |
| |
| A snapshot of Chrome that we update from time to time. |
| uribase='https://dl.google.com/linux/chrome/deb' |
| filename=$( |
| curl -s "${uribase}/dists/stable/main/binary-amd64/Packages.gz" | \ |
| zcat | \ |
| awk '$1 == "Filename:" && $2 ~ /google-chrome-stable/ {print $NF}') |
| echo "${filename##*/}" |
| wget "${uribase}/${filename}" |
| gsutil cp -a public-read google-chrome-stable_*.deb \ |
| gs://chromeos-localmirror/secureshell/distfiles/ |
| """ |
| |
| import shutil |
| import sys |
| |
| import libdot |
| |
| |
| def chrome_setup(): |
| """Download our copy of Chrome for headless testing.""" |
| spec = libdot.fetch_manifest_lookup( |
| libdot.DIR / "fetch.json", "chrome/linux" |
| ) |
| name = spec.url.rsplit("/", 1)[-1] |
| if not name.endswith("_amd64.deb"): |
| raise RuntimeError(f"Need to update naming logic: {name}") |
| name = name[:-10] |
| |
| puppeteer = libdot.node.NODE_MODULES_DIR / "puppeteer" |
| download_dir = puppeteer / ".local-chromium" |
| chrome_dir = download_dir / name |
| chrome_bin = chrome_dir / "opt" / "google" / "chrome" / "chrome" |
| if chrome_bin.exists(): |
| return chrome_bin |
| |
| # Create a tempdir to unpack everything into. |
| tmpdir = chrome_dir.with_name(f"{chrome_dir.name}.tmp") |
| shutil.rmtree(tmpdir, ignore_errors=True) |
| tmpdir.mkdir(parents=True, exist_ok=True) |
| |
| # Get the snapshot deb archive. |
| chrome_deb = tmpdir / "deb" |
| libdot.fetch_manifest_spec(spec, chrome_deb) |
| |
| # Unpack the deb archive, then clean it all up. |
| libdot.run(["ar", "x", "deb", "data.tar.xz"], cwd=tmpdir) |
| libdot.unpack("data.tar.xz", cwd=tmpdir) |
| libdot.unlink(chrome_deb) |
| libdot.unlink(tmpdir / "data.tar.xz") |
| |
| # Finally move the tempdir to the saved location. |
| tmpdir.rename(chrome_dir) |
| |
| return chrome_bin |
| |
| |
| def main(argv): |
| """The main func!""" |
| libdot.setup_logging() |
| libdot.node_and_npm_setup() |
| |
| chrome_bin = chrome_setup() |
| libdot.node.run(["mocha-headless-chrome", "-e", chrome_bin] + argv) |
| |
| |
| if __name__ == "__main__": |
| sys.exit(main(sys.argv[1:])) |