Skip to content

Commit

Permalink
Reduce noise of Android accessibility test PRESUBMIT
Browse files Browse the repository at this point in the history
This CL fixes some tests to reduce the noise of an accessibility
PRESUBMIT, and moves these into a new PRESUBMIT.py file.

AX-Relnotes: N/A
Bug: 379843998
Change-Id: I142288de836c92234fadabcb9d66cc382415057d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6036252
Reviewed-by: Aaron Leventhal <[email protected]>
Reviewed-by: Andrew Grieve <[email protected]>
Commit-Queue: Mark Schillaci <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1386935}
  • Loading branch information
mschillaci authored and Chromium LUCI CQ committed Nov 22, 2024
1 parent c19f5d9 commit 9c81854
Show file tree
Hide file tree
Showing 5 changed files with 422 additions and 336 deletions.
122 changes: 0 additions & 122 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -5873,128 +5873,6 @@ def FileFilter(affected_file):

return [output_api.PresubmitNotifyResult(message)]


_ACCESSIBILITY_EVENTS_TEST_PATH = (
r"^content/test/data/accessibility/event/.*\.html",
)

_ACCESSIBILITY_TREE_TEST_PATH = (
r"^content/test/data/accessibility/accname/"
".*-expected-(mac|win|uia-win|auralinux).txt",
r"^content/test/data/accessibility/aria/"
".*-expected-(mac|win|uia-win|auralinux).txt",
r"^content/test/data/accessibility/css/"
".*-expected-(mac|win|uia-win|auralinux).txt",
r"^content/test/data/accessibility/event/"
".*-expected-(mac|win|uia-win|auralinux).txt",
r"^content/test/data/accessibility/html/"
".*-expected-(mac|win|uia-win|auralinux).txt",
)

_ACCESSIBILITY_ANDROID_EVENTS_TEST_PATH = (
r"^.*/WebContentsAccessibilityEventsTest\.java",
)

_ACCESSIBILITY_ANDROID_TREE_TEST_PATH = (
r"^.*/WebContentsAccessibilityTreeTest\.java",
)

def CheckAccessibilityEventsTestsAreIncludedForAndroid(input_api, output_api):
"""Checks that commits that include a newly added, renamed/moved, or deleted
test in the DumpAccessibilityEventsTest suite also includes a corresponding
change to the Android test."""

def FilePathFilter(affected_file):
paths = _ACCESSIBILITY_EVENTS_TEST_PATH
return input_api.FilterSourceFile(affected_file, files_to_check=paths)

def AndroidFilePathFilter(affected_file):
paths = _ACCESSIBILITY_ANDROID_EVENTS_TEST_PATH
return input_api.FilterSourceFile(affected_file, files_to_check=paths)

# Only consider changes in the events test data path with html type.
if not any(
input_api.AffectedFiles(include_deletes=True,
file_filter=FilePathFilter)):
return []

# If the commit contains any change to the Android test file, ignore.
if any(
input_api.AffectedFiles(include_deletes=True,
file_filter=AndroidFilePathFilter)):
return []

# Only consider changes that are adding/renaming or deleting a file
message = []
for f in input_api.AffectedFiles(include_deletes=True,
file_filter=FilePathFilter):
if f.Action() == 'A':
message = (
"It appears that you are adding platform expectations for a"
"\ndump_accessibility_events* test, but have not included"
"\na corresponding change for Android."
"\nPlease include the test from:"
"\n content/public/android/javatests/src/org/chromium/"
"content/browser/accessibility/"
"WebContentsAccessibilityEventsTest.java"
"\nIf this message is confusing or annoying, please contact"
"\nmembers of ui/accessibility/OWNERS.")

# If no message was set, return empty.
if not len(message):
return []

return [output_api.PresubmitPromptWarning(message)]


def CheckAccessibilityTreeTestsAreIncludedForAndroid(input_api, output_api):
"""Checks that commits that include a newly added, renamed/moved, or deleted
test in the DumpAccessibilityTreeTest suite also includes a corresponding
change to the Android test."""

def FilePathFilter(affected_file):
paths = _ACCESSIBILITY_TREE_TEST_PATH
return input_api.FilterSourceFile(affected_file, files_to_check=paths)

def AndroidFilePathFilter(affected_file):
paths = _ACCESSIBILITY_ANDROID_TREE_TEST_PATH
return input_api.FilterSourceFile(affected_file, files_to_check=paths)

# Only consider changes in the various tree test data paths with html type.
if not any(
input_api.AffectedFiles(include_deletes=True,
file_filter=FilePathFilter)):
return []

# If the commit contains any change to the Android test file, ignore.
if any(
input_api.AffectedFiles(include_deletes=True,
file_filter=AndroidFilePathFilter)):
return []

# Only consider changes that are adding/renaming or deleting a file
message = []
for f in input_api.AffectedFiles(include_deletes=True,
file_filter=FilePathFilter):
if f.Action() == 'A':
message = (
"It appears that you are adding platform expectations for a"
"\ndump_accessibility_tree* test, but have not included"
"\na corresponding change for Android."
"\nPlease include (or remove) the test from:"
"\n content/public/android/javatests/src/org/chromium/"
"content/browser/accessibility/"
"WebContentsAccessibilityTreeTest.java"
"\nIf this message is confusing or annoying, please contact"
"\nmembers of ui/accessibility/OWNERS.")

# If no message was set, return empty.
if not len(message):
return []

return [output_api.PresubmitPromptWarning(message)]


# string pattern, sequence of strings to show when pattern matches,
# error flag. True if match is a presubmit error, otherwise it's a warning.
_NON_INCLUSIVE_TERMS = (
Expand Down
214 changes: 0 additions & 214 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,220 +1289,6 @@ def testRelnotesLowercaseWithEqualSign(self):
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))


class AccessibilityEventsTestsAreIncludedForAndroidTest(unittest.TestCase):
# Test that no warning is raised when the Android file is also modified.
def testAndroidChangeIncluded(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile(
'content/test/data/accessibility/event/foo-expected-mac.txt',
[''],
action='A'),
MockAffectedFile(
'accessibility/WebContentsAccessibilityEventsTest.java', [''],
action='M')
]

msgs = PRESUBMIT.CheckAccessibilityEventsTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that Android change is not required when no html file is added/removed.
def testIgnoreNonHtmlFiles(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile('content/test/data/accessibility/event/foo.txt',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/event/foo.cc',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/event/foo.h',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/event/foo.py',
[''],
action='A')
]

msgs = PRESUBMIT.CheckAccessibilityEventsTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that Android change is not required for unrelated html files.
def testIgnoreNonRelatedHtmlFiles(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile('content/test/data/accessibility/aria/foo.html',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/html/foo.html',
[''],
action='A'),
MockAffectedFile('chrome/tests/data/accessibility/foo.html', [''],
action='A')
]

msgs = PRESUBMIT.CheckAccessibilityEventsTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that only modifying an html file will not trigger the warning.
def testIgnoreModifiedFiles(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile(
'content/test/data/accessibility/event/foo-expected-win.txt',
[''],
action='M')
]

msgs = PRESUBMIT.CheckAccessibilityEventsTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))


class AccessibilityTreeTestsAreIncludedForAndroidTest(unittest.TestCase):
# Test that no warning is raised when the Android file is also modified.
def testAndroidChangeIncluded(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile('content/test/data/accessibility/aria/foo.html',
[''],
action='A'),
MockAffectedFile(
'accessibility/WebContentsAccessibilityTreeTest.java', [''],
action='M')
]

msgs = PRESUBMIT.CheckAccessibilityTreeTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that no warning is raised when the Android file is also modified.
def testAndroidChangeIncludedManyFiles(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile(
'content/test/data/accessibility/accname/foo.html', [''],
action='A'),
MockAffectedFile('content/test/data/accessibility/aria/foo.html',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/css/foo.html',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/html/foo.html',
[''],
action='A'),
MockAffectedFile(
'accessibility/WebContentsAccessibilityTreeTest.java', [''],
action='M')
]

msgs = PRESUBMIT.CheckAccessibilityTreeTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that a warning is raised when the Android file is not modified.
def testAndroidChangeMissing(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile(
'content/test/data/accessibility/aria/foo-expected-win.txt',
[''],
action='A'),
]

msgs = PRESUBMIT.CheckAccessibilityTreeTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
1, len(msgs),
'Expected %d messages, found %d: %s' % (1, len(msgs), msgs))

# Test that Android change is not required when no platform expectations files are changed.
def testAndroidChangNotMissing(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile('content/test/data/accessibility/accname/foo.txt',
[''],
action='A'),
MockAffectedFile(
'content/test/data/accessibility/html/foo-expected-blink.txt',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/html/foo.html',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/aria/foo.cc',
[''],
action='A'),
MockAffectedFile('content/test/data/accessibility/css/foo.h', [''],
action='A'),
MockAffectedFile('content/test/data/accessibility/tree/foo.py',
[''],
action='A')
]

msgs = PRESUBMIT.CheckAccessibilityTreeTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that Android change is not required for unrelated html files.
def testIgnoreNonRelatedHtmlFiles(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile('content/test/data/accessibility/event/foo.html',
[''],
action='A'),
]

msgs = PRESUBMIT.CheckAccessibilityTreeTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))

# Test that only modifying an html file will not trigger the warning.
def testIgnoreModifiedFiles(self):
mock_input_api = MockInputApi()

mock_input_api.files = [
MockAffectedFile('content/test/data/accessibility/aria/foo.html',
[''],
action='M')
]

msgs = PRESUBMIT.CheckAccessibilityTreeTestsAreIncludedForAndroid(
mock_input_api, MockOutputApi())
self.assertEqual(
0, len(msgs),
'Expected %d messages, found %d: %s' % (0, len(msgs), msgs))


class AndroidDeprecatedTestAnnotationTest(unittest.TestCase):

def testCheckAndroidTestAnnotationUsage(self):
Expand Down
2 changes: 2 additions & 0 deletions content/test/content_test_bundle_data.filelist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ data/accept-drop.html
data/accept-header-iframe.html
data/accept-header-iframe.html.mock-http-headers
data/accept-header.html
data/accessibility/PRESUBMIT.py
data/accessibility/PRESUBMIT_test.py
data/accessibility/accdescription/description-ignores-slot-expected-blink.txt
data/accessibility/accdescription/description-ignores-slot.html
data/accessibility/accname/desc-combobox-focusable-expected-android-assist-data.txt
Expand Down
Loading

0 comments on commit 9c81854

Please sign in to comment.