summaryrefslogtreecommitdiffstats
path: root/testing/raptor/test/conftest.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/raptor/test/conftest.py
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/raptor/test/conftest.py')
-rw-r--r--testing/raptor/test/conftest.py165
1 files changed, 165 insertions, 0 deletions
diff --git a/testing/raptor/test/conftest.py b/testing/raptor/test/conftest.py
new file mode 100644
index 0000000000..562042ca43
--- /dev/null
+++ b/testing/raptor/test/conftest.py
@@ -0,0 +1,165 @@
+import json
+import os
+import sys
+from argparse import Namespace
+
+import pytest
+
+# need this so the raptor unit tests can find raptor/raptor classes
+here = os.path.abspath(os.path.dirname(__file__))
+raptor_dir = os.path.join(os.path.dirname(here), "raptor")
+sys.path.insert(0, raptor_dir)
+
+from browsertime import Browsertime
+from perftest import Perftest
+from webextension import WebExtensionFirefox
+
+
+@pytest.fixture
+def options(request):
+ opts = {
+ "app": "firefox",
+ "binary": "path/to/dummy/browser",
+ "browsertime_visualmetrics": False,
+ "extra_prefs": {},
+ }
+
+ if hasattr(request.module, "OPTIONS"):
+ opts.update(request.module.OPTIONS)
+ return opts
+
+
+@pytest.fixture
+def browsertime_options(options):
+ options["browsertime_node"] = "browsertime_node"
+ options["browsertime_browsertimejs"] = "browsertime_browsertimejs"
+ options["browsertime_ffmpeg"] = "browsertime_ffmpeg"
+ options["browsertime_geckodriver"] = "browsertime_geckodriver"
+ options["browsertime_chromedriver"] = "browsertime_chromedriver"
+ options["browsertime_video"] = "browsertime_video"
+ options["browsertime_visualmetrics"] = "browsertime_visualmetrics"
+ options["browsertime_no_ffwindowrecorder"] = "browsertime_no_ffwindowrecorder"
+ return options
+
+
+@pytest.fixture
+def raptor(options):
+ return WebExtensionFirefox(**options)
+
+
+@pytest.fixture
+def mock_test():
+ return {
+ "name": "raptor-firefox-tp6",
+ "test_url": "/dummy/url",
+ "secondary_url": "/dummy/url-2",
+ }
+
+
+@pytest.fixture(scope="session")
+def get_prefs():
+ def _inner(browser):
+ import raptor
+
+ prefs_dir = os.path.join(raptor.__file__, "preferences")
+ with open(os.path.join(prefs_dir, "{}.json".format(browser)), "r") as fh:
+ return json.load(fh)
+
+
+@pytest.fixture(scope="session")
+def filedir():
+ return os.path.join(here, "files")
+
+
+@pytest.fixture
+def get_binary():
+ from moztest.selftest import fixtures
+
+ def inner(app):
+ if app != "firefox":
+ pytest.xfail(reason="{} support not implemented".format(app))
+
+ binary = fixtures.binary()
+ if not binary:
+ pytest.skip("could not find a {} binary".format(app))
+ return binary
+
+ return inner
+
+
+@pytest.fixture
+def create_args():
+ args = Namespace(
+ app="firefox",
+ test="browsertime-tp6-unittest",
+ binary="path/to/binary",
+ gecko_profile=False,
+ extra_profiler_run=False,
+ debug_mode=False,
+ page_cycles=None,
+ page_timeout=None,
+ test_url_params=None,
+ host=None,
+ run_local=True,
+ browsertime=True,
+ cold=False,
+ live_sites=False,
+ enable_marionette_trace=False,
+ collect_perfstats=False,
+ chimera=False,
+ )
+
+ def inner(**kwargs):
+ for next_arg in kwargs:
+ print(next_arg)
+ print(kwargs[next_arg])
+ setattr(args, next_arg, kwargs[next_arg])
+ return args
+
+ return inner
+
+
+@pytest.fixture(scope="module")
+def ConcretePerftest():
+ class PerftestImplementation(Perftest):
+ def check_for_crashes(self):
+ super(PerftestImplementation, self).check_for_crashes()
+
+ def clean_up(self):
+ super(PerftestImplementation, self).clean_up()
+
+ def run_test(self, test, timeout):
+ super(PerftestImplementation, self).run_test(test, timeout)
+
+ def run_test_setup(self, test):
+ super(PerftestImplementation, self).run_test_setup(test)
+
+ def run_test_teardown(self, test):
+ super(PerftestImplementation, self).run_test_teardown(test)
+
+ def set_browser_test_prefs(self):
+ super(PerftestImplementation, self).set_browser_test_prefs()
+
+ def get_browser_meta(self):
+ return (), ()
+
+ def setup_chrome_args(self, test):
+ super(PerftestImplementation, self).setup_chrome_args(test)
+
+ return PerftestImplementation
+
+
+@pytest.fixture(scope="module")
+def ConcreteBrowsertime():
+ class BrowsertimeImplementation(Browsertime):
+ @property
+ def browsertime_args(self):
+ return []
+
+ def get_browser_meta(self):
+ return (), ()
+
+ def setup_chrome_args(self, test):
+ super(BrowsertimeImplementation, self).setup_chrome_args(test)
+
+ return BrowsertimeImplementation