Skip to content

Commit 9e99675

Browse files
authored
Made some pixel tests fuzzy (flutter#154680)
This is a forward fix for the failures seen in https://github.com/flutter/engine/pull/54714/checks?check_run_id=29742599916 on flutter/engine#54714 issue: flutter#127855
1 parent b0ed1cb commit 9e99675

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

packages/flutter/test/painting/decoration_test.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:ui' as ui show ColorFilter, Image;
6+
import 'dart:ui' as ui show Color, ColorFilter, Image;
77

88
import 'package:fake_async/fake_async.dart';
99
import 'package:flutter/foundation.dart';
@@ -14,6 +14,36 @@ import '../image_data.dart';
1414
import '../painting/mocks_for_image_cache.dart';
1515
import '../rendering/rendering_tester.dart';
1616

17+
/// Positive result if the colors would be mapped to the same argb8888 color.
18+
class _ColorMatcher extends Matcher {
19+
_ColorMatcher(this._target);
20+
21+
final ui.Color _target;
22+
23+
@override
24+
Description describe(Description description) {
25+
return description.add('matches "$_target"');
26+
}
27+
28+
@override
29+
bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
30+
if (item is ui.Color) {
31+
return item.colorSpace == _target.colorSpace &&
32+
(item.a - _target.a).abs() <= (1 / 255) &&
33+
(item.r - _target.r).abs() <= (1 / 255) &&
34+
(item.g - _target.g).abs() <= (1 / 255) &&
35+
(item.b - _target.b).abs() <= (1 / 255);
36+
} else {
37+
return false;
38+
}
39+
}
40+
41+
}
42+
43+
Matcher _matchesColor(ui.Color color) {
44+
return _ColorMatcher(color);
45+
}
46+
1747
class TestCanvas implements Canvas {
1848
final List<Invocation> invocations = <Invocation>[];
1949

@@ -326,7 +356,7 @@ void main() {
326356
expect(call.positionalArguments[3], isA<Paint>());
327357
final Paint paint = call.positionalArguments[3] as Paint;
328358
expect(paint.colorFilter, colorFilter);
329-
expect(paint.color, const Color(0x7F000000)); // 0.5 opacity
359+
expect(paint.color, _matchesColor(const Color(0x7F000000))); // 0.5 opacity
330360
expect(paint.filterQuality, FilterQuality.high);
331361
expect(paint.isAntiAlias, true);
332362
expect(paint.invertColors, isTrue);

0 commit comments

Comments
 (0)