From 9e99675dbe785fad3ea0cd42ab9fa0d4cae955ff Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:11:03 -0700 Subject: [PATCH] Made some pixel tests fuzzy (#154680) This is a forward fix for the failures seen in https://github.com/flutter/engine/pull/54714/checks?check_run_id=29742599916 on https://github.com/flutter/engine/pull/54714 issue: https://github.com/flutter/flutter/issues/127855 --- .../test/painting/decoration_test.dart | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/flutter/test/painting/decoration_test.dart b/packages/flutter/test/painting/decoration_test.dart index 677d9d9e3d..903e7be2f8 100644 --- a/packages/flutter/test/painting/decoration_test.dart +++ b/packages/flutter/test/painting/decoration_test.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:ui' as ui show ColorFilter, Image; +import 'dart:ui' as ui show Color, ColorFilter, Image; import 'package:fake_async/fake_async.dart'; import 'package:flutter/foundation.dart'; @@ -14,6 +14,36 @@ import '../image_data.dart'; import '../painting/mocks_for_image_cache.dart'; import '../rendering/rendering_tester.dart'; +/// Positive result if the colors would be mapped to the same argb8888 color. +class _ColorMatcher extends Matcher { + _ColorMatcher(this._target); + + final ui.Color _target; + + @override + Description describe(Description description) { + return description.add('matches "$_target"'); + } + + @override + bool matches(dynamic item, Map matchState) { + if (item is ui.Color) { + return item.colorSpace == _target.colorSpace && + (item.a - _target.a).abs() <= (1 / 255) && + (item.r - _target.r).abs() <= (1 / 255) && + (item.g - _target.g).abs() <= (1 / 255) && + (item.b - _target.b).abs() <= (1 / 255); + } else { + return false; + } + } + +} + +Matcher _matchesColor(ui.Color color) { + return _ColorMatcher(color); +} + class TestCanvas implements Canvas { final List invocations = []; @@ -326,7 +356,7 @@ void main() { expect(call.positionalArguments[3], isA()); final Paint paint = call.positionalArguments[3] as Paint; expect(paint.colorFilter, colorFilter); - expect(paint.color, const Color(0x7F000000)); // 0.5 opacity + expect(paint.color, _matchesColor(const Color(0x7F000000))); // 0.5 opacity expect(paint.filterQuality, FilterQuality.high); expect(paint.isAntiAlias, true); expect(paint.invertColors, isTrue);