Add support for viewport size adjustments in wptrunner.

This commit is contained in:
Ms2ger 2015-12-21 15:42:16 +01:00
parent ee6c5ae2fb
commit 1619a908b3
8 changed files with 62 additions and 22 deletions

View file

@ -130,26 +130,29 @@ class RefTest(URLManifestItem):
item_type = "reftest"
def __init__(self, source_file, url, references, url_base="/", timeout=None,
manifest=None):
viewport_size=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 ["==", "!="]:
raise ValueError, "Unrecognised ref_type %s" % ref_type
self.references = tuple(references)
self.timeout = timeout
self.viewport_size = viewport_size
@property
def is_reference(self):
return self.source_file.name_is_reference
def meta_key(self):
return (self.timeout,)
return (self.timeout, self.viewport_size)
def to_json(self):
rv = URLManifestItem.to_json(self)
rv["references"] = self.references
if self.timeout is not None:
rv["timeout"] = self.timeout
if self.viewport_size is not None:
rv["viewport_size"] = self.viewport_size
return rv
@classmethod
@ -161,6 +164,7 @@ class RefTest(URLManifestItem):
obj["references"],
url_base=manifest.url_base,
timeout=obj.get("timeout"),
viewport_size=obj.get("viewport_size"),
manifest=manifest)

View file

@ -180,6 +180,23 @@ class SourceFile(object):
if timeout_str and timeout_str.lower() == "long":
return timeout_str
@cached_property
def viewport_nodes(self):
"""List of ElementTree Elements corresponding to nodes in a test that
specify viewport sizes"""
return self.root.findall(".//{http://www.w3.org/1999/xhtml}meta[@name='viewport-size']")
@cached_property
def viewport_size(self):
"""The viewport size of a test or reference file"""
if not self.root:
return None
if not self.viewport_nodes:
return None
return self.viewport_nodes[0].attrib.get("content", None)
@cached_property
def testharness_nodes(self):
"""List of ElementTree Elements corresponding to nodes representing a
@ -271,7 +288,7 @@ 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)]
rv = [RefTest(self, self.url, self.references, timeout=self.timeout, viewport_size=self.viewport_size)]
else:
# If nothing else it's a helper file, which we don't have a specific type for