From ab2d0323a765d297a3b7900112dbed2a562119af Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 6 Nov 2018 13:29:23 -0800 Subject: [PATCH] cleanup accessibility test skips in gallery (#23977) --- .../lib/demo/material/backdrop_demo.dart | 1 + .../demo/material/bottom_app_bar_demo.dart | 11 +++---- .../lib/demo/material/buttons_demo.dart | 29 ++++++++++--------- .../lib/demo/material/cards_demo.dart | 9 ++++-- .../lib/demo/material/tabs_fab_demo.dart | 2 +- .../demo/material/text_form_field_demo.dart | 5 +++- .../flutter_gallery/lib/gallery/demo.dart | 2 +- .../test/accessibility_test.dart | 18 ++++++------ .../flutter_test/lib/src/accessibility.dart | 6 ++-- 9 files changed, 47 insertions(+), 36 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/material/backdrop_demo.dart b/examples/flutter_gallery/lib/demo/material/backdrop_demo.dart index 9f7b62486f..67d0a61408 100644 --- a/examples/flutter_gallery/lib/demo/material/backdrop_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/backdrop_demo.dart @@ -395,6 +395,7 @@ class _BackdropDemoState extends State with SingleTickerProviderSt onPressed: _toggleBackdropPanelVisibility, icon: AnimatedIcon( icon: AnimatedIcons.close_menu, + semanticLabel: 'close', progress: _controller.view, ), ), diff --git a/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart b/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart index 0b1a2727b2..0baef79476 100644 --- a/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/bottom_app_bar_demo.dart @@ -33,7 +33,7 @@ class _BottomAppBarDemoState extends State { label: 'circular floating action button', value: FloatingActionButton( onPressed: _showSnackbar, - child: Icon(Icons.add), + child: Icon(Icons.add, semanticLabel: 'Action'), backgroundColor: Colors.orange, ), ); @@ -43,7 +43,7 @@ class _BottomAppBarDemoState extends State { label: 'diamond shape floating action button', value: _DiamondFab( onPressed: _showSnackbar, - child: Icon(Icons.add), + child: Icon(Icons.add, semanticLabel: 'Action'), ), ); @@ -147,7 +147,7 @@ class _BottomAppBarDemoState extends State { actions: [ MaterialDemoDocumentationButton(BottomAppBarDemo.routeName), IconButton( - icon: const Icon(Icons.sentiment_very_satisfied), + icon: const Icon(Icons.sentiment_very_satisfied, semanticLabel: 'Update shape'), onPressed: () { setState(() { _fabShape = _fabShape == kCircularFab ? kDiamondFab : kCircularFab; @@ -349,7 +349,7 @@ class _DemoBottomAppBar extends StatelessWidget { Widget build(BuildContext context) { final List rowContents = [ IconButton( - icon: const Icon(Icons.menu), + icon: const Icon(Icons.menu, semanticLabel: 'Show bottom sheet'), onPressed: () { showModalBottomSheet( context: context, @@ -367,7 +367,7 @@ class _DemoBottomAppBar extends StatelessWidget { rowContents.addAll( [ IconButton( - icon: const Icon(Icons.search), + icon: const Icon(Icons.search, semanticLabel: 'show search action',), onPressed: () { Scaffold.of(context).showSnackBar( const SnackBar(content: Text('This is a dummy search action.')), @@ -379,6 +379,7 @@ class _DemoBottomAppBar extends StatelessWidget { Theme.of(context).platform == TargetPlatform.iOS ? Icons.more_horiz : Icons.more_vert, + semanticLabel: 'Show menu actions', ), onPressed: () { Scaffold.of(context).showSnackBar( diff --git a/examples/flutter_gallery/lib/demo/material/buttons_demo.dart b/examples/flutter_gallery/lib/demo/material/buttons_demo.dart index 9de0655709..4b5f079a37 100644 --- a/examples/flutter_gallery/lib/demo/material/buttons_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/buttons_demo.dart @@ -120,7 +120,7 @@ class _ButtonsDemoState extends State { demos: demos, actions: [ IconButton( - icon: const Icon(Icons.sentiment_very_satisfied), + icon: const Icon(Icons.sentiment_very_satisfied, semanticLabel: 'Update shape'), onPressed: () { setState(() { _buttonShape = _buttonShape == null ? const StadiumBorder() : null; @@ -141,13 +141,13 @@ class _ButtonsDemoState extends State { mainAxisSize: MainAxisSize.min, children: [ RaisedButton( - child: const Text('RAISED BUTTON'), + child: const Text('RAISED BUTTON', semanticsLabel: 'RAISED BUTTON 1'), onPressed: () { // Perform some action }, ), const RaisedButton( - child: Text('DISABLED'), + child: Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 1'), onPressed: null, ), ], @@ -157,14 +157,14 @@ class _ButtonsDemoState extends State { children: [ RaisedButton.icon( icon: const Icon(Icons.add, size: 18.0), - label: const Text('RAISED BUTTON'), + label: const Text('RAISED BUTTON', semanticsLabel: 'RAISED BUTTON 2'), onPressed: () { // Perform some action }, ), RaisedButton.icon( icon: const Icon(Icons.add, size: 18.0), - label: const Text('DISABLED'), + label: const Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 2'), onPressed: null, ), ], @@ -184,13 +184,13 @@ class _ButtonsDemoState extends State { mainAxisSize: MainAxisSize.min, children: [ FlatButton( - child: const Text('FLAT BUTTON'), + child: const Text('FLAT BUTTON', semanticsLabel: 'FLAT BUTTON 1'), onPressed: () { // Perform some action }, ), const FlatButton( - child: Text('DISABLED'), + child: Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 3',), onPressed: null, ), ], @@ -200,14 +200,14 @@ class _ButtonsDemoState extends State { children: [ FlatButton.icon( icon: const Icon(Icons.add_circle_outline, size: 18.0), - label: const Text('FLAT BUTTON'), + label: const Text('FLAT BUTTON', semanticsLabel: 'FLAT BUTTON 2'), onPressed: () { // Perform some action }, ), FlatButton.icon( icon: const Icon(Icons.add_circle_outline, size: 18.0), - label: const Text('DISABLED'), + label: const Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 4'), onPressed: null, ), ], @@ -227,13 +227,13 @@ class _ButtonsDemoState extends State { mainAxisSize: MainAxisSize.min, children: [ OutlineButton( - child: const Text('OUTLINE BUTTON'), + child: const Text('OUTLINE BUTTON', semanticsLabel: 'OUTLINE BUTTON 1'), onPressed: () { // Perform some action }, ), const OutlineButton( - child: Text('DISABLED'), + child: Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 5'), onPressed: null, ), ], @@ -243,14 +243,14 @@ class _ButtonsDemoState extends State { children: [ OutlineButton.icon( icon: const Icon(Icons.add, size: 18.0), - label: const Text('OUTLINE BUTTON'), + label: const Text('OUTLINE BUTTON', semanticsLabel: 'OUTLINE BUTTON 2'), onPressed: () { // Perform some action }, ), OutlineButton.icon( icon: const Icon(Icons.add, size: 18.0), - label: const Text('DISABLED'), + label: const Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 6'), onPressed: null, ), ], @@ -360,7 +360,7 @@ class _ButtonsDemoState extends State { const IconButton( icon: Icon( Icons.thumb_up, - semanticLabel: 'Thumbs up', + semanticLabel: 'Thumbs not up', ), onPressed: null, ) @@ -379,6 +379,7 @@ class _ButtonsDemoState extends State { onPressed: () { // Perform some action }, + tooltip: 'floating action button', ), ); } diff --git a/examples/flutter_gallery/lib/demo/material/cards_demo.dart b/examples/flutter_gallery/lib/demo/material/cards_demo.dart index 2a09e8cabd..f7ea1b9a4e 100644 --- a/examples/flutter_gallery/lib/demo/material/cards_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/cards_demo.dart @@ -133,12 +133,12 @@ class TravelDestinationItem extends StatelessWidget { alignment: MainAxisAlignment.start, children: [ FlatButton( - child: const Text('SHARE'), + child: Text('SHARE', semanticsLabel: 'Share ${destination.title}'), textColor: Colors.amber.shade500, onPressed: () { /* do nothing */ }, ), FlatButton( - child: const Text('EXPLORE'), + child: Text('EXPLORE', semanticsLabel: 'Explore ${destination.title}'), textColor: Colors.amber.shade500, onPressed: () { /* do nothing */ }, ), @@ -172,7 +172,10 @@ class _CardsDemoState extends State { actions: [ MaterialDemoDocumentationButton(CardsDemo.routeName), IconButton( - icon: const Icon(Icons.sentiment_very_satisfied), + icon: const Icon( + Icons.sentiment_very_satisfied, + semanticLabel: 'update shape', + ), onPressed: () { setState(() { _shape = _shape != null ? null : const RoundedRectangleBorder( diff --git a/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart b/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart index 6f09cb8622..b24daf71b5 100644 --- a/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart @@ -141,7 +141,7 @@ class _TabsFabDemoState extends State with SingleTickerProviderStat actions: [ MaterialDemoDocumentationButton(TabsFabDemo.routeName), IconButton( - icon: const Icon(Icons.sentiment_very_satisfied), + icon: const Icon(Icons.sentiment_very_satisfied, semanticLabel: 'Toggle extended buttons'), onPressed: () { setState(() { _extendedButtons = !_extendedButtons; diff --git a/examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart b/examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart index bcaa216094..2fab33a206 100644 --- a/examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart @@ -72,7 +72,10 @@ class _PasswordFieldState extends State { _obscureText = !_obscureText; }); }, - child: Icon(_obscureText ? Icons.visibility : Icons.visibility_off), + child: Icon( + _obscureText ? Icons.visibility : Icons.visibility_off, + semanticLabel: _obscureText ? 'show password' : 'hide password', + ), ), ), ); diff --git a/examples/flutter_gallery/lib/gallery/demo.dart b/examples/flutter_gallery/lib/gallery/demo.dart index 12afd7df98..25a13b7087 100644 --- a/examples/flutter_gallery/lib/gallery/demo.dart +++ b/examples/flutter_gallery/lib/gallery/demo.dart @@ -78,7 +78,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget { Builder( builder: (BuildContext context) { return IconButton( - icon: const Icon(Icons.library_books), + icon: const Icon(Icons.library_books, semanticLabel: 'Show documentation'), onPressed: () => _showApiDocumentation(context), ); }, diff --git a/examples/flutter_gallery/test/accessibility_test.dart b/examples/flutter_gallery/test/accessibility_test.dart index 27a3c51427..59358c7837 100644 --- a/examples/flutter_gallery/test/accessibility_test.dart +++ b/examples/flutter_gallery/test/accessibility_test.dart @@ -243,14 +243,14 @@ void main() { await tester.pumpWidget(MaterialApp(home: BackdropDemo())); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); handle.dispose(); - }, skip: true); + }); testWidgets('bottom_app_bar_demo', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget(MaterialApp(home: BottomAppBarDemo())); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); handle.dispose(); - }, skip: true); + }); testWidgets('bottom_navigation_demo', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); @@ -264,14 +264,14 @@ void main() { await tester.pumpWidget(MaterialApp(home: ButtonsDemo())); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); handle.dispose(); - }, skip: true); + }); testWidgets('cards_demo', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget(MaterialApp(home: CardsDemo())); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); handle.dispose(); - }, skip: true); + }); testWidgets('chip_demo', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); @@ -446,14 +446,14 @@ void main() { await tester.pumpWidget(MaterialApp(home: TabsFabDemo())); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); handle.dispose(); - }, skip: true); + }); testWidgets('text_form_field_demo', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget(const MaterialApp(home: TextFormFieldDemo())); await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); handle.dispose(); - }, skip: true); + }); testWidgets('tooltip_demo', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); @@ -503,7 +503,7 @@ void main() { await tester.pumpWidget(MaterialApp(theme: theme, home: BottomAppBarDemo())); await expectLater(tester, meetsGuideline(textContrastGuideline)); handle.dispose(); - }, skip: true); // https://github.com/flutter/flutter/issues/21651 + }); testWidgets('bottom_navigation_demo $themeName', (WidgetTester tester) async { final AutomatedTestWidgetsFlutterBinding binding = tester.binding; @@ -521,7 +521,7 @@ void main() { await tester.pumpWidget(MaterialApp(theme: theme, home: ButtonsDemo())); await expectLater(tester, meetsGuideline(textContrastGuideline)); handle.dispose(); - }, skip: true); // https://github.com/flutter/flutter/issues/21647 + }); testWidgets('cards_demo $themeName', (WidgetTester tester) async { final AutomatedTestWidgetsFlutterBinding binding = tester.binding; @@ -530,7 +530,7 @@ void main() { await tester.pumpWidget(MaterialApp(theme: theme, home: CardsDemo())); await expectLater(tester, meetsGuideline(textContrastGuideline)); handle.dispose(); - }, skip: true); // https://github.com/flutter/flutter/issues/21651 + }); testWidgets('chip_demo $themeName', (WidgetTester tester) async { final AutomatedTestWidgetsFlutterBinding binding = tester.binding; diff --git a/packages/flutter_test/lib/src/accessibility.dart b/packages/flutter_test/lib/src/accessibility.dart index 3433ae08a5..97a269d5c3 100644 --- a/packages/flutter_test/lib/src/accessibility.dart +++ b/packages/flutter_test/lib/src/accessibility.dart @@ -142,7 +142,7 @@ class LabeledTapTargetGuideline extends AccessibilityGuideline { result += traverse(child); return true; }); - if (node.isMergedIntoParent) + if (node.isMergedIntoParent || node.isInvisible || node.hasFlag(ui.SemanticsFlag.isHidden)) return result; final SemanticsData data = node.getSemanticsData(); // Skip node if it has no actions, or is marked as hidden. @@ -203,9 +203,11 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline { }); Future evaluateNode(SemanticsNode node) async { + Evaluation result = const Evaluation.pass(); + if (node.isInvisible || node.isMergedIntoParent || node.hasFlag(ui.SemanticsFlag.isHidden)) + return result; final SemanticsData data = node.getSemanticsData(); final List children = []; - Evaluation result = const Evaluation.pass(); node.visitChildren((SemanticsNode child) { children.add(child); return true;