Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Dec 19, 2024
1 parent 985624e commit 5d34df3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/writing-tests/testdriver.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The api in `test_driver.bidi` provides access to the

### Markup ###

To use WebDriver BiDi, enable the `bidi` feature in `testdriver.js` by adding
To use WebDriver BiDi, enable the `bidi` feature in `testdriver.js` by adding the
`feature=bidi` query string parameter. Details are in [RFC 214: Add testdriver features](https://github.com/web-platform-tests/rfcs/blob/master/rfcs/testdriver-features.md).
```html
<script src="/resources/testdriver.js?feature=bidi"></script>
Expand Down
19 changes: 11 additions & 8 deletions tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,23 @@ def check_parsed(repo_root: Text, path: Text, f: IO[bytes]) -> List[rules.Error]
src = element.attrib["src"]

def is_path_correct(script: Text, src: Text) -> bool:
"""
If the `src` relevant to the `script`, check that the `src` is the
correct path for `script`.
:param script: the script name to check the `src` for.
:param src: the included path.
:return: if the `src` irrelevant to the `script`, or if the `src`
path is the correct path.
"""
if script == src:
# The src does not provide the full path.
return False

if "/%s" % script not in src:
# The src is not related to the script.
# The src is not relevant to the script.
return True

return src == "/resources/%s" % script or ("%s" % src).startswith(
"/resources/%s?" % script)
return ("%s" % src).startswith("/resources/%s" % script)

def is_query_string_correct(script: Text, src: Text,
allowed_query_string_params: Dict[str, List[str]]) -> bool:
Expand All @@ -553,7 +560,7 @@ def is_query_string_correct(script: Text, src: Text,
allowed parameter names and
values are lists of allowed
values for each parameter.
:return: if the query string does not contain any not-allowed
:return: if the query string is empty or contains only allowed
params.
"""
if not ("%s" % src).startswith("/resources/%s?" % script):
Expand All @@ -569,10 +576,6 @@ def is_query_string_correct(script: Text, src: Text,
return False

for param_name in query_string_params:
if ':' in param_name:
# Allow for vendor-specific query parameters.
continue

if param_name not in allowed_query_string_params:
return False

Expand Down
2 changes: 1 addition & 1 deletion tools/lint/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class TestdriverPath(Rule):

class TestdriverUnsupportedQueryParameter(Rule):
name = "TESTDRIVER-UNSUPPORTED-QUERY-PARAMETER"
description = "testdriver.js script seen with incorrect query parameters"
description = "testdriver.js script seen with unsupported query parameters"


class TestdriverVendorPath(Rule):
Expand Down
16 changes: 10 additions & 6 deletions tools/lint/tests/test_file_lints.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def test_testdriver_unsupported_query_param():
if kind in ["web-lax", "web-strict"]:
assert errors == [
("TESTDRIVER-UNSUPPORTED-QUERY-PARAMETER",
"testdriver.js script seen with incorrect query parameters",
"testdriver.js script seen with unsupported query parameters",
filename, None),
]
elif kind == "python":
Expand All @@ -532,7 +532,11 @@ def test_testdriver_vendor_query_param():
check_errors(errors)

if kind in ["web-lax", "web-strict"]:
assert errors == []
assert errors == [
('TESTDRIVER-UNSUPPORTED-QUERY-PARAMETER',
'testdriver.js script seen with unsupported query parameters',
filename, None)
]
elif kind == "python":
assert errors == [
("PARSE-FAILED", "Unable to parse file", filename, 2),
Expand All @@ -556,7 +560,7 @@ def test_testdriver_unsupported_feature():
if kind in ["web-lax", "web-strict"]:
assert errors == [
("TESTDRIVER-UNSUPPORTED-QUERY-PARAMETER",
"testdriver.js script seen with incorrect query parameters",
"testdriver.js script seen with unsupported query parameters",
filename, None),
]
elif kind == "python":
Expand All @@ -565,7 +569,7 @@ def test_testdriver_unsupported_feature():
]


def test_testdriver_multiple_unsupported_features():
def test_testdriver_multiple_with_unsupported_features():
code = b"""
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="/resources/testharness.js"></script>
Expand All @@ -582,7 +586,7 @@ def test_testdriver_multiple_unsupported_features():
if kind == "web-lax":
assert errors == [
('TESTDRIVER-UNSUPPORTED-QUERY-PARAMETER',
'testdriver.js script seen with incorrect query parameters',
'testdriver.js script seen with unsupported query parameters',
filename, None)
]
elif kind == "python":
Expand Down Expand Up @@ -660,7 +664,7 @@ def test_testdriver_unsupported_empty_feature():
if kind in ["web-lax", "web-strict"]:
assert errors == [
("TESTDRIVER-UNSUPPORTED-QUERY-PARAMETER",
"testdriver.js script seen with incorrect query parameters",
"testdriver.js script seen with unsupported query parameters",
filename, None),
]
elif kind == "python":
Expand Down

0 comments on commit 5d34df3

Please sign in to comment.