Skip to content

Conversation

@zemanux
Copy link
Contributor

@zemanux zemanux commented Dec 18, 2025

Fix #180057

Pre-launch Checklist

@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Dec 18, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new accessibilityAnnouncement matcher to simplify testing of accessibility announcements. The implementation is clean and well-documented. The new matcher is used to refactor several existing tests, making them more concise and readable. I have one suggestion to improve the description of the matcher for better test failure messages.

@zemanux zemanux force-pushed the accessibility_announcement branch from bcf00ec to 25af693 Compare December 18, 2025 09:57
@zemanux zemanux force-pushed the accessibility_announcement branch from 25af693 to 64c48a3 Compare December 29, 2025 09:33
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly LGTM

///
/// * [WidgetTester.takeAnnouncements], which retrieves the announcements.
/// * [SemanticsService.sendAnnouncement], which sends an announcement.
Matcher accessibilityAnnouncement(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name can be more descriptive, something like containsAccessibilityAnnouncement. Our current nameing convenient is that keyword contains means it can have optional argument that only check against when set, otherwise, it should be matches

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

///
/// See also:
///
/// * [WidgetTester.takeAnnouncements], which retrieves the announcements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// * [WidgetTester.takeAnnouncements], which retrieves the announcements.
/// * [WidgetTester.takeAnnouncements], which retrieves the announcements in unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@zemanux zemanux requested a review from chunhtai January 5, 2026 09:43
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

///
/// ```dart
/// await SemanticsService.sendAnnouncement(tester.view, 'Hello', TextDirection.ltr);
/// expect(tester.takeAnnouncements(), contains(containsAccessibilityAnnouncement('Hello')));
Copy link
Member

@loic-sharma loic-sharma Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains(containsAccessibilityAnnouncement(...)) seems a little funky. What do you think of renaming containsAccessibilityAnnouncement to isAccessibilityAnnouncement?

The isFoo naming convention seems to better match other matchers like isOffstage, isSystemTextScaler, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see contains was suggested above: #180058 (comment)

Let me discuss offline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@loic-sharma
I considered that as well. However, since containsSemantics already exists nearby, I used containsAccessibilityAnnouncement for consistency. Maybe we should just update the example in the comment?

Copy link
Member

@loic-sharma loic-sharma Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chunhtai and I discussed this. TLDR: Let's rename this to isAccessibilityAnnouncement.


Longer version:

We don't have a consistent naming convention. We'd like to support several kinds of matchers:

  1. Partial matchers. These only match the properties you provide. Example: isFoo(property1: true).

    The matcher's arguments are null by default. The matcher only matches on non-null values you provide.

    Unfortunately, you cannot use this partial matcher to assert a value is null. For that you'd use...

  2. Exact matchers. These match all the properties, including those you do not provide. Example: matchesFoo(property1: true, nullablePropery: null)

    The matcher's arguments have the same default value as the object's property's default value.

To adopt this naming convention, we'll want to:

  1. Add this to our style guide
  2. Add a new isSemantics matcher, and deprecate containsSemantics.

I'll file an issue to track this work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed: #180534

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@zemanux zemanux force-pushed the accessibility_announcement branch from 04c6793 to 913def7 Compare January 5, 2026 19:44
Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the wonderful patch!

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 5, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Jan 5, 2026
Merged via the queue into flutter:master with commit 68d3d7b Jan 5, 2026
70 of 71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 5, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 6, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_test] Add a Matcher for CapturedAccessibilityAnnouncement

3 participants