mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Auto merge of #9272 - Ms2ger:dpi, r=ato
Support device-pixel-ratio in wpt reftests. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9272) <!-- Reviewable:end -->
This commit is contained in:
commit
0e6bca8e8e
16 changed files with 134 additions and 22 deletions
|
@ -4,8 +4,5 @@
|
|||
# Should be == with expected failure:
|
||||
fragment=top != ../html/acid2.html acid2_ref.html
|
||||
|
||||
resolution=300x300,device-pixel-ratio=2 != pixel_snapping_border_a.html pixel_snapping_border_ref.html
|
||||
resolution=300x300,device-pixel-ratio=2 != pixel_snapping_position_a.html pixel_snapping_position_ref.html
|
||||
|
||||
# This file must be sorted alphabetically.
|
||||
# Please run `./mach test-tidy` to check your changes.
|
||||
|
|
|
@ -123,7 +123,7 @@ class RefTest(URLManifestItem):
|
|||
item_type = "reftest"
|
||||
|
||||
def __init__(self, source_file, url, references, url_base="/", timeout=None,
|
||||
viewport_size=None, manifest=None):
|
||||
viewport_size=None, dpi=None, manifest=None):
|
||||
URLManifestItem.__init__(self, source_file, url, url_base=url_base, manifest=manifest)
|
||||
for _, ref_type in references:
|
||||
if ref_type not in ["==", "!="]:
|
||||
|
@ -131,13 +131,14 @@ class RefTest(URLManifestItem):
|
|||
self.references = tuple(references)
|
||||
self.timeout = timeout
|
||||
self.viewport_size = viewport_size
|
||||
self.dpi = dpi
|
||||
|
||||
@property
|
||||
def is_reference(self):
|
||||
return self.source_file.name_is_reference
|
||||
|
||||
def meta_key(self):
|
||||
return (self.timeout, self.viewport_size)
|
||||
return (self.timeout, self.viewport_size, self.dpi)
|
||||
|
||||
def to_json(self):
|
||||
rv = URLManifestItem.to_json(self)
|
||||
|
@ -146,6 +147,8 @@ class RefTest(URLManifestItem):
|
|||
rv["timeout"] = self.timeout
|
||||
if self.viewport_size is not None:
|
||||
rv["viewport_size"] = self.viewport_size
|
||||
if self.dpi is not None:
|
||||
rv["dpi"] = self.dpi
|
||||
return rv
|
||||
|
||||
@classmethod
|
||||
|
@ -157,6 +160,7 @@ class RefTest(URLManifestItem):
|
|||
url_base=manifest.url_base,
|
||||
timeout=obj.get("timeout"),
|
||||
viewport_size=obj.get("viewport_size"),
|
||||
dpi=obj.get("dpi"),
|
||||
manifest=manifest)
|
||||
|
||||
|
||||
|
|
|
@ -197,6 +197,23 @@ class SourceFile(object):
|
|||
|
||||
return self.viewport_nodes[0].attrib.get("content", None)
|
||||
|
||||
@cached_property
|
||||
def dpi_nodes(self):
|
||||
"""List of ElementTree Elements corresponding to nodes in a test that
|
||||
specify device pixel ratios"""
|
||||
return self.root.findall(".//{http://www.w3.org/1999/xhtml}meta[@name='device-pixel-ratio']")
|
||||
|
||||
@cached_property
|
||||
def dpi(self):
|
||||
"""The device pixel ratio of a test or reference file"""
|
||||
if not self.root:
|
||||
return None
|
||||
|
||||
if not self.dpi_nodes:
|
||||
return None
|
||||
|
||||
return self.dpi_nodes[0].attrib.get("content", None)
|
||||
|
||||
@cached_property
|
||||
def testharness_nodes(self):
|
||||
"""List of ElementTree Elements corresponding to nodes representing a
|
||||
|
@ -288,7 +305,8 @@ class SourceFile(object):
|
|||
rv.append(TestharnessTest(self, url, timeout=self.timeout))
|
||||
|
||||
elif self.content_is_ref_node:
|
||||
rv = [RefTest(self, self.url, self.references, timeout=self.timeout, viewport_size=self.viewport_size)]
|
||||
rv = [RefTest(self, self.url, self.references, timeout=self.timeout,
|
||||
viewport_size=self.viewport_size, dpi=self.dpi)]
|
||||
|
||||
else:
|
||||
# If nothing else it's a helper file, which we don't have a specific type for
|
||||
|
|
|
@ -206,12 +206,12 @@ class RefTestImplementation(object):
|
|||
def logger(self):
|
||||
return self.executor.logger
|
||||
|
||||
def get_hash(self, test, viewport_size):
|
||||
def get_hash(self, test, viewport_size, dpi):
|
||||
timeout = test.timeout * self.timeout_multiplier
|
||||
key = (test.url, viewport_size)
|
||||
key = (test.url, viewport_size, dpi)
|
||||
|
||||
if key not in self.screenshot_cache:
|
||||
success, data = self.executor.screenshot(test, viewport_size)
|
||||
success, data = self.executor.screenshot(test, viewport_size, dpi)
|
||||
|
||||
if not success:
|
||||
return False, data
|
||||
|
@ -236,6 +236,7 @@ class RefTestImplementation(object):
|
|||
|
||||
def run_test(self, test):
|
||||
viewport_size = test.viewport_size
|
||||
dpi = test.dpi
|
||||
self.message = []
|
||||
|
||||
# Depth-first search of reference tree, with the goal
|
||||
|
@ -249,7 +250,7 @@ class RefTestImplementation(object):
|
|||
nodes, relation = stack.pop()
|
||||
|
||||
for i, node in enumerate(nodes):
|
||||
success, data = self.get_hash(node, viewport_size)
|
||||
success, data = self.get_hash(node, viewport_size, dpi)
|
||||
if success is False:
|
||||
return {"status": data[0], "message": data[1]}
|
||||
|
||||
|
@ -266,7 +267,7 @@ class RefTestImplementation(object):
|
|||
|
||||
for i, (node, screenshot) in enumerate(zip(nodes, screenshots)):
|
||||
if screenshot is None:
|
||||
success, screenshot = self.retake_screenshot(node, viewport_size)
|
||||
success, screenshot = self.retake_screenshot(node, viewport_size, dpi)
|
||||
if success:
|
||||
screenshots[i] = screenshot
|
||||
|
||||
|
@ -277,12 +278,12 @@ class RefTestImplementation(object):
|
|||
"message": "\n".join(self.message),
|
||||
"extra": {"reftest_screenshots": log_data}}
|
||||
|
||||
def retake_screenshot(self, node, viewport_size):
|
||||
success, data = self.executor.screenshot(node, viewport_size)
|
||||
def retake_screenshot(self, node, viewport_size, dpi):
|
||||
success, data = self.executor.screenshot(node, viewport_size, dpi)
|
||||
if not success:
|
||||
return False, data
|
||||
|
||||
key = (node.url, viewport_size)
|
||||
key = (node.url, viewport_size, dpi)
|
||||
hash_val, _ = self.screenshot_cache[key]
|
||||
self.screenshot_cache[key] = hash_val, data
|
||||
return True, data
|
||||
|
|
|
@ -385,9 +385,10 @@ class MarionetteRefTestExecutor(RefTestExecutor):
|
|||
|
||||
return self.convert_result(test, result)
|
||||
|
||||
def screenshot(self, test, viewport_size):
|
||||
def screenshot(self, test, viewport_size, dpi):
|
||||
# https://github.com/w3c/wptrunner/issues/166
|
||||
assert viewport_size is None
|
||||
assert dpi is None
|
||||
|
||||
timeout = self.timeout_multiplier * test.timeout if self.debug_info is None else None
|
||||
|
||||
|
|
|
@ -247,9 +247,10 @@ class SeleniumRefTestExecutor(RefTestExecutor):
|
|||
|
||||
return self.convert_result(test, result)
|
||||
|
||||
def screenshot(self, test, viewport_size):
|
||||
def screenshot(self, test, viewport_size, dpi):
|
||||
# https://github.com/w3c/wptrunner/issues/166
|
||||
assert viewport_size is None
|
||||
assert dpi is None
|
||||
|
||||
return SeleniumRun(self._screenshot,
|
||||
self.protocol.webdriver,
|
||||
|
|
|
@ -196,7 +196,7 @@ class ServoRefTestExecutor(ProcessTestExecutor):
|
|||
os.rmdir(self.tempdir)
|
||||
ProcessTestExecutor.teardown(self)
|
||||
|
||||
def screenshot(self, test, viewport_size):
|
||||
def screenshot(self, test, viewport_size, dpi):
|
||||
full_url = self.test_url(test)
|
||||
|
||||
with TempFilename(self.tempdir) as output_path:
|
||||
|
@ -216,6 +216,9 @@ class ServoRefTestExecutor(ProcessTestExecutor):
|
|||
if viewport_size:
|
||||
command += ["--resolution", viewport_size]
|
||||
|
||||
if dpi:
|
||||
command += ["--device-pixel-ratio", dpi]
|
||||
|
||||
self.command = debug_args + command
|
||||
|
||||
env = os.environ.copy()
|
||||
|
|
|
@ -226,9 +226,10 @@ class ServoWebDriverRefTestExecutor(RefTestExecutor):
|
|||
message += traceback.format_exc(e)
|
||||
return test.result_cls("ERROR", message), []
|
||||
|
||||
def screenshot(self, test, viewport_size):
|
||||
def screenshot(self, test, viewport_size, dpi):
|
||||
# https://github.com/w3c/wptrunner/issues/166
|
||||
assert viewport_size is None
|
||||
assert dpi is None
|
||||
|
||||
timeout = (test.timeout * self.timeout_multiplier + extra_timeout
|
||||
if self.debug_info is None else None)
|
||||
|
|
|
@ -216,7 +216,7 @@ class ReftestTest(Test):
|
|||
|
||||
def __init__(self, url, inherit_metadata, test_metadata, references,
|
||||
timeout=DEFAULT_TIMEOUT, path=None, viewport_size=None,
|
||||
protocol="http"):
|
||||
dpi=None, protocol="http"):
|
||||
Test.__init__(self, url, inherit_metadata, test_metadata, timeout, path, protocol)
|
||||
|
||||
for _, ref_type in references:
|
||||
|
@ -225,6 +225,7 @@ class ReftestTest(Test):
|
|||
|
||||
self.references = references
|
||||
self.viewport_size = viewport_size
|
||||
self.dpi = dpi
|
||||
|
||||
@classmethod
|
||||
def from_manifest(cls,
|
||||
|
@ -250,6 +251,7 @@ class ReftestTest(Test):
|
|||
timeout=timeout,
|
||||
path=manifest_test.path,
|
||||
viewport_size=manifest_test.viewport_size,
|
||||
dpi=manifest_test.dpi,
|
||||
protocol="https" if hasattr(manifest_test, "https") and manifest_test.https else "http")
|
||||
|
||||
nodes[url] = node
|
||||
|
|
|
@ -3511,6 +3511,34 @@
|
|||
"url": "/_mozilla/css/percentage_width_inline_block_a.html"
|
||||
}
|
||||
],
|
||||
"css/pixel_snapping_border_a.html": [
|
||||
{
|
||||
"dpi": "2",
|
||||
"path": "css/pixel_snapping_border_a.html",
|
||||
"references": [
|
||||
[
|
||||
"/_mozilla/css/pixel_snapping_border_ref.html",
|
||||
"!="
|
||||
]
|
||||
],
|
||||
"url": "/_mozilla/css/pixel_snapping_border_a.html",
|
||||
"viewport_size": "300x300"
|
||||
}
|
||||
],
|
||||
"css/pixel_snapping_position_a.html": [
|
||||
{
|
||||
"dpi": "2",
|
||||
"path": "css/pixel_snapping_position_a.html",
|
||||
"references": [
|
||||
[
|
||||
"/_mozilla/css/pixel_snapping_position_ref.html",
|
||||
"!="
|
||||
]
|
||||
],
|
||||
"url": "/_mozilla/css/pixel_snapping_position_a.html",
|
||||
"viewport_size": "300x300"
|
||||
}
|
||||
],
|
||||
"css/png_rgba_colorspace_a.html": [
|
||||
{
|
||||
"path": "css/png_rgba_colorspace_a.html",
|
||||
|
@ -9526,6 +9554,34 @@
|
|||
"url": "/_mozilla/css/percentage_width_inline_block_a.html"
|
||||
}
|
||||
],
|
||||
"css/pixel_snapping_border_a.html": [
|
||||
{
|
||||
"dpi": "2",
|
||||
"path": "css/pixel_snapping_border_a.html",
|
||||
"references": [
|
||||
[
|
||||
"/_mozilla/css/pixel_snapping_border_ref.html",
|
||||
"!="
|
||||
]
|
||||
],
|
||||
"url": "/_mozilla/css/pixel_snapping_border_a.html",
|
||||
"viewport_size": "300x300"
|
||||
}
|
||||
],
|
||||
"css/pixel_snapping_position_a.html": [
|
||||
{
|
||||
"dpi": "2",
|
||||
"path": "css/pixel_snapping_position_a.html",
|
||||
"references": [
|
||||
[
|
||||
"/_mozilla/css/pixel_snapping_position_ref.html",
|
||||
"!="
|
||||
]
|
||||
],
|
||||
"url": "/_mozilla/css/pixel_snapping_position_a.html",
|
||||
"viewport_size": "300x300"
|
||||
}
|
||||
],
|
||||
"css/png_rgba_colorspace_a.html": [
|
||||
{
|
||||
"path": "css/png_rgba_colorspace_a.html",
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Pixel snapping border test</title>
|
||||
<meta name=device-pixel-ratio content=2>
|
||||
<meta name=viewport-size content=300x300>
|
||||
<link rel=mismatch href=pixel_snapping_border_ref.html>
|
||||
<style>
|
||||
div {
|
||||
height: 101px;
|
|
@ -3,6 +3,9 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Pixel snapping position test</title>
|
||||
<meta name=device-pixel-ratio content=2>
|
||||
<meta name=viewport-size content=300x300>
|
||||
<link rel=mismatch href=pixel_snapping_position_ref.html>
|
||||
<style>
|
||||
div {
|
||||
position: absolute;
|
|
@ -130,7 +130,7 @@ class RefTest(URLManifestItem):
|
|||
item_type = "reftest"
|
||||
|
||||
def __init__(self, source_file, url, references, url_base="/", timeout=None,
|
||||
viewport_size=None, manifest=None):
|
||||
viewport_size=None, dpi=None, manifest=None):
|
||||
URLManifestItem.__init__(self, source_file, url, url_base=url_base, manifest=manifest)
|
||||
for _, ref_type in references:
|
||||
if ref_type not in ["==", "!="]:
|
||||
|
@ -138,13 +138,14 @@ class RefTest(URLManifestItem):
|
|||
self.references = tuple(references)
|
||||
self.timeout = timeout
|
||||
self.viewport_size = viewport_size
|
||||
self.dpi = dpi
|
||||
|
||||
@property
|
||||
def is_reference(self):
|
||||
return self.source_file.name_is_reference
|
||||
|
||||
def meta_key(self):
|
||||
return (self.timeout, self.viewport_size)
|
||||
return (self.timeout, self.viewport_size, self.dpi)
|
||||
|
||||
def to_json(self):
|
||||
rv = URLManifestItem.to_json(self)
|
||||
|
@ -153,6 +154,8 @@ class RefTest(URLManifestItem):
|
|||
rv["timeout"] = self.timeout
|
||||
if self.viewport_size is not None:
|
||||
rv["viewport_size"] = self.viewport_size
|
||||
if self.dpi is not None:
|
||||
rv["dpi"] = self.dpi
|
||||
return rv
|
||||
|
||||
@classmethod
|
||||
|
@ -165,6 +168,7 @@ class RefTest(URLManifestItem):
|
|||
url_base=manifest.url_base,
|
||||
timeout=obj.get("timeout"),
|
||||
viewport_size=obj.get("viewport_size"),
|
||||
dpi=obj.get("dpi"),
|
||||
manifest=manifest)
|
||||
|
||||
|
||||
|
|
|
@ -197,6 +197,23 @@ class SourceFile(object):
|
|||
|
||||
return self.viewport_nodes[0].attrib.get("content", None)
|
||||
|
||||
@cached_property
|
||||
def dpi_nodes(self):
|
||||
"""List of ElementTree Elements corresponding to nodes in a test that
|
||||
specify device pixel ratios"""
|
||||
return self.root.findall(".//{http://www.w3.org/1999/xhtml}meta[@name='device-pixel-ratio']")
|
||||
|
||||
@cached_property
|
||||
def dpi(self):
|
||||
"""The device pixel ratio of a test or reference file"""
|
||||
if not self.root:
|
||||
return None
|
||||
|
||||
if not self.dpi_nodes:
|
||||
return None
|
||||
|
||||
return self.dpi_nodes[0].attrib.get("content", None)
|
||||
|
||||
@cached_property
|
||||
def testharness_nodes(self):
|
||||
"""List of ElementTree Elements corresponding to nodes representing a
|
||||
|
@ -288,7 +305,8 @@ class SourceFile(object):
|
|||
rv.append(TestharnessTest(self, url, timeout=self.timeout))
|
||||
|
||||
elif self.content_is_ref_node:
|
||||
rv = [RefTest(self, self.url, self.references, timeout=self.timeout, viewport_size=self.viewport_size)]
|
||||
rv = [RefTest(self, self.url, self.references, timeout=self.timeout,
|
||||
viewport_size=self.viewport_size, dpi=self.dpi)]
|
||||
|
||||
else:
|
||||
# If nothing else it's a helper file, which we don't have a specific type for
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue