From ce248e87f9c1c968544674b9cc31507ba025d066 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 13 Jun 2023 08:57:27 -0700 Subject: [PATCH] Update misc tests for Material3 (#128712) --- .../app_lifecycle_listener.1.dart | 47 +++++++++---------- .../flutter_test/test/accessibility_test.dart | 45 ++++++++++++++++-- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart b/examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart index 3315f81732..c35945e12a 100644 --- a/examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart +++ b/examples/api/lib/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart @@ -78,30 +78,29 @@ class _ApplicationExitControlState extends State { return Center( child: SizedBox( width: 300, - child: IntrinsicHeight( - child: Column( - children: [ - RadioListTile( - title: const Text('Do Not Allow Exit'), - groupValue: _shouldExit, - value: false, - onChanged: _radioChanged, - ), - RadioListTile( - title: const Text('Allow Exit'), - groupValue: _shouldExit, - value: true, - onChanged: _radioChanged, - ), - const SizedBox(height: 30), - ElevatedButton( - onPressed: _quit, - child: const Text('Quit'), - ), - const SizedBox(height: 30), - Text('Exit Request: $_lastExitResponse'), - ], - ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + RadioListTile( + title: const Text('Do Not Allow Exit'), + groupValue: _shouldExit, + value: false, + onChanged: _radioChanged, + ), + RadioListTile( + title: const Text('Allow Exit'), + groupValue: _shouldExit, + value: true, + onChanged: _radioChanged, + ), + const SizedBox(height: 30), + ElevatedButton( + onPressed: _quit, + child: const Text('Quit'), + ), + const SizedBox(height: 30), + Text('Exit Request: $_lastExitResponse'), + ], ), ), ); diff --git a/packages/flutter_test/test/accessibility_test.dart b/packages/flutter_test/test/accessibility_test.dart index 59129ba474..2bf455c290 100644 --- a/packages/flutter_test/test/accessibility_test.dart +++ b/packages/flutter_test/test/accessibility_test.dart @@ -275,11 +275,12 @@ void main() { handle.dispose(); }); - testWidgets('yellow text on yellow background fails with correct message', + testWidgets('Material2: yellow text on yellow background fails with correct message', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget( _boilerplate( + useMaterial3: false, Container( width: 200.0, height: 200.0, @@ -306,6 +307,38 @@ void main() { handle.dispose(); }); + testWidgets('Material3: yellow text on yellow background fails with correct message', + (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + await tester.pumpWidget( + _boilerplate( + useMaterial3: true, + Container( + width: 200.0, + height: 200.0, + color: Colors.yellow, + child: const Text( + 'this is a test', + style: TextStyle(fontSize: 14.0, color: Colors.yellowAccent), + ), + ), + ), + ); + final Evaluation result = await textContrastGuideline.evaluate(tester); + expect(result.passed, false); + expect( + result.reason, + 'SemanticsNode#4(Rect.fromLTRB(300.0, 200.0, 500.0, 400.0), ' + 'label: "this is a test", textDirection: ltr):\n' + 'Expected contrast ratio of at least 4.5 but found 1.19 for a font ' + 'size of 14.0.\n' + 'The computed colors was:\n' + 'light - Color(0xfffffbfe), dark - Color(0xffffeb3b)\n' + 'See also: https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html', + ); + handle.dispose(); + }); + testWidgets('label without corresponding text is skipped', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); @@ -937,5 +970,11 @@ void main() { }); } -Widget _boilerplate(Widget child) => - MaterialApp(home: Scaffold(body: Center(child: child))); +Widget _boilerplate(Widget child, { bool? useMaterial3 }) { + return MaterialApp( + theme: ThemeData(useMaterial3: useMaterial3), + home: Scaffold( + body: Center(child: child), + ), + ); +}