Skip to content

Commit

Permalink
Add support for JS shell tests to the manifest code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed May 8, 2018
1 parent 41c88bf commit 8b10545
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
6 changes: 5 additions & 1 deletion tools/manifest/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ def from_json(cls, manifest, tests_root, path, obj, source_files=None):
class TestharnessTest(URLManifestItem):
item_type = "testharness"

def __init__(self, source_file, url, url_base="/", timeout=None, testdriver=False, manifest=None):
def __init__(self, source_file, url, url_base="/", timeout=None, testdriver=False, jsshell=False, manifest=None):
URLManifestItem.__init__(self, source_file, url, url_base=url_base, manifest=manifest)
self.timeout = timeout
self.testdriver = testdriver
self.jsshell = jsshell

def meta_key(self):
return (self.timeout, self.testdriver)
Expand All @@ -116,6 +117,8 @@ def to_json(self):
rv[-1]["timeout"] = self.timeout
if self.testdriver:
rv[-1]["testdriver"] = self.testdriver
if self.jsshell:
rv[-1]["jsshell"] = True
return rv

@classmethod
Expand All @@ -128,6 +131,7 @@ def from_json(cls, manifest, tests_root, path, obj, source_files=None):
url_base=manifest.url_base,
timeout=extras.get("timeout"),
testdriver=bool(extras.get("testdriver")),
jsshell=bool(extras.get("jsshell")),
manifest=manifest)


Expand Down
14 changes: 8 additions & 6 deletions tools/manifest/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def read_script_metadata(f, regexp):
b"serviceworker": {"force_https": True},
b"sharedworker": {},
b"dedicatedworker": {"suffix": ".any.worker.html"},
b"worker": {"longhand": {b"dedicatedworker", b"sharedworker", b"serviceworker"}}
b"worker": {"longhand": {b"dedicatedworker", b"sharedworker", b"serviceworker"}},
b"jsshell": {"suffix": ".any.js"},
}


Expand Down Expand Up @@ -100,8 +101,9 @@ def parse_variants(value):

def global_suffixes(value):
"""
Yields the relevant filename suffixes (strings) for the variants defined by
the given comma-separated value.
Yields tuples of the relevant filename suffix (a string) and whether the
variant is intended to run in a JS shell, for the variants defined by the
given comma-separated value.
"""
assert isinstance(value, binary_type), value

Expand All @@ -113,7 +115,7 @@ def global_suffixes(value):
suffix = variant.get("suffix", ".any.%s.html" % global_type.decode("utf-8"))
if variant.get("force_https", False):
suffix = ".https" + suffix
rv.add(suffix)
rv.add((suffix, global_type == b"jsshell"))

return rv

Expand Down Expand Up @@ -605,8 +607,8 @@ def manifest_items(self):
break

tests = [
TestharnessTest(self, global_variant_url(self.url, suffix) + variant, timeout=self.timeout)
for suffix in sorted(global_suffixes(globals))
TestharnessTest(self, global_variant_url(self.url, suffix) + variant, timeout=self.timeout, jsshell=jsshell)
for (suffix, jsshell) in sorted(global_suffixes(globals))
for variant in self.test_variants
]
rv = TestharnessTest.item_type, tests
Expand Down
31 changes: 31 additions & 0 deletions tools/manifest/tests/test_sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,37 @@ def test_multi_global_with_custom_globals(input, expected):

for item, url in zip(items, expected_urls):
assert item.url == url
assert item.jsshell is False
assert item.timeout is None


def test_multi_global_with_jsshell_globals():
contents = b"""// META: global=jsshell
test()"""

s = create("html/test.any.js", contents=contents)
assert not s.name_is_non_test
assert not s.name_is_manual
assert not s.name_is_visual
assert s.name_is_multi_global
assert not s.name_is_worker
assert not s.name_is_reference

assert not s.content_is_testharness

item_type, items = s.manifest_items()
assert item_type == "testharness"

expected = [
("/html/test.any.html", False),
("/html/test.any.js", True),
("/html/test.any.worker.html", False),
]
assert len(items) == len(expected)

for item, (url, jsshell) in zip(items, expected):
assert item.url == url
assert item.jsshell == jsshell
assert item.timeout is None


Expand Down
1 change: 1 addition & 0 deletions tools/wptrunner/wptrunner/executors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class TestExecutor(object):
test_type = None
convert_result = None
supports_testdriver = False
supports_jsshell = False

def __init__(self, browser, server_config, timeout_multiplier=1,
debug_info=None, **kwargs):
Expand Down
6 changes: 6 additions & 0 deletions tools/wptrunner/wptrunner/wptrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ def run_tests(config, test_paths, product, **kwargs):
if test.testdriver and not executor_cls.supports_testdriver:
logger.test_start(test.id)
logger.test_end(test.id, status="SKIP")
elif test.jsshell and not executor_cls.supports_jsshell:
# We expect that tests for JavaScript shells
# will not be run along with tests that run in
# a full web browser, so we silently skip them
# here.
pass
else:
run_tests["testharness"].append(test)
else:
Expand Down
8 changes: 6 additions & 2 deletions tools/wptrunner/wptrunner/wpttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,29 @@ class TestharnessTest(Test):
test_type = "testharness"

def __init__(self, tests_root, url, inherit_metadata, test_metadata,
timeout=None, path=None, protocol="http", testdriver=False):
timeout=None, path=None, protocol="http", testdriver=False,
jsshell=False):
Test.__init__(self, tests_root, url, inherit_metadata, test_metadata, timeout,
path, protocol)

self.testdriver = testdriver
self.jsshell = jsshell

@classmethod
def from_manifest(cls, manifest_item, inherit_metadata, test_metadata):
timeout = cls.long_timeout if manifest_item.timeout == "long" else cls.default_timeout
protocol = "https" if hasattr(manifest_item, "https") and manifest_item.https else "http"
testdriver = manifest_item.testdriver if hasattr(manifest_item, "testdriver") else False
jsshell = manifest_item.jsshell if hasattr(manifest_item, "jsshell") else False
return cls(manifest_item.source_file.tests_root,
manifest_item.url,
inherit_metadata,
test_metadata,
timeout=timeout,
path=manifest_item.source_file.path,
protocol=protocol,
testdriver=testdriver)
testdriver=testdriver,
jsshell=jsshell)

@property
def id(self):
Expand Down

0 comments on commit 8b10545

Please sign in to comment.