From 8b105455a9b1fba8ca4cd7f973c565ca361278f5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 18 Apr 2018 17:30:08 +0200 Subject: [PATCH] Add support for JS shell tests to the manifest code. --- tools/manifest/item.py | 6 +++- tools/manifest/sourcefile.py | 14 ++++++---- tools/manifest/tests/test_sourcefile.py | 31 +++++++++++++++++++++ tools/wptrunner/wptrunner/executors/base.py | 1 + tools/wptrunner/wptrunner/wptrunner.py | 6 ++++ tools/wptrunner/wptrunner/wpttest.py | 8 ++++-- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/tools/manifest/item.py b/tools/manifest/item.py index 06ae3c236e6170..5a87d2820c4e11 100644 --- a/tools/manifest/item.py +++ b/tools/manifest/item.py @@ -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) @@ -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 @@ -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) diff --git a/tools/manifest/sourcefile.py b/tools/manifest/sourcefile.py index 0bf7e8b675cf8f..3b4abbc29bfa8b 100644 --- a/tools/manifest/sourcefile.py +++ b/tools/manifest/sourcefile.py @@ -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"}, } @@ -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 @@ -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 @@ -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 diff --git a/tools/manifest/tests/test_sourcefile.py b/tools/manifest/tests/test_sourcefile.py index 6e1059253dbd0f..c7093b8b69379e 100644 --- a/tools/manifest/tests/test_sourcefile.py +++ b/tools/manifest/tests/test_sourcefile.py @@ -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 diff --git a/tools/wptrunner/wptrunner/executors/base.py b/tools/wptrunner/wptrunner/executors/base.py index 3f6d1a249b704c..08030b3f5f9277 100644 --- a/tools/wptrunner/wptrunner/executors/base.py +++ b/tools/wptrunner/wptrunner/executors/base.py @@ -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): diff --git a/tools/wptrunner/wptrunner/wptrunner.py b/tools/wptrunner/wptrunner/wptrunner.py index 40863d8d862d4c..f68ba95bcc9cc4 100644 --- a/tools/wptrunner/wptrunner/wptrunner.py +++ b/tools/wptrunner/wptrunner/wptrunner.py @@ -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: diff --git a/tools/wptrunner/wptrunner/wpttest.py b/tools/wptrunner/wptrunner/wpttest.py index 0fb1bdd3e8e3d3..03c9163451c544 100644 --- a/tools/wptrunner/wptrunner/wpttest.py +++ b/tools/wptrunner/wptrunner/wpttest.py @@ -244,17 +244,20 @@ 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, @@ -262,7 +265,8 @@ def from_manifest(cls, manifest_item, inherit_metadata, test_metadata): timeout=timeout, path=manifest_item.source_file.path, protocol=protocol, - testdriver=testdriver) + testdriver=testdriver, + jsshell=jsshell) @property def id(self):