From 986503981cebf586daf4fd44dde4ffca523b8863 Mon Sep 17 00:00:00 2001 From: Ankur Jain Date: Tue, 30 Aug 2022 15:50:18 -0700 Subject: [PATCH] Add test where white text on white background fails contrast. (#110217) --- .../flutter_test/test/accessibility_test.dart | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/flutter_test/test/accessibility_test.dart b/packages/flutter_test/test/accessibility_test.dart index c0dbb015cb92..399a33e77fad 100644 --- a/packages/flutter_test/test/accessibility_test.dart +++ b/packages/flutter_test/test/accessibility_test.dart @@ -43,6 +43,40 @@ void main() { handle.dispose(); }); + testWidgets('White text on white background fails contrast test', + (WidgetTester tester) async { + final SemanticsHandle handle = tester.ensureSemantics(); + await tester.pumpWidget( + _boilerplate( + Container( + width: 200.0, + height: 300.0, + color: Colors.white, + child: Column( + children: const [ + Text( + 'this is a white text', + style: TextStyle(fontSize: 14.0, color: Colors.white), + ), + SizedBox(height: 50), + Text( + 'this is a black text test1', + style: TextStyle(fontSize: 14.0, color: Colors.black), + ), + SizedBox(height: 50), + Text( + 'this is a black text test2', + style: TextStyle(fontSize: 14.0, color: Colors.black), + ), + ], + ), + ), + ), + ); + await expectLater(tester, doesNotMeetGuideline(textContrastGuideline)); + handle.dispose(); + }); + const Color surface = Color(0xFFF0F0F0); /// Shades of blue with contrast ratio of 2.9, 4.4, 4.5 from [surface].