Commit e7fbee66 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix clip debugPaint (TextPainter RTL fallout) (#12026)

parent 4262c1e9
...@@ -1039,6 +1039,7 @@ abstract class _RenderCustomClip<T> extends RenderProxyBox { ...@@ -1039,6 +1039,7 @@ abstract class _RenderCustomClip<T> extends RenderProxyBox {
fontSize: 14.0, fontSize: 14.0,
), ),
), ),
textDirection: TextDirection.rtl, // doesn't matter, it's one character
) )
..layout(); ..layout();
return true; return true;
......
...@@ -260,34 +260,46 @@ abstract class _TestRecordingCanvasMatcher extends Matcher { ...@@ -260,34 +260,46 @@ abstract class _TestRecordingCanvasMatcher extends Matcher {
bool matches(Object object, Map<dynamic, dynamic> matchState) { bool matches(Object object, Map<dynamic, dynamic> matchState) {
final TestRecordingCanvas canvas = new TestRecordingCanvas(); final TestRecordingCanvas canvas = new TestRecordingCanvas();
final TestRecordingPaintingContext context = new TestRecordingPaintingContext(canvas); final TestRecordingPaintingContext context = new TestRecordingPaintingContext(canvas);
if (object is _ContextPainterFunction) { final StringBuffer description = new StringBuffer();
final _ContextPainterFunction function = object; String prefixMessage = 'unexpectedly failed.';
function(context, Offset.zero); bool result = false;
} else if (object is _CanvasPainterFunction) { try {
final _CanvasPainterFunction function = object; if (object is _ContextPainterFunction) {
function(canvas); final _ContextPainterFunction function = object;
} else { function(context, Offset.zero);
if (object is Finder) { } else if (object is _CanvasPainterFunction) {
TestAsyncUtils.guardSync(); final _CanvasPainterFunction function = object;
final Finder finder = object; function(canvas);
object = finder.evaluate().single.renderObject;
}
if (object is RenderObject) {
final RenderObject renderObject = object;
renderObject.paint(context, Offset.zero);
} else { } else {
matchState[this] = 'was not one of the supported objects for the "paints" matcher.'; if (object is Finder) {
return false; TestAsyncUtils.guardSync();
final Finder finder = object;
object = finder.evaluate().single.renderObject;
}
if (object is RenderObject) {
final RenderObject renderObject = object;
renderObject.paint(context, Offset.zero);
} else {
matchState[this] = 'was not one of the supported objects for the "paints" matcher.';
return false;
}
} }
result = _evaluatePredicates(canvas.invocations, description);
if (!result)
prefixMessage = 'did not match the pattern.';
} catch (error, stack) {
prefixMessage = 'threw the following exception:';
description.writeln(error.toString());
description.write(stack.toString());
result = false;
} }
final StringBuffer description = new StringBuffer();
final bool result = _evaluatePredicates(canvas.invocations, description);
if (!result) { if (!result) {
if (canvas.invocations.isNotEmpty) if (canvas.invocations.isNotEmpty) {
description.write('The complete display list was:'); description.write('The complete display list was:');
for (RecordedInvocation call in canvas.invocations) for (RecordedInvocation call in canvas.invocations)
description.write('\n * $call'); description.write('\n * $call');
matchState[this] = 'did not match the pattern.\n$description'; }
matchState[this] = '$prefixMessage\n$description';
} }
return result; return result;
} }
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import '../rendering/mock_canvas.dart';
final List<String> log = <String>[]; final List<String> log = <String>[];
...@@ -223,4 +226,25 @@ void main() { ...@@ -223,4 +226,25 @@ void main() {
expect(log, equals(<String>['a', 'tap', 'a', 'b', 'c', 'tap'])); expect(log, equals(<String>['a', 'tap', 'a', 'b', 'c', 'tap']));
}); });
testWidgets('debugPaintSizeEnabled', (WidgetTester tester) async {
await tester.pumpWidget(
const ClipRect(
child: const Placeholder(),
),
);
expect(tester.renderObject(find.byType(ClipRect)).paint, paints
..save()
..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 600.0))
..save()
..path() // Placeholder
..restore()
..restore()
);
debugPaintSizeEnabled = true;
expect(tester.renderObject(find.byType(ClipRect)).debugPaint, paints // ignore: INVALID_USE_OF_PROTECTED_MEMBER
..rect(rect: new Rect.fromLTRB(0.0, 0.0, 800.0, 600.0))
..paragraph()
);
debugPaintSizeEnabled = false;
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment