Skip to content

Commit 10bc7b7

Browse files
committed
Add a lint for the NavigatorID mixin
We have a number of places where tests use UA sniffing when they have no reasonable reason to; we really shouldn't do this, as it just leads to more problems down the road when we're trying to get interoperability.
1 parent 2cb44ea commit 10bc7b7

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

lint.ignore

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,3 +840,111 @@ PROMISE_REJECTS: wasm/core/js/harness/testharness.js
840840

841841
# Legitimate use of test_driver_internal
842842
TEST DRIVER INTERNAL: resources/testdriver.js
843+
844+
# Intentional use of the NavigatorID interface mixin
845+
NAVIGATORID: FileAPI/blob/Blob-constructor-endings.html
846+
NAVIGATORID: FileAPI/file/File-constructor-endings.html
847+
NAVIGATORID: client-hints/permissions-policy/ch-ua-high-entropy-values-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html
848+
NAVIGATORID: client-hints/permissions-policy/ch-ua-high-entropy-values-default-permissions-policy.https.sub.html
849+
NAVIGATORID: client-hints/permissions-policy/ch-ua-high-entropy-values-disabled-by-permissions-policy.https.sub.html
850+
NAVIGATORID: client-hints/permissions-policy/ch-ua-high-entropy-values-enabled-by-permissions-policy.https.sub.html
851+
NAVIGATORID: client-hints/permissions-policy/ch-ua-high-entropy-values-enabled-on-self-origin-by-permissions-policy.https.sub.html
852+
NAVIGATORID: client-hints/permissions-policy/ch-ua-high-entropy-values-permissions-policy-attribute.https.sub.html
853+
NAVIGATORID: clipboard-apis/async-navigator-clipboard-write-multiple.tentative.https.sub.html
854+
NAVIGATORID: conformance-checkers/*
855+
NAVIGATORID: content-security-policy/embedded-enforcement/support/echo-allow-csp-from.py
856+
NAVIGATORID: editing/other/typing-around-link-element-at-collapsed-selection.tentative.html
857+
NAVIGATORID: encrypted-media/util/utils.js
858+
NAVIGATORID: file-system-access/resources/test-helpers.js
859+
NAVIGATORID: html/semantics/forms/the-textarea-element/selection-after-whitespace-change.html
860+
NAVIGATORID: html/webappapis/system-state-and-capabilities/the-navigator-object/navigator.any.js
861+
NAVIGATORID: html/webappapis/system-state-and-capabilities/the-navigator-object/navigator_user_agent.https.tentative.html
862+
NAVIGATORID: infrastructure/testdriver/actions/textEditCommands.html
863+
NAVIGATORID: input-events/input-events-cut-paste.html
864+
NAVIGATORID: input-events/input-events-get-target-ranges.html
865+
NAVIGATORID: input-events/input-events-typing.html
866+
NAVIGATORID: network-error-logging/sends-report-on-404.https.html
867+
NAVIGATORID: network-error-logging/sends-report-on-cache-validation.https.html
868+
NAVIGATORID: network-error-logging/sends-report-on-redirect.https.html
869+
NAVIGATORID: network-error-logging/sends-report-on-subdomain-dns-failure.https.html
870+
NAVIGATORID: network-error-logging/sends-report-on-success-with-subdomain-policy.https.html
871+
NAVIGATORID: network-error-logging/sends-report-on-success.https.html
872+
NAVIGATORID: permissions-policy/resources/permissions-policy-ch-ua-high-entropy-values.html
873+
NAVIGATORID: resources/accesskey.js
874+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-cert_fetch_error-downgraded.tentative.html
875+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-cert_fetch_error.tentative.html
876+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-cert_parse_error-downgraded.tentative.html
877+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-cert_parse_error.tentative.html
878+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-cert_verification_error-downgraded.tentative.html
879+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-cert_verification_error.tentative.html
880+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-failed-zero-success-fraction.tentative.html
881+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-invalid_integrity_header.tentative.html
882+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-mi_error.tentative.html
883+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-ok-no-referrer.tentative.html
884+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-ok-origin-referrer.tentative.html
885+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-ok.tentative.html
886+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-parse_error.tentative.html
887+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-signature_verification_error-downgraded.tentative.html
888+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-navigation-signature_verification_error.tentative.html
889+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-cert_fetch_error-downgraded.tentative.html
890+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-cert_fetch_error.tentative.html
891+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-cert_parse_error-downgraded.tentative.html
892+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-cert_parse_error.tentative.html
893+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-cert_verification_error-downgraded.tentative.html
894+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-cert_verification_error.tentative.html
895+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-failed-zero-success-feaction.tentative.html
896+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-invalid_integrity_header.tentative.html
897+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-mi_error.tentative.html
898+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-ok.tentative.html
899+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-parse_error.tentative.html
900+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-signature_verification_error-downgraded.tentative.html
901+
NAVIGATORID: signed-exchange/reporting/sxg-reporting-prefetch-signature_verification_error.tentative.html
902+
NAVIGATORID: signed-exchange/subresource/sxg-subresource-header-integrity-mismatch.tentative.html
903+
NAVIGATORID: ua-client-hints/idlharness.https.any.js
904+
NAVIGATORID: ua-client-hints/useragentdata.https.any.js
905+
NAVIGATORID: ua-client-hints/useragentdata.https.tentative.any.js
906+
NAVIGATORID: webdriver/tests/bidi/emulation/set_user_agent_override/conftest.py
907+
NAVIGATORID: workers/WorkerNavigator.any.js
908+
NAVIGATORID: workers/WorkerNavigator_appName.htm
909+
NAVIGATORID: workers/WorkerNavigator_appVersion.htm
910+
NAVIGATORID: workers/WorkerNavigator_platform.htm
911+
NAVIGATORID: workers/WorkerNavigator_userAgent.htm
912+
NAVIGATORID: workers/WorkerNavigator_userAgentData.https.html
913+
NAVIGATORID: workers/WorkerNavigator_userAgentData.https.tentative.html
914+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/002.html
915+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/002.js
916+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/003.html
917+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/003.js
918+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/004.html
919+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/004.js
920+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/005.html
921+
NAVIGATORID: workers/interfaces/WorkerUtils/navigator/005.js
922+
NAVIGATORID: workers/support/WorkerNavigator.js
923+
NAVIGATORID: xhr/preserve-ua-header-on-redirect.htm
924+
925+
# Bad use of the NavigatorID interface mixin; you shouldn't ever be adding things here.
926+
NAVIGATORID: content-security-policy/generic/test-case.sub.js
927+
NAVIGATORID: cookies/third-party-cookies/resources/third-party-cookies-cross-site-popup-opener.html
928+
NAVIGATORID: css/css-tables/tools/markup-generator.html
929+
NAVIGATORID: dom/events/scrolling/scrollend-event-fired-after-sequence-of-scrolls.tentative.html
930+
NAVIGATORID: dom/events/scrolling/scrollend-user-scroll-common.js
931+
NAVIGATORID: editing/include/editor-test-utils.js
932+
NAVIGATORID: editing/include/tests.js
933+
NAVIGATORID: editing/other/insertparagraph-in-inline-editing-host.tentative.html
934+
NAVIGATORID: editing/plaintext-only/insertLineBreak.html
935+
NAVIGATORID: editing/plaintext-only/insertText.html
936+
NAVIGATORID: encrypted-media/polyfill/cast-polyfill.js
937+
NAVIGATORID: encrypted-media/polyfill/chrome-polyfill.js
938+
NAVIGATORID: encrypted-media/polyfill/edge-keystatuses.js
939+
NAVIGATORID: encrypted-media/polyfill/firefox-polyfill.js
940+
NAVIGATORID: event-timing/TapToStopFling.html
941+
NAVIGATORID: event-timing/selection-autoscroll.html
942+
NAVIGATORID: fenced-frame/visual-viewport.https.html
943+
NAVIGATORID: font-access/resources/font-data.js
944+
NAVIGATORID: font-access/resources/font-test-utils.js
945+
NAVIGATORID: html/semantics/forms/the-select-element/customizable-select/select-keyboard-behavior.optional.html
946+
NAVIGATORID: pointerevents/pointerevent_range_input.html
947+
NAVIGATORID: scheduler/task-controller-setPriority-delayed-task.any.js
948+
NAVIGATORID: uievents/keyboard/key.js
949+
NAVIGATORID: web-animations/resources/timing-override.js
950+
NAVIGATORID: webxr/xrWebGLLayer_opaque_framebuffer_stencil.https.html

tools/lint/lint.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def filter_ignorelist_errors(data: Ignorelist, errors: Sequence[rules.Error]) ->
360360
rules.AssertPreconditionRegexp,
361361
rules.HTMLInvalidSyntaxRegexp,
362362
rules.TestDriverInternalRegexp,
363+
rules.NavigatorIdRegexp,
363364
)
364365
]
365366

tools/lint/rules.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,11 @@ class TestDriverInternalRegexp(Regexp):
565565
file_extensions = EXTENSIONS["js_all"]
566566
description = "Test-file uses test_driver_internal API"
567567
to_fix = """Only use test_driver public API"""
568+
569+
570+
class NavigatorIdRegexp(Regexp):
571+
pattern = br"\bnavigator\.(appCodeName|appName|appVersion|platform|product|productSub|userAgent|userAgentData|vendor|vendorSub|taintEnabled|oscpu)\b"
572+
name = "NAVIGATORID"
573+
file_extensions = EXTENSIONS["js_all"]
574+
description = "navigator.%s used"
575+
to_fix = """Avoid user-agent sniffing within tests"""

tools/lint/tests/test_file_lints.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,33 @@ def test_testdriver_internal():
253253
assert errors == [("TEST DRIVER INTERNAL", "Test-file uses test_driver_internal API", filename, 1)]
254254

255255

256+
@pytest.mark.parametrize(
257+
"attribute",
258+
[
259+
"appCodeName",
260+
"appName",
261+
"appVersion",
262+
"platform",
263+
"product",
264+
"productSub",
265+
"userAgent",
266+
"userAgentData",
267+
"vendor",
268+
"vendorSub",
269+
"taintEnabled",
270+
"oscpu",
271+
],
272+
)
273+
def test_navigatorid(attribute):
274+
error_map = check_with_files(b"<script>navigator.%s</script>" % attribute.encode("ascii"))
275+
276+
for (filename, (errors, kind)) in error_map.items():
277+
check_errors(errors)
278+
279+
if kind != "python":
280+
assert errors == [("NAVIGATORID", f"navigator.{attribute} used", filename, 1)]
281+
282+
256283
def test_meta_timeout():
257284
code = b"""
258285
<html xmlns="http://www.w3.org/1999/xhtml">

0 commit comments

Comments
 (0)