Support device-pixel-ratio in wpt reftests.

This commit is contained in:
Ms2ger 2016-01-12 12:07:19 +01:00
parent 6beebd3b4f
commit 198ee0f2c6
10 changed files with 72 additions and 19 deletions

View file

@ -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)

View file

@ -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