From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- testing/mozbase/mozrunner/tests/conftest.py | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 testing/mozbase/mozrunner/tests/conftest.py (limited to 'testing/mozbase/mozrunner/tests/conftest.py') diff --git a/testing/mozbase/mozrunner/tests/conftest.py b/testing/mozbase/mozrunner/tests/conftest.py new file mode 100644 index 0000000000..509deaf231 --- /dev/null +++ b/testing/mozbase/mozrunner/tests/conftest.py @@ -0,0 +1,83 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this file, +# You can obtain one at http://mozilla.org/MPL/2.0/. + +from __future__ import absolute_import + +import os +import threading +from time import sleep + +import mozrunner +import pytest +from moztest.selftest import fixtures + + +@pytest.fixture(scope="session") +def get_binary(): + if "BROWSER_PATH" in os.environ: + os.environ["GECKO_BINARY_PATH"] = os.environ["BROWSER_PATH"] + + def inner(app): + if app not in ("chrome", "chromium", "firefox"): + pytest.xfail(reason="{} support not implemented".format(app)) + + if app == "firefox": + binary = fixtures.binary() + elif app == "chrome": + binary = os.environ.get("CHROME_BINARY_PATH") + elif app == "chromium": + binary = os.environ.get("CHROMIUM_BINARY_PATH") + + if not binary: + pytest.skip("could not find a {} binary".format(app)) + return binary + + return inner + + +@pytest.fixture(params=["firefox", "chrome", "chromium"]) +def runner(request, get_binary): + app = request.param + binary = get_binary(app) + + cmdargs = ["--headless"] + if app in ["chrome", "chromium"]: + # prevents headless chromium from exiting after loading the page + cmdargs.append("--remote-debugging-port=9222") + # only needed on Windows, but no harm in specifying it everywhere + cmdargs.append("--disable-gpu") + runner = mozrunner.runners[app](binary, cmdargs=cmdargs) + runner.app = app + yield runner + runner.stop() + + +class RunnerThread(threading.Thread): + def __init__(self, runner, start=False, timeout=1): + threading.Thread.__init__(self) + self.runner = runner + self.timeout = timeout + self.do_start = start + + def run(self): + sleep(self.timeout) + if self.do_start: + self.runner.start() + else: + self.runner.stop() + + +@pytest.fixture +def create_thread(): + threads = [] + + def inner(*args, **kwargs): + thread = RunnerThread(*args, **kwargs) + threads.append(thread) + return thread + + yield inner + + for thread in threads: + thread.join() -- cgit v1.2.3