From 209f04544bf0cefa4ed5f62d3c42653fc89f9d87 Mon Sep 17 00:00:00 2001 From: Maksim Sadym Date: Wed, 16 Oct 2024 12:40:46 +0200 Subject: [PATCH] Rename to `require_webdriver_bidi` + add .js test --- .../webdriver/bidi/subscription.window.js.ini | 2 + .../webdriver/bidi/subscription.html | 2 +- .../webdriver/bidi/subscription.window.js | 23 ++++++++ tools/lint/lint.py | 10 ++-- tools/lint/rules.py | 10 ++-- tools/manifest/item.py | 8 +-- tools/manifest/sourcefile.py | 20 +++---- tools/manifest/tests/test_manifest.py | 6 +-- tools/manifest/tests/test_sourcefile.py | 54 +++++++++---------- tools/wptrunner/wptrunner/browsers/chrome.py | 12 ++--- .../wptrunner/executors/executorchrome.py | 4 +- tools/wptrunner/wptrunner/wpttest.py | 12 ++--- 12 files changed, 94 insertions(+), 69 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..1a5ac47c67d942 --- /dev/null +++ b/infrastructure/metadata/infrastructure/webdriver/bidi/subscription.window.js.ini @@ -0,0 +1,2 @@ +disabled: + if product != "chrome": @True 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..b70d8c9c6f378c 100644 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -442,13 +442,13 @@ 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..63ae76be5c61ca 100644 --- a/tools/manifest/sourcefile.py +++ b/tools/manifest/sourcefile.py @@ -440,11 +440,11 @@ 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 +500,18 @@ 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 +988,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 +1007,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 +1024,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 +1052,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..05bf1415173e27 100644 --- a/tools/manifest/tests/test_manifest.py +++ b/tools/manifest/tests/test_manifest.py @@ -294,8 +294,8 @@ 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): m.update(tree) @@ -303,7 +303,7 @@ def test_update_from_json_modified(): assert json_str == { 'items': {'testharness': {'test1': [ "1"*40, - (None, {'timeout': 'long', 'pac': 'proxy.pac', 'require_bidi': 'true'}) + (None, {'timeout': 'long', 'pac': 'proxy.pac', 'require_webdriver_bidi': 'true'}) ]}}, 'url_base': '/', 'version': 8 diff --git a/tools/manifest/tests/test_sourcefile.py b/tools/manifest/tests/test_sourcefile.py index 14ed87b52c6cea..46f4ae4c3611d6 100644 --- a/tools/manifest/tests/test_sourcefile.py +++ b/tools/manifest/tests/test_sourcefile.py @@ -962,13 +962,13 @@ 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 +976,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 +986,13 @@ 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 +1000,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 +1010,13 @@ 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 +1024,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 +1034,17 @@ 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/browsers/chrome.py b/tools/wptrunner/wptrunner/browsers/chrome.py index 310b5a02d4820c..20a6455ec10946 100644 --- a/tools/wptrunner/wptrunner/browsers/chrome.py +++ b/tools/wptrunner/wptrunner/browsers/chrome.py @@ -216,7 +216,7 @@ def __init__(self, super().__init__(logger, **kwargs) self._leak_check = leak_check self._actual_port = None - self._require_bidi = None + self._require_webdriver_bidi = None def restart_on_test_type_change(self, new_test_type: str, old_test_type: str) -> bool: # Restart the test runner when switch from/to wdspec tests. Wdspec test @@ -266,16 +266,16 @@ def executor_browser(self): return browser_cls, {**browser_kwargs, "leak_check": self._leak_check} @property - def require_bidi(self) -> Optional[bool]: - return self._require_bidi + def require_webdriver_bidi(self) -> Optional[bool]: + return self._require_webdriver_bidi def settings(self, test: Test) -> BrowserSettings: - """ Required to store `require_bidi` in browser settings.""" + """ Required to store `require_webdriver_bidi` in browser settings.""" settings = super().settings(test) - self._require_bidi = test.require_bidi + self._require_webdriver_bidi = test.require_webdriver_bidi return { **settings, - "require_bidi": self._require_bidi + "require_webdriver_bidi": self._require_webdriver_bidi } diff --git a/tools/wptrunner/wptrunner/executors/executorchrome.py b/tools/wptrunner/wptrunner/executors/executorchrome.py index a0a44e636ade96..0688c72b3661e3 100644 --- a/tools/wptrunner/wptrunner/executors/executorchrome.py +++ b/tools/wptrunner/wptrunner/executors/executorchrome.py @@ -246,9 +246,9 @@ class ChromeDriverRefTestExecutor(WebDriverRefTestExecutor, _SanitizerMixin): # class ChromeDriverTestharnessExecutor(WebDriverTestharnessExecutor, _SanitizerMixin): # type: ignore def __init__(self, *args, reuse_window=False, **kwargs): - require_bidi = kwargs.get("browser_settings", {}).get("require_bidi", + require_webdriver_bidi = kwargs.get("browser_settings", {}).get("require_webdriver_bidi", None) - if require_bidi == 'true': + if require_webdriver_bidi == 'true': self.protocol_cls = ChromeDriverBidiProtocol else: self.protocol_cls = ChromeDriverProtocol diff --git a/tools/wptrunner/wptrunner/wpttest.py b/tools/wptrunner/wptrunner/wpttest.py index 02f88676ff9705..3e70939d32cceb 100644 --- a/tools/wptrunner/wptrunner/wpttest.py +++ b/tools/wptrunner/wptrunner/wpttest.py @@ -216,7 +216,7 @@ class Test(ABC): 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): + 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 +224,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, @@ -483,9 +483,9 @@ class TestharnessTest(Test): 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): + 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_bidi) + path, protocol, subdomain, pac, require_webdriver_bidi) self.testdriver = testdriver self.jsshell = jsshell @@ -495,7 +495,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 +508,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,