diff --git a/packages/flutter/lib/src/rendering/debug.dart b/packages/flutter/lib/src/rendering/debug.dart index 195b735666..3efd8bceca 100644 --- a/packages/flutter/lib/src/rendering/debug.dart +++ b/packages/flutter/lib/src/rendering/debug.dart @@ -7,40 +7,55 @@ import 'package:flutter/rendering.dart'; export 'package:flutter/foundation.dart' show debugPrint; +// Any changes to this file should be reflected in the debugAssertAllRenderVarsUnset() +// function below. + +const Color _kDebugPaintSizeColor = const Color(0xFF00FFFF); +const Color _kDebugPaintSpacingColor = const Color(0x90909090); +const Color _kDebugPaintPaddingColor = const Color(0x900090FF); +const Color _kDebugPaintPaddingInnerEdgeColor = const Color(0xFF0090FF); +const Color _kDebugPaintArrowColor = const Color(0xFFFFFF00); +const Color _kDebugPaintAlphabeticBaselineColor = const Color(0xFF00FF00); +const Color _kDebugPaintIdeographicBaselineColor = const Color(0xFFFFD000); +const Color _kDebugPaintLayerBordersColor = const Color(0xFFFF9800); +const int _kDebugPaintPointersColorValue = 0x00BBBB; +const HSVColor _kDebugCurrentRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0); +const double _kDebugRepaintRainbowHueIncrement = 2.0; + /// Causes each RenderBox to paint a box around its bounds, and some extra /// boxes, such as RenderPadding, to draw construction lines. bool debugPaintSizeEnabled = false; /// The color to use when painting RenderObject bounds. -Color debugPaintSizeColor = const Color(0xFF00FFFF); +Color debugPaintSizeColor = _kDebugPaintSizeColor; /// The color to use when painting some boxes that just add space (e.g. an empty /// RenderConstrainedBox or RenderPadding). -Color debugPaintSpacingColor = const Color(0x90909090); +Color debugPaintSpacingColor = _kDebugPaintSpacingColor; /// The color to use when painting RenderPadding edges. -Color debugPaintPaddingColor = const Color(0x900090FF); +Color debugPaintPaddingColor = _kDebugPaintPaddingColor; /// The color to use when painting RenderPadding edges. -Color debugPaintPaddingInnerEdgeColor = const Color(0xFF0090FF); +Color debugPaintPaddingInnerEdgeColor = _kDebugPaintPaddingInnerEdgeColor; /// The color to use when painting the arrows used to show RenderPositionedBox alignment. -Color debugPaintArrowColor = const Color(0xFFFFFF00); +Color debugPaintArrowColor = _kDebugPaintArrowColor; /// Causes each RenderBox to paint a line at each of its baselines. bool debugPaintBaselinesEnabled = false; /// The color to use when painting alphabetic baselines. -Color debugPaintAlphabeticBaselineColor = const Color(0xFF00FF00); +Color debugPaintAlphabeticBaselineColor = _kDebugPaintAlphabeticBaselineColor; /// The color ot use when painting ideographic baselines. -Color debugPaintIdeographicBaselineColor = const Color(0xFFFFD000); +Color debugPaintIdeographicBaselineColor = _kDebugPaintIdeographicBaselineColor; /// Causes each Layer to paint a box around its bounds. bool debugPaintLayerBordersEnabled = false; /// The color to use when painting Layer borders. -Color debugPaintLayerBordersColor = const Color(0xFFFF9800); +Color debugPaintLayerBordersColor = _kDebugPaintLayerBordersColor; /// Causes objects like [RenderPointerListener] to flash while they are being /// tapped. This can be useful to see how large the hit box is, e.g. when @@ -51,16 +66,16 @@ Color debugPaintLayerBordersColor = const Color(0xFFFF9800); bool debugPaintPointersEnabled = false; /// The color to use when reporting pointers for [debugPaintPointersEnabled]. -int debugPaintPointersColorValue = 0x00BBBB; +int debugPaintPointersColorValue = _kDebugPaintPointersColorValue; /// Overlay a rotating set of colors when repainting layers in checked mode. bool debugRepaintRainbowEnabled = false; /// The current color to overlay when repainting a layer. -HSVColor debugCurrentRepaintColor = const HSVColor.fromAHSV(0.4, 60.0, 1.0, 1.0); +HSVColor debugCurrentRepaintColor = _kDebugCurrentRepaintColor; /// The amount to increment the hue of the current repaint color. -double debugRepaintRainbowHueIncrement = 2.0; +double debugRepaintRainbowHueIncrement = _kDebugRepaintRainbowHueIncrement; /// Log the call stacks that mark render objects as needing paint. bool debugPrintMarkNeedsPaintStacks = false; @@ -89,3 +104,39 @@ List debugDescribeTransform(Matrix4 transform) { matrix.removeLast(); return matrix; } + +/// Returns true if none of the rendering library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [https://docs.flutter.io/flutter/rendering/rendering-library.html] for +/// a complete list. +bool debugAssertAllRenderVarsUnset(String reason) { + assert(() { + if (debugPaintSizeEnabled || + debugPaintBaselinesEnabled || + debugPaintLayerBordersEnabled || + debugPaintPointersEnabled || + debugRepaintRainbowEnabled || + debugPrintMarkNeedsPaintStacks || + debugPrintMarkNeedsLayoutStacks || + debugCheckIntrinsicSizes || + debugProfilePaintsEnabled || + debugPaintSizeColor != _kDebugPaintSizeColor || + debugPaintSpacingColor != _kDebugPaintSpacingColor || + debugPaintPaddingColor != _kDebugPaintPaddingColor || + debugPaintPaddingInnerEdgeColor != _kDebugPaintPaddingInnerEdgeColor || + debugPaintArrowColor != _kDebugPaintArrowColor || + debugPaintAlphabeticBaselineColor != _kDebugPaintAlphabeticBaselineColor || + debugPaintIdeographicBaselineColor != _kDebugPaintIdeographicBaselineColor || + debugPaintLayerBordersColor != _kDebugPaintLayerBordersColor || + debugPaintPointersColorValue != _kDebugPaintPointersColorValue || + debugCurrentRepaintColor != _kDebugCurrentRepaintColor || + debugRepaintRainbowHueIncrement != _kDebugRepaintRainbowHueIncrement) { + throw new FlutterError(reason); + } + return true; + }); + return true; +} diff --git a/packages/flutter/lib/src/scheduler/debug.dart b/packages/flutter/lib/src/scheduler/debug.dart index 6b374c4666..18b3fb49f8 100644 --- a/packages/flutter/lib/src/scheduler/debug.dart +++ b/packages/flutter/lib/src/scheduler/debug.dart @@ -2,6 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/foundation.dart'; + +// Any changes to this file should be reflected in the debugAssertAllSchedulerVarsUnset() +// function below. + /// Print a banner at the beginning of each frame. /// /// Frames triggered by the engine and handler by the scheduler binding will @@ -24,3 +29,21 @@ bool debugPrintBeginFrameBanner = false; /// Combined with [debugPrintBeginFrameBanner], this can be helpful for /// determining if code is running during a frame or between frames. bool debugPrintEndFrameBanner = false; + +/// Returns true if none of the scheduler library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [https://docs.flutter.io/flutter/scheduler/scheduler-library.html] for +/// a complete list. +bool debugAssertAllSchedulerVarsUnset(String reason) { + assert(() { + if (debugPrintBeginFrameBanner || + debugPrintEndFrameBanner) { + throw new FlutterError(reason); + } + return true; + }); + return true; +} diff --git a/packages/flutter/lib/src/widgets/debug.dart b/packages/flutter/lib/src/widgets/debug.dart index 6717547029..02841dea62 100644 --- a/packages/flutter/lib/src/widgets/debug.dart +++ b/packages/flutter/lib/src/widgets/debug.dart @@ -8,6 +8,9 @@ import 'package:flutter/foundation.dart'; import 'framework.dart'; import 'table.dart'; +// Any changes to this file should be reflected in the debugAssertAllWidgetVarsUnset() +// function below. + /// Log the dirty widgets that are built each frame. /// /// Combined with [debugPrintBuildScope] or [debugPrintBeginFrameBanner], this @@ -167,3 +170,24 @@ void debugWidgetBuilderValue(Widget widget, Widget built) { return true; }); } + +/// Returns true if none of the widget library debug variables have been changed. +/// +/// This function is used by the test framework to ensure that debug variables +/// haven't been inadvertently changed. +/// +/// See [https://docs.flutter.io/flutter/widgets/widgets-library.html] for +/// a complete list. +bool debugAssertAllWidgetVarsUnset(String reason) { + assert(() { + if (debugPrintRebuildDirtyWidgets || + debugPrintBuildScope || + debugPrintScheduleBuildForStacks || + debugPrintGlobalKeyedWidgetLifecycle || + debugProfileBuildsEnabled) { + throw new FlutterError(reason); + } + return true; + }); + return true; +} diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 5aef98f351..5e3483c21e 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -395,6 +395,15 @@ abstract class TestWidgetsFlutterBinding extends BindingBase assert(debugAssertNoTransientCallbacks( 'An animation is still running even after the widget tree was disposed.' )); + assert(debugAssertAllRenderVarsUnset( + 'The value of a rendering debug variable was changed by the test.' + )); + assert(debugAssertAllWidgetVarsUnset( + 'The value of a widget debug variable was changed by the test.' + )); + assert(debugAssertAllSchedulerVarsUnset( + 'The value of a scheduler debug variable was changed by the test.' + )); } /// Called by the [testWidgets] function after a test is executed.