-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use announce function in live region #38084
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1743,12 +1743,43 @@ void _testImage() { | |
}); | ||
} | ||
|
||
class MockAccessibilityAnnouncements implements AccessibilityAnnouncements { | ||
int announceInvoked = 0; | ||
|
||
@override | ||
void announce(String message, Assertiveness assertiveness) { | ||
announceInvoked += 1; | ||
} | ||
|
||
@override | ||
DomHTMLElement ariaLiveElementFor(Assertiveness assertiveness) { | ||
throw UnsupportedError( | ||
'ariaLiveElementFor is not supported in MockAccessibilityAnnouncements'); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
throw UnsupportedError( | ||
'dispose is not supported in MockAccessibilityAnnouncements!'); | ||
} | ||
|
||
@override | ||
void handleMessage(StandardMessageCodec codec, ByteData? data) { | ||
throw UnsupportedError( | ||
'handleMessage is not supported in MockAccessibilityAnnouncements!'); | ||
} | ||
} | ||
|
||
void _testLiveRegion() { | ||
test('renders a live region if there is a label', () async { | ||
test('announces the label after an update', () async { | ||
semantics() | ||
..debugOverrideTimestampFunction(() => _testTime) | ||
..semanticsEnabled = true; | ||
|
||
final MockAccessibilityAnnouncements mockAccessibilityAnnouncements = | ||
MockAccessibilityAnnouncements(); | ||
debugOverrideAccessibilityAnnouncements(mockAccessibilityAnnouncements); | ||
|
||
final ui.SemanticsUpdateBuilder builder = ui.SemanticsUpdateBuilder(); | ||
updateNode( | ||
builder, | ||
|
@@ -1758,19 +1789,20 @@ void _testLiveRegion() { | |
rect: const ui.Rect.fromLTRB(0, 0, 100, 50), | ||
); | ||
semantics().updateSemantics(builder.build()); | ||
|
||
expectSemanticsTree(''' | ||
<sem aria-label="This is a snackbar" aria-live="polite" style="$rootSemanticStyle"></sem> | ||
'''); | ||
expect(mockAccessibilityAnnouncements.announceInvoked, 1); | ||
|
||
semantics().semanticsEnabled = false; | ||
}); | ||
|
||
test('does not render a live region if there is no label', () async { | ||
test('does not announce anything if there is no label', () async { | ||
semantics() | ||
..debugOverrideTimestampFunction(() => _testTime) | ||
..semanticsEnabled = true; | ||
|
||
final MockAccessibilityAnnouncements mockAccessibilityAnnouncements = | ||
MockAccessibilityAnnouncements(); | ||
debugOverrideAccessibilityAnnouncements(mockAccessibilityAnnouncements); | ||
|
||
final ui.SemanticsUpdateBuilder builder = ui.SemanticsUpdateBuilder(); | ||
updateNode( | ||
builder, | ||
|
@@ -1779,10 +1811,41 @@ void _testLiveRegion() { | |
rect: const ui.Rect.fromLTRB(0, 0, 100, 50), | ||
); | ||
semantics().updateSemantics(builder.build()); | ||
expect(mockAccessibilityAnnouncements.announceInvoked, 0); | ||
|
||
expectSemanticsTree(''' | ||
<sem style="$rootSemanticStyle"></sem> | ||
'''); | ||
semantics().semanticsEnabled = false; | ||
}); | ||
|
||
test('does not announce the same label over and over', () async { | ||
semantics() | ||
..debugOverrideTimestampFunction(() => _testTime) | ||
..semanticsEnabled = true; | ||
|
||
final MockAccessibilityAnnouncements mockAccessibilityAnnouncements = | ||
MockAccessibilityAnnouncements(); | ||
debugOverrideAccessibilityAnnouncements(mockAccessibilityAnnouncements); | ||
|
||
ui.SemanticsUpdateBuilder builder = ui.SemanticsUpdateBuilder(); | ||
updateNode( | ||
builder, | ||
label: 'This is a snackbar', | ||
flags: 0 | ui.SemanticsFlag.isLiveRegion.index, | ||
transform: Matrix4.identity().toFloat64(), | ||
rect: const ui.Rect.fromLTRB(0, 0, 100, 50), | ||
); | ||
semantics().updateSemantics(builder.build()); | ||
expect(mockAccessibilityAnnouncements.announceInvoked, 1); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I'd add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Done! |
||
builder = ui.SemanticsUpdateBuilder(); | ||
updateNode( | ||
builder, | ||
label: 'This is a snackbar', | ||
flags: 0 | ui.SemanticsFlag.isLiveRegion.index, | ||
transform: Matrix4.identity().toFloat64(), | ||
rect: const ui.Rect.fromLTRB(0, 0, 100, 50), | ||
); | ||
semantics().updateSemantics(builder.build()); | ||
expect(mockAccessibilityAnnouncements.announceInvoked, 1); | ||
|
||
semantics().semanticsEnabled = false; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic that protects us from announcing the same message again is missing a test. It can be tested by clearing the contents of
ariaLiveElementFor(Assertiveness.polite)
after the first announcement, issuing an update with the same message, and verifying that the element remains empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on our conversation, I implemented a mock class for
AccessibilityAnnouncements
and added this test case.