Skip to content

Commit

Permalink
Rename to require_webdriver_bidi + add .js test
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Oct 17, 2024
1 parent e612560 commit 209f045
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
disabled:
if product != "chrome": @True
2 changes: 1 addition & 1 deletion infrastructure/webdriver/bidi/subscription.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="require-bidi" content="true" />
<meta name="require_webdriver_bidi" content="true" />
<title>Test console log are present</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Expand Down
23 changes: 23 additions & 0 deletions infrastructure/webdriver/bidi/subscription.window.js
Original file line number Diff line number Diff line change
@@ -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");
10 changes: 5 additions & 5 deletions tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions tools/lint/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<meta
name="require-bidi"...>` element
name="require_webdriver_bidi"...>` element
"""


class InvalidRequireBidi(Rule):
name = "INVALID-REQUIRE-BIDI"
name = "INVALID-REQUIRE-WEBDRIVER-BIDI"
description = collapse("""
Test file with `<meta name='require-bidi'...>` element that has a `content`
Test file with `<meta name='require_webdriver_bidi'...>` 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`"
Expand Down
8 changes: 4 additions & 4 deletions tools/manifest/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions tools/manifest/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
))
Expand Down
6 changes: 3 additions & 3 deletions tools/manifest/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,16 @@ 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)
json_str = m.to_json()
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
Expand Down
54 changes: 27 additions & 27 deletions tools/manifest/tests/test_sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,22 +962,22 @@ 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:
contents = b"""importScripts('/resources/testharness.js')
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
Expand All @@ -986,22 +986,22 @@ 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:
contents = b"""importScripts('/resources/testharness.js')
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
Expand All @@ -1010,22 +1010,22 @@ 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:
contents = b"""importScripts('/resources/testharness.js')
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
Expand All @@ -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"<meta name=require-bidi content={require_bidi_value} />".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"<meta name=require_webdriver_bidi content={require_webdriver_bidi_value} />".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
12 changes: 6 additions & 6 deletions tools/wptrunner/wptrunner/browsers/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}


Expand Down
4 changes: 2 additions & 2 deletions tools/wptrunner/wptrunner/executors/executorchrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tools/wptrunner/wptrunner/wpttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ 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
self._inherit_metadata = inherit_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,
Expand Down Expand Up @@ -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
Expand All @@ -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 []
Expand All @@ -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,
Expand Down

0 comments on commit 209f045

Please sign in to comment.