From 9b130f356c6f76da93c3a4c5ba99a597b806e5b1 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 16 Oct 2024 12:50:33 +0200 Subject: [PATCH] Rename to `require_webdriver_bidi` + add `subscription.window.js` --- .../webdriver/bidi/subscription.window.js.ini | 1 + .../webdriver/bidi/subscription.html | 2 +- .../webdriver/bidi/subscription.window.js | 23 ++++++++ tools/lint/lint.py | 12 ++-- tools/lint/rules.py | 10 ++-- tools/manifest/item.py | 8 +-- tools/manifest/sourcefile.py | 22 +++---- tools/manifest/tests/test_manifest.py | 15 +++-- tools/manifest/tests/test_sourcefile.py | 58 ++++++++++--------- tools/wptrunner/wptrunner/wpttest.py | 25 ++++---- 10 files changed, 109 insertions(+), 67 deletions(-) create mode 100644 infrastructure/metadata/infrastructure/webdriver/bidi/subscription.window.js.ini create mode 100644 infrastructure/webdriver/bidi/subscription.window.js diff --git a/infrastructure/metadata/infrastructure/webdriver/bidi/subscription.window.js.ini b/infrastructure/metadata/infrastructure/webdriver/bidi/subscription.window.js.ini new file mode 100644 index 00000000000000..7c3127d167a740 --- /dev/null +++ b/infrastructure/metadata/infrastructure/webdriver/bidi/subscription.window.js.ini @@ -0,0 +1 @@ +disabled: https://github.com/web-platform-tests/wpt/issues/47544 diff --git a/infrastructure/webdriver/bidi/subscription.html b/infrastructure/webdriver/bidi/subscription.html index 36a82f70cd7814..134d4237cfcb9a 100644 --- a/infrastructure/webdriver/bidi/subscription.html +++ b/infrastructure/webdriver/bidi/subscription.html @@ -1,6 +1,6 @@ - + Test console log are present diff --git a/infrastructure/webdriver/bidi/subscription.window.js b/infrastructure/webdriver/bidi/subscription.window.js new file mode 100644 index 00000000000000..2fd3c383dd853c --- /dev/null +++ b/infrastructure/webdriver/bidi/subscription.window.js @@ -0,0 +1,23 @@ +// META: title=Test console log are present +// META: require_webdriver_bidi=true +// META: script=/resources/testdriver.js + +'use strict'; + +promise_test(async () => { + const some_message = "SOME MESSAGE"; + // Subscribe to `log.entryAdded` BiDi events. This will not add a listener to the page. + await test_driver.bidi.log.entry_added.subscribe(); + // Add a listener for the log.entryAdded event. This will not subscribe to the event, so the subscription is + // required before. The cleanup is done automatically after the test is finished. + const log_entry_promise = test_driver.bidi.log.entry_added.once(); + // Emit a console.log message. + // Note: Lint rule is disabled in `lint.ignore` file. + console.log(some_message); + // Wait for the log.entryAdded event to be received. + const event = await log_entry_promise; + // Assert the log.entryAdded event has the expected message. + assert_equals(event.args.length, 1); + const event_message = event.args[0]; + assert_equals(event_message.value, some_message); +}, "Assert testdriver can subscribe and receive events"); diff --git a/tools/lint/lint.py b/tools/lint/lint.py index e6e0ba1d8bd59a..573fbffd58a8fe 100644 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -442,13 +442,15 @@ def check_parsed(repo_root: Text, path: Text, f: IO[bytes]) -> List[rules.Error] if timeout_value != "long": errors.append(rules.InvalidTimeout.error(path, (timeout_value,))) - if len(source_file.require_bidi_nodes) > 1: + if len(source_file.require_webdriver_bidi_nodes) > 1: errors.append(rules.MultipleRequireBidi.error(path)) - for timeout_node in source_file.require_bidi_nodes: - require_bidi_value = timeout_node.attrib.get("content", "").lower() - if require_bidi_value != "true" and require_bidi_value != "false": - errors.append(rules.InvalidRequireBidi.error(path, (require_bidi_value,))) + for timeout_node in source_file.require_webdriver_bidi_nodes: + require_webdriver_bidi_value = timeout_node.attrib.get("content", + "").lower() + if require_webdriver_bidi_value != "true" and require_webdriver_bidi_value != "false": + errors.append(rules.InvalidRequireBidi.error(path, ( + require_webdriver_bidi_value,))) if source_file.content_is_ref_node or source_file.content_is_testharness: for element in source_file.variant_nodes: diff --git a/tools/lint/rules.py b/tools/lint/rules.py index 1e1eb3a529fb7c..6325e48c558d6e 100644 --- a/tools/lint/rules.py +++ b/tools/lint/rules.py @@ -153,18 +153,18 @@ class InvalidTimeout(Rule): class MultipleRequireBidi(Rule): - name = "MULTIPLE-REQUIRE-BIDI" - description = "More than one meta name='require-bidi'" + name = "MULTIPLE-REQUIRE-WEBDRIVER-BIDI" + description = "More than one meta name='require_webdriver_bidi'" to_fix = """ ensure each test file has only one instance of a `` element + name="require_webdriver_bidi"...>` element """ class InvalidRequireBidi(Rule): - name = "INVALID-REQUIRE-BIDI" + name = "INVALID-REQUIRE-WEBDRIVER-BIDI" description = collapse(""" - Test file with `` element that has a `content` + Test file with `` element that has a `content` attribute whose value is not a boolean: %s """) to_fix = "replace the value of the `content` attribute with `true` or `false`" diff --git a/tools/manifest/item.py b/tools/manifest/item.py index 84b523765191f0..18e2805f02d8f7 100644 --- a/tools/manifest/item.py +++ b/tools/manifest/item.py @@ -166,8 +166,8 @@ def pac(self) -> Optional[Text]: return self._extras.get("pac") @property - def require_bidi(self) -> Optional[Text]: - return self._extras.get("require_bidi") + def require_webdriver_bidi(self) -> Optional[Text]: + return self._extras.get("require_webdriver_bidi") @property def testdriver(self) -> Optional[Text]: @@ -187,8 +187,8 @@ def to_json(self) -> Tuple[Optional[Text], Dict[Text, Any]]: rv[-1]["timeout"] = self.timeout if self.pac is not None: rv[-1]["pac"] = self.pac - if self.require_bidi is not None: - rv[-1]["require_bidi"] = self.require_bidi + if self.require_webdriver_bidi is not None: + rv[-1]["require_webdriver_bidi"] = self.require_webdriver_bidi if self.testdriver: rv[-1]["testdriver"] = self.testdriver if self.jsshell: diff --git a/tools/manifest/sourcefile.py b/tools/manifest/sourcefile.py index 9bc80c7a3db045..03ff6bb1b601ff 100644 --- a/tools/manifest/sourcefile.py +++ b/tools/manifest/sourcefile.py @@ -440,11 +440,12 @@ def timeout_nodes(self) -> List[ElementTree.Element]: return self.root.findall(".//{http://www.w3.org/1999/xhtml}meta[@name='timeout']") @cached_property - def require_bidi_nodes(self) -> List[ElementTree.Element]: + def require_webdriver_bidi_nodes(self) -> List[ElementTree.Element]: """List of ElementTree Elements corresponding to nodes in a test that specify timeouts""" assert self.root is not None - return self.root.findall(".//{http://www.w3.org/1999/xhtml}meta[@name='require-bidi']") + return self.root.findall( + ".//{http://www.w3.org/1999/xhtml}meta[@name='require_webdriver_bidi']") @cached_property def pac_nodes(self) -> List[ElementTree.Element]: @@ -500,18 +501,19 @@ def pac(self) -> Optional[Text]: return None @cached_property - def require_bidi(self) -> Optional[Text]: + def require_webdriver_bidi(self) -> Optional[Text]: """Flag indicating if BiDi functionality is required for the given test""" if self.script_metadata: for (meta, content) in self.script_metadata: - if meta == 'require_bidi': + if meta == 'require_webdriver_bidi': return content if self.root is None: return None - if self.require_bidi_nodes: - return self.require_bidi_nodes[0].attrib.get("content", None) + if self.require_webdriver_bidi_nodes: + return self.require_webdriver_bidi_nodes[0].attrib.get("content", + None) return None @@ -988,7 +990,7 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]: global_variant_url(self.rel_url, suffix) + variant, timeout=self.timeout, pac=self.pac, - require_bidi=self.require_bidi, + require_webdriver_bidi=self.require_webdriver_bidi, jsshell=jsshell, script_metadata=self.script_metadata ) @@ -1007,7 +1009,7 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]: test_url + variant, timeout=self.timeout, pac=self.pac, - require_bidi=self.require_bidi, + require_webdriver_bidi=self.require_webdriver_bidi, script_metadata=self.script_metadata ) for variant in self.test_variants @@ -1024,7 +1026,7 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]: test_url + variant, timeout=self.timeout, pac=self.pac, - require_bidi=self.require_bidi, + require_webdriver_bidi=self.require_webdriver_bidi, script_metadata=self.script_metadata ) for variant in self.test_variants @@ -1052,7 +1054,7 @@ def manifest_items(self) -> Tuple[Text, List[ManifestItem]]: url, timeout=self.timeout, pac=self.pac, - require_bidi=self.require_bidi, + require_webdriver_bidi=self.require_webdriver_bidi, testdriver=testdriver, script_metadata=self.script_metadata )) diff --git a/tools/manifest/tests/test_manifest.py b/tools/manifest/tests/test_manifest.py index c3cb03aa7724fa..3104eb023833e7 100644 --- a/tools/manifest/tests/test_manifest.py +++ b/tools/manifest/tests/test_manifest.py @@ -294,21 +294,26 @@ def test_update_from_json_modified(): # Reload it from JSON m = manifest.Manifest.from_json("/", json_str) - # Update timeout, pac and require_bidi - s2 = SourceFileWithTest("test1", "1"*40, item.TestharnessTest, timeout="long", pac="proxy.pac", require_bidi="true") + # Update timeout, pac and require_webdriver_bidi + s2 = SourceFileWithTest("test1", "1" * 40, item.TestharnessTest, + timeout="long", pac="proxy.pac", + require_webdriver_bidi="true") tree, sourcefile_mock = tree_and_sourcefile_mocks([(s2, None, True)]) - with mock.patch("tools.manifest.manifest.SourceFile", side_effect=sourcefile_mock): + with mock.patch("tools.manifest.manifest.SourceFile", + side_effect=sourcefile_mock): m.update(tree) json_str = m.to_json() assert json_str == { 'items': {'testharness': {'test1': [ - "1"*40, - (None, {'timeout': 'long', 'pac': 'proxy.pac', 'require_bidi': 'true'}) + "1" * 40, + (None, {'timeout': 'long', 'pac': 'proxy.pac', + 'require_webdriver_bidi': 'true'}) ]}}, 'url_base': '/', 'version': 8 } + def test_manifest_spec_to_json(): m = manifest.Manifest("") diff --git a/tools/manifest/tests/test_sourcefile.py b/tools/manifest/tests/test_sourcefile.py index 14ed87b52c6cea..6c3615aa1617b6 100644 --- a/tools/manifest/tests/test_sourcefile.py +++ b/tools/manifest/tests/test_sourcefile.py @@ -962,13 +962,14 @@ def test_hash(): assert "b45ef6fec89518d314f546fd6c3025367b721684" == s.hash -REQUIRE_BIDI_VALUES = [None, "true", "false", "SOME_NONSENSE"] +REQUIRE_WEBDRIVER_BIDI_VALUES = [None, "true", "false", "SOME_NONSENSE"] -@pytest.mark.parametrize("require_bidi_value", REQUIRE_BIDI_VALUES) -def test_worker_require_bidi(require_bidi_value): - if require_bidi_value is not None: - contents = f"""// META: require_bidi={require_bidi_value} +@pytest.mark.parametrize("require_webdriver_bidi_value", + REQUIRE_WEBDRIVER_BIDI_VALUES) +def test_worker_require_webdriver_bidi(require_webdriver_bidi_value): + if require_webdriver_bidi_value is not None: + contents = f"""// META: require_webdriver_bidi={require_webdriver_bidi_value} importScripts('/resources/testharness.js') test()""".encode("utf-8") else: @@ -976,8 +977,8 @@ def test_worker_require_bidi(require_bidi_value): test()""" metadata = list(read_script_metadata(BytesIO(contents), js_meta_re)) - assert metadata == ([("require_bidi", - require_bidi_value)] if require_bidi_value is not None else []) + assert metadata == ([("require_webdriver_bidi", + require_webdriver_bidi_value)] if require_webdriver_bidi_value is not None else []) s = create("html/test.worker.js", contents=contents) assert s.name_is_worker @@ -986,13 +987,14 @@ def test_worker_require_bidi(require_bidi_value): assert item_type == "testharness" for item in items: - assert item.require_bidi == require_bidi_value + assert item.require_webdriver_bidi == require_webdriver_bidi_value -@pytest.mark.parametrize("require_bidi_value", REQUIRE_BIDI_VALUES) -def test_window_require_bidi(require_bidi_value): - if require_bidi_value is not None: - contents = f"""// META: require_bidi={require_bidi_value} +@pytest.mark.parametrize("require_webdriver_bidi_value", + REQUIRE_WEBDRIVER_BIDI_VALUES) +def test_window_require_webdriver_bidi(require_webdriver_bidi_value): + if require_webdriver_bidi_value is not None: + contents = f"""// META: require_webdriver_bidi={require_webdriver_bidi_value} importScripts('/resources/testharness.js') test()""".encode("utf-8") else: @@ -1000,8 +1002,8 @@ def test_window_require_bidi(require_bidi_value): test()""" metadata = list(read_script_metadata(BytesIO(contents), js_meta_re)) - assert metadata == ([("require_bidi", - require_bidi_value)] if require_bidi_value is not None else []) + assert metadata == ([("require_webdriver_bidi", + require_webdriver_bidi_value)] if require_webdriver_bidi_value is not None else []) s = create("html/test.window.js", contents=contents) assert s.name_is_window @@ -1010,13 +1012,14 @@ def test_window_require_bidi(require_bidi_value): assert item_type == "testharness" for item in items: - assert item.require_bidi == require_bidi_value + assert item.require_webdriver_bidi == require_webdriver_bidi_value -@pytest.mark.parametrize("require_bidi_value", REQUIRE_BIDI_VALUES) -def test_multi_global_require_bidi(require_bidi_value): - if require_bidi_value is not None: - contents = f"""// META: require_bidi={require_bidi_value} +@pytest.mark.parametrize("require_webdriver_bidi_value", + REQUIRE_WEBDRIVER_BIDI_VALUES) +def test_multi_global_require_webdriver_bidi(require_webdriver_bidi_value): + if require_webdriver_bidi_value is not None: + contents = f"""// META: require_webdriver_bidi={require_webdriver_bidi_value} importScripts('/resources/testharness.js') test()""".encode("utf-8") else: @@ -1024,8 +1027,8 @@ def test_multi_global_require_bidi(require_bidi_value): test()""" metadata = list(read_script_metadata(BytesIO(contents), js_meta_re)) - assert metadata == ([("require_bidi", - require_bidi_value)] if require_bidi_value is not None else []) + assert metadata == ([("require_webdriver_bidi", + require_webdriver_bidi_value)] if require_webdriver_bidi_value is not None else []) s = create("html/test.any.js", contents=contents) assert s.name_is_multi_global @@ -1034,17 +1037,18 @@ def test_multi_global_require_bidi(require_bidi_value): assert item_type == "testharness" for item in items: - assert item.require_bidi == require_bidi_value + assert item.require_webdriver_bidi == require_webdriver_bidi_value -@pytest.mark.parametrize("require_bidi_value", REQUIRE_BIDI_VALUES) -def test_html_require_bidi(require_bidi_value): - if require_bidi_value is not None: - content = f"".encode( +@pytest.mark.parametrize("require_webdriver_bidi_value", + REQUIRE_WEBDRIVER_BIDI_VALUES) +def test_html_require_webdriver_bidi(require_webdriver_bidi_value): + if require_webdriver_bidi_value is not None: + content = f"".encode( "utf-8") else: content = b"" s = create("test.html", content) - assert s.require_bidi == require_bidi_value + assert s.require_webdriver_bidi == require_webdriver_bidi_value diff --git a/tools/wptrunner/wptrunner/wpttest.py b/tools/wptrunner/wptrunner/wpttest.py index 02f88676ff9705..1b714ea5be42e5 100644 --- a/tools/wptrunner/wptrunner/wpttest.py +++ b/tools/wptrunner/wptrunner/wpttest.py @@ -215,8 +215,10 @@ class Test(ABC): default_timeout = 10 # seconds long_timeout = 60 # seconds - def __init__(self, url_base, tests_root, url, inherit_metadata, test_metadata, - timeout=None, path=None, protocol="http", subdomain=False, pac=None, require_bidi=None): + def __init__(self, url_base, tests_root, url, inherit_metadata, + test_metadata, + timeout=None, path=None, protocol="http", subdomain=False, pac=None, + require_webdriver_bidi=None): self.url_base = url_base self.tests_root = tests_root self.url = url @@ -224,7 +226,7 @@ def __init__(self, url_base, tests_root, url, inherit_metadata, test_metadata, self._test_metadata = test_metadata self.timeout = timeout if timeout is not None else self.default_timeout self.path = path - self.require_bidi = require_bidi + self.require_webdriver_bidi = require_webdriver_bidi self.subdomain = subdomain self.environment = {"url_base": url_base, "protocol": protocol, @@ -481,11 +483,14 @@ class TestharnessTest(Test): subtest_result_cls = TestharnessSubtestResult test_type = "testharness" - def __init__(self, url_base, tests_root, url, inherit_metadata, test_metadata, - timeout=None, path=None, protocol="http", testdriver=False, - jsshell=False, scripts=None, subdomain=False, pac=None, require_bidi=None): - Test.__init__(self, url_base, tests_root, url, inherit_metadata, test_metadata, timeout, - path, protocol, subdomain, pac, require_bidi) + def __init__(self, url_base, tests_root, url, inherit_metadata, + test_metadata, + timeout=None, path=None, protocol="http", testdriver=False, + jsshell=False, scripts=None, subdomain=False, pac=None, + require_webdriver_bidi=None): + Test.__init__(self, url_base, tests_root, url, inherit_metadata, + test_metadata, timeout, + path, protocol, subdomain, pac, require_webdriver_bidi) self.testdriver = testdriver self.jsshell = jsshell @@ -495,7 +500,7 @@ def __init__(self, url_base, tests_root, url, inherit_metadata, test_metadata, def from_manifest(cls, manifest_file, manifest_item, inherit_metadata, test_metadata): timeout = cls.long_timeout if manifest_item.timeout == "long" else cls.default_timeout pac = manifest_item.pac - require_bidi = manifest_item.require_bidi + require_webdriver_bidi = manifest_item.require_webdriver_bidi testdriver = manifest_item.testdriver if hasattr(manifest_item, "testdriver") else False jsshell = manifest_item.jsshell if hasattr(manifest_item, "jsshell") else False script_metadata = manifest_item.script_metadata or [] @@ -508,7 +513,7 @@ def from_manifest(cls, manifest_file, manifest_item, inherit_metadata, test_meta test_metadata, timeout=timeout, pac=pac, - require_bidi=require_bidi, + require_webdriver_bidi=require_webdriver_bidi, path=os.path.join(manifest_file.tests_root, manifest_item.path), protocol=server_protocol(manifest_item), testdriver=testdriver,