Skip to content

Commit

Permalink
[wptrunner] Enable print-reftests for content shell (#36471)
Browse files Browse the repository at this point in the history
This is done by passing the 'print specifier over stdin.

Tested with:
  xvfb-run wpt run ... infrastructure/reftest/*-print.html \
    --metadata=infrastructure/metadata

All except `reftest_mismatch_page_margins-print.html` should pass
(`@page` does not currently work).
  • Loading branch information
jonathan-j-lee authored Oct 17, 2022
1 parent 5ae18d5 commit 3e00888
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
16 changes: 11 additions & 5 deletions tools/wptrunner/wptrunner/browsers/content_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@
from .base import Browser, ExecutorBrowser
from .base import get_timeout_multiplier # noqa: F401
from ..executors import executor_kwargs as base_executor_kwargs
from ..executors.executorcontentshell import (ContentShellRefTestExecutor, # noqa: F401
ContentShellCrashtestExecutor, # noqa: F401
ContentShellTestharnessExecutor) # noqa: F401
from ..executors.executorcontentshell import ( # noqa: F401
ContentShellCrashtestExecutor,
ContentShellPrintRefTestExecutor,
ContentShellRefTestExecutor,
ContentShellTestharnessExecutor,
)


__wptrunner__ = {"product": "content_shell",
"check_args": "check_args",
"browser": "ContentShellBrowser",
"executor": {"reftest": "ContentShellRefTestExecutor",
"executor": {
"crashtest": "ContentShellCrashtestExecutor",
"testharness": "ContentShellTestharnessExecutor"},
"print-reftest": "ContentShellPrintRefTestExecutor",
"reftest": "ContentShellRefTestExecutor",
"testharness": "ContentShellTestharnessExecutor",
},
"browser_kwargs": "browser_kwargs",
"executor_kwargs": "executor_kwargs",
"env_extras": "env_extras",
Expand Down
31 changes: 26 additions & 5 deletions tools/wptrunner/wptrunner/executors/executorcontentshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ def __init__(self, parent):
self.stdout_queue = parent.browser.stdout_queue
self.stdin_queue = parent.browser.stdin_queue

def do_test(self, url, timeout=None):
"""Sends a url to content_shell and returns the resulting text and image output.
def do_test(self, command, timeout=None):
"""Send a command to content_shell and return the resulting outputs.
A command consists of a URL to navigate to, followed by an optional
expected image hash and 'print' mode specifier. The syntax looks like:
http://web-platform.test:8000/test.html['<hash>['print]]
"""
self._send_command(url)
self._send_command(command)

deadline = time() + timeout if timeout else None
# The first block can also contain audio data but not in WPT.
Expand Down Expand Up @@ -201,15 +205,32 @@ def do_test(self, test):
return _convert_exception(test, exception, self.protocol.content_shell_errors.read_errors())

def screenshot(self, test, viewport_size, dpi, page_ranges):
_, image = self.protocol.content_shell_test.do_test(self.test_url(test),
test.timeout * self.timeout_multiplier)
# Currently, the page size and DPI are hardcoded for print-reftests:
# https://chromium.googlesource.com/chromium/src/+/4e1b7bc33d42b401d7d9ad1dcba72883add3e2af/content/web_test/renderer/test_runner.cc#100
# Content shell has an internal `window.testRunner.setPrintingSize(...)`
# API, but it's not callable with protocol mode.
assert dpi is None
command = self.test_url(test)
if self.is_print:
# Currently, `content_shell` uses the expected image hash to avoid
# dumping a matching image as an optimization. In Chromium, the
# hash can be computed from an expected screenshot checked into the
# source tree (i.e., without looking at a reference). This is not
# possible in `wpt`, so pass an empty hash here to force a dump.
command += "''print"
_, image = self.protocol.content_shell_test.do_test(
command, test.timeout * self.timeout_multiplier)

if not image:
return False, ("ERROR", self.protocol.content_shell_errors.read_errors())

return True, b64encode(image).decode()


class ContentShellPrintRefTestExecutor(ContentShellRefTestExecutor):
is_print = True


class ContentShellCrashtestExecutor(CrashtestExecutor):
def __init__(self, logger, browser, server_config, timeout_multiplier=1, debug_info=None,
**kwargs):
Expand Down

0 comments on commit 3e00888

Please sign in to comment.