commit 927f60a7cc9674955e5f7b6872fd15e674af20d0 Author: Carlos Alberto Lopez Perez Date: Tue Nov 12 20:10:27 2024 +0100 rebase diff --git a/tools/wpt/browser.py b/tools/wpt/browser.py index 923bf9904f..023f8447c5 100644 --- a/tools/wpt/browser.py +++ b/tools/wpt/browser.py @@ -2375,16 +2375,22 @@ class WebKitTestRunner(Browser): class WebKitGTKMiniBrowser(WebKit): + """WebKitGTK MiniBrowser specific interface.""" + + BASE_DOWNLOAD_URI = "https://webkitgtk.org/built-products/" + PORT_PRETTY_NAME = "WebKitGTK" + WEBDRIVER_BINARY_NAME = "WebKitWebDriver" + LIBEXEC_SUBDIR_PREFIX = "webkit2gtk" + product = "webkitgtk_minibrowser" def download(self, dest=None, channel=None, rename=None): - base_dowload_uri = "https://webkitgtk.org/built-products/" - base_download_dir = base_dowload_uri + platform.machine() + "/release/" + channel + "/MiniBrowser/" + base_download_dir = self.BASE_DOWNLOAD_URI + platform.machine() + "/release/" + channel + "/MiniBrowser/" try: response = get(base_download_dir + "LAST-IS") except requests.exceptions.HTTPError as e: if e.response.status_code == 404: - raise RuntimeError("Can't find a WebKitGTK MiniBrowser %s bundle for %s at %s" - % (channel, platform.machine(), base_dowload_uri)) + raise RuntimeError("Can't find a %s MiniBrowser %s bundle for %s at %s" + % (self.PORT_PRETTY_NAME, channel, platform.machine(), self.BASE_DOWNLOAD_URI)) raise bundle_filename = response.text.strip() @@ -2393,7 +2399,7 @@ class WebKitGTKMiniBrowser(WebKit): dest = self._get_browser_download_dir(dest, channel) bundle_file_path = os.path.join(dest, bundle_filename) - self.logger.info("Downloading WebKitGTK MiniBrowser bundle from %s" % bundle_url) + self.logger.info("Downloading %s MiniBrowser bundle from %s" %(self.PORT_PRETTY_NAME, bundle_url)) with open(bundle_file_path, "w+b") as f: get_download_to_descriptor(f, bundle_url) @@ -2405,13 +2411,13 @@ class WebKitGTKMiniBrowser(WebKit): if bundle_expected_hash != bundle_computed_hash: self.logger.error("Calculated SHA256 hash is %s but was expecting %s" % (bundle_computed_hash, bundle_expected_hash)) - raise RuntimeError("The WebKitGTK MiniBrowser bundle at %s has incorrect SHA256 hash." % bundle_file_path) + raise RuntimeError("The %s MiniBrowser bundle at %s has incorrect SHA256 hash." % (self.PORT_PRETTY_NAME, bundle_file_path)) return bundle_file_path def install(self, dest=None, channel=None, prompt=True): dest = self._get_browser_binary_dir(dest, channel) bundle_path = self.download(dest, channel) - bundle_uncompress_directory = os.path.join(dest, "webkitgtk_minibrowser") + bundle_uncompress_directory = os.path.join(dest, self.product) # Clean it from previous runs if os.path.exists(bundle_uncompress_directory): @@ -2425,17 +2431,17 @@ class WebKitGTKMiniBrowser(WebKit): elif ".tar." in bundle_file_name: untar(f, bundle_uncompress_directory) else: - raise NotImplementedError("Unable to install WebKitGTK MiniBrowser bundle from file:" % bundle_file_name) + raise NotImplementedError("Unable to install %s MiniBrowser bundle from file:" %(self.PORT_PRETTY_NAME, bundle_file_name)) os.remove(bundle_path) - for expected_binary in ["MiniBrowser", "WebKitWebDriver"]: + for expected_binary in ["MiniBrowser", self.WEBDRIVER_BINARY_NAME]: binary_path = os.path.join(bundle_uncompress_directory, expected_binary) if not (os.path.isfile(binary_path) and os.access(binary_path, os.X_OK)): raise RuntimeError("Can't find a %s binary at %s" % (expected_binary, binary_path)) minibrowser_path = os.path.join(bundle_uncompress_directory, "MiniBrowser") version_str = subprocess.check_output([minibrowser_path, "--version"]).decode("utf-8").strip() - self.logger.info("WebKitGTK MiniBrowser bundle for channel %s installed: %s" % (channel, version_str)) + self.logger.info("%s MiniBrowser bundle for channel %s installed: %s" % (self.PORT_PRETTY_NAME, channel, version_str)) install_ok_file = os.path.join(bundle_uncompress_directory, ".installation-ok") open(install_ok_file, "w").close() # touch return minibrowser_path @@ -2443,7 +2449,7 @@ class WebKitGTKMiniBrowser(WebKit): def _find_executable_in_channel_bundle(self, binary, venv_path=None, channel=None): if venv_path: venv_base_path = self._get_browser_binary_dir(venv_path, channel) - bundle_dir = os.path.join(venv_base_path, "webkitgtk_minibrowser") + bundle_dir = os.path.join(venv_base_path, self.product) install_ok_file = os.path.join(bundle_dir, ".installation-ok") if os.path.isfile(install_ok_file): return which(binary, path=bundle_dir) @@ -2452,8 +2458,10 @@ class WebKitGTKMiniBrowser(WebKit): def find_binary(self, venv_path=None, channel=None): minibrowser_path = self._find_executable_in_channel_bundle("MiniBrowser", venv_path, channel) if minibrowser_path: + self.logger.info("Found %s MiniBrowser %s at path: %s" % (self.PORT_PRETTY_NAME, channel, minibrowser_path)) return minibrowser_path + # Find MiniBrowser on the system which is usually installed on the libexec dir triplet = "x86_64-linux-gnu" # Try to use GCC to detect this machine triplet gcc = which("gcc") @@ -2462,22 +2470,22 @@ class WebKitGTKMiniBrowser(WebKit): triplet = call(gcc, "-dumpmachine").strip() except subprocess.CalledProcessError: pass - - versions = ["4.0", "4.1"] - libexecpaths = [] - - for version in versions: - # Fedora paths. - libexecpaths.append(f"/usr/libexec/webkit2gtk-{version}") - # Debian/Ubuntu paths - libexecpaths.append(f"/usr/lib/{triplet}/webkit2gtk-{version}") - - return which("MiniBrowser", path=os.pathsep.join(libexecpaths)) + for libexec_dir in ["/usr/libexec", f"/usr/lib/{triplet}"]: + if os.path.isdir(libexec_dir): + for libexec_entry in sorted(os.listdir(libexec_dir), reverse=True): + if libexec_entry.startswith(self.LIBEXEC_SUBDIR_PREFIX): + minibrowser_candidate_path = os.path.join(libexec_dir, libexec_entry, 'MiniBrowser') + if os.path.isfile(minibrowser_candidate_path) and os.access(minibrowser_candidate_path, os.X_OK): + self.logger.info("Found %s MiniBrowser at path: %s" % (self.PORT_PRETTY_NAME, minibrowser_candidate_path)) + return minibrowser_candidate_path + return None def find_webdriver(self, venv_path=None, channel=None): - webdriver_path = self._find_executable_in_channel_bundle("WebKitWebDriver", venv_path, channel) + webdriver_path = self._find_executable_in_channel_bundle(self.WEBDRIVER_BINARY_NAME, venv_path, channel) if not webdriver_path: - webdriver_path = which("WebKitWebDriver") + webdriver_path = which(self.WEBDRIVER_BINARY_NAME) + if webdriver_path: + self.logger.info("Found %s WebDriver at path: %s" % (self.PORT_PRETTY_NAME, webdriver_path)) return webdriver_path def version(self, binary=None, webdriver_binary=None): @@ -2489,7 +2497,7 @@ class WebKitGTKMiniBrowser(WebKit): return None # Example output: "WebKitGTK 2.26.1" if output: - m = re.match(r"WebKitGTK (.+)", output) + m = re.match(r"%s (.+)" %self.PORT_PRETTY_NAME, output) if not m: self.logger.warning("Failed to extract version from: %s" % output) return None @@ -2497,6 +2505,14 @@ class WebKitGTKMiniBrowser(WebKit): return None +class WPEWebKitMiniBrowser(WebKitGTKMiniBrowser): + BASE_DOWNLOAD_URI = "https://wpewebkit.org/built-products/" + PORT_PRETTY_NAME = "WPE WebKit" + WEBDRIVER_BINARY_NAME = "WPEWebDriver" + LIBEXEC_SUBDIR_PREFIX = "wpe-webkit" + product = "wpewebkit_minibrowser" + + class Epiphany(Browser): """Epiphany-specific interface.""" diff --git a/tools/wpt/install.py b/tools/wpt/install.py index 1e6408b0be..e8f0a36a08 100644 --- a/tools/wpt/install.py +++ b/tools/wpt/install.py @@ -14,6 +14,7 @@ latest_channels = { 'safari': 'preview', 'servo': 'nightly', 'webkitgtk_minibrowser': 'nightly', + 'wpewebkit_minibrowser': 'nightly', 'wktr': 'main', } diff --git a/tools/wpt/run.py b/tools/wpt/run.py index 9c6acbc2a4..57f8ca66aa 100644 --- a/tools/wpt/run.py +++ b/tools/wpt/run.py @@ -819,6 +819,7 @@ class WebKitTestRunner(BrowserSetup): class WebKitGTKMiniBrowser(BrowserSetup): name = "webkitgtk_minibrowser" browser_cls = browser.WebKitGTKMiniBrowser + WEBDRIVER_BINARY_NAME = "WebKitWebDriver" def install(self, channel=None): if self.prompt_install(self.name): @@ -838,10 +839,16 @@ class WebKitGTKMiniBrowser(BrowserSetup): venv_path=self.venv.path, channel=kwargs["browser_channel"]) if webdriver_binary is None: - raise WptrunError("Unable to find WebKitWebDriver in PATH") + raise WptrunError("Unable to find %s in PATH" % self.WEBDRIVER_BINARY_NAME) kwargs["webdriver_binary"] = webdriver_binary +class WPEWebKitMiniBrowser(WebKitGTKMiniBrowser): + name = "wpewebkit_minibrowser" + browser_cls = browser.WPEWebKitMiniBrowser + WEBDRIVER_BINARY_NAME = "WPEWebDriver" + + class Epiphany(BrowserSetup): name = "epiphany" browser_cls = browser.Epiphany @@ -883,6 +890,7 @@ product_setup = { "webkit": WebKit, "wktr": WebKitTestRunner, "webkitgtk_minibrowser": WebKitGTKMiniBrowser, + "wpewebkit_minibrowser": WPEWebKitMiniBrowser, "epiphany": Epiphany, "ladybird": Ladybird, } @@ -961,7 +969,7 @@ def setup_wptrunner(venv, **kwargs): if kwargs["install_browser"]: logger.info("Installing browser") - kwargs["binary"] = setup_cls.install(channel=channel) + kwargs["binary"] = setup_cls.install(channel=kwargs["browser_channel"]) setup_cls.setup(kwargs) diff --git a/tools/wptrunner/wptrunner/browsers/__init__.py b/tools/wptrunner/wptrunner/browsers/__init__.py index aaf91a1dc8..c27ae7281d 100644 --- a/tools/wptrunner/wptrunner/browsers/__init__.py +++ b/tools/wptrunner/wptrunner/browsers/__init__.py @@ -38,6 +38,7 @@ product_list = ["android_webview", "opera", "webkit", "webkitgtk_minibrowser", + "wpewebkit_minibrowser", "wktr", "epiphany", "ladybird"] diff --git a/tools/wptrunner/wptrunner/browsers/wpewebkit_minibrowser.py b/tools/wptrunner/wptrunner/browsers/wpewebkit_minibrowser.py new file mode 100644 index 0000000000..07c169365c --- /dev/null +++ b/tools/wptrunner/wptrunner/browsers/wpewebkit_minibrowser.py @@ -0,0 +1,77 @@ +# mypy: allow-untyped-defs + +from .base import (NullBrowser, # noqa: F401 + certificate_domain_list, + get_timeout_multiplier, # noqa: F401 + maybe_add_args) +from .webkit import WebKitBrowser +from ..executors import executor_kwargs as base_executor_kwargs +from ..executors.base import WdspecExecutor # noqa: F401 +from ..executors.executorwebdriver import (WebDriverTestharnessExecutor, # noqa: F401 + WebDriverRefTestExecutor, # noqa: F401 + WebDriverCrashtestExecutor) # noqa: F401 + +__wptrunner__ = {"product": "wpewebkit_minibrowser", + "check_args": "check_args", + "browser": "WPEWebKitMiniBrowser", + "browser_kwargs": "browser_kwargs", + "executor": {"testharness": "WebDriverTestharnessExecutor", + "reftest": "WebDriverRefTestExecutor", + "wdspec": "WdspecExecutor", + "crashtest": "WebDriverCrashtestExecutor"}, + "executor_kwargs": "executor_kwargs", + "env_extras": "env_extras", + "env_options": "env_options", + "run_info_extras": "run_info_extras", + "timeout_multiplier": "get_timeout_multiplier"} + + +def check_args(**kwargs): + pass + + +def browser_kwargs(logger, test_type, run_info_data, config, **kwargs): + # Workaround for https://gitlab.gnome.org/GNOME/libsoup/issues/172 + webdriver_required_args = ["--host=127.0.0.1"] + webdriver_args = maybe_add_args(webdriver_required_args, kwargs.get("webdriver_args")) + return {"binary": kwargs["binary"], + "webdriver_binary": kwargs["webdriver_binary"], + "webdriver_args": webdriver_args} + + +def capabilities(server_config, **kwargs): + browser_required_args = ["--automation", "--headless"] + args = kwargs.get("binary_args", []) + args = maybe_add_args(browser_required_args, args) + return { + "browserName": "MiniBrowser", + "wpe:browserOptions": { + "binary": kwargs["binary"], + "args": args, + "certificates": certificate_domain_list(server_config.domains_set, kwargs["host_cert_path"])}} + + +def executor_kwargs(logger, test_type, test_environment, run_info_data, + **kwargs): + executor_kwargs = base_executor_kwargs(test_type, test_environment, run_info_data, **kwargs) + executor_kwargs["close_after_done"] = True + executor_kwargs["capabilities"] = capabilities(test_environment.config, **kwargs) + if test_type == "wdspec": + executor_kwargs["binary_args"] = executor_kwargs["capabilities"]["wpe:browserOptions"]["args"] + return executor_kwargs + + +def env_extras(**kwargs): + return [] + + +def env_options(): + return {} + + +def run_info_extras(logger, **kwargs): + return {"webkit_port": "wpe"} + + +class WPEWebKitMiniBrowser(WebKitBrowser): + pass