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

Add a debug feature to the gestures library to dump hit test results (#11346)

parent 94ed7dce
......@@ -11,6 +11,7 @@ export 'src/gestures/arena.dart';
export 'src/gestures/binding.dart';
export 'src/gestures/constants.dart';
export 'src/gestures/converter.dart';
export 'src/gestures/debug.dart';
export 'src/gestures/drag.dart';
export 'src/gestures/drag_details.dart';
export 'src/gestures/events.dart';
......
......@@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart';
import 'arena.dart';
import 'converter.dart';
import 'debug.dart';
import 'events.dart';
import 'hit_test.dart';
import 'pointer_router.dart';
......@@ -75,6 +76,11 @@ abstract class GestureBinding extends BindingBase with HitTestable, HitTestDispa
result = new HitTestResult();
hitTest(result, event.position);
_hitTests[event.pointer] = result;
assert(() {
if (debugPrintHitTestResults)
debugPrint('$event: $result');
return true;
});
} else if (event is PointerUpEvent || event is PointerCancelEvent) {
result = _hitTests.remove(event.pointer);
} else if (event.down) {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// 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 debugAssertAllGesturesVarsUnset()
// function below.
/// Whether to print the results of each hit test to the console.
///
/// When this is set, in debug mode, any time a hit test is triggered by the
/// [GestureBinding] the results are dumped to the console.
///
/// This has no effect in release builds.
bool debugPrintHitTestResults = false;
/// Returns true if none of the gestures 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/gestures/gestures-library.html] for
/// a complete list.
bool debugAssertAllGesturesVarsUnset(String reason) {
assert(() {
if (debugPrintHitTestResults)
throw new FlutterError(reason);
return true;
});
return true;
}
......@@ -474,6 +474,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
'The value of a foundation debug variable was changed by the test.',
debugPrintOverride: debugPrintOverride,
));
assert(debugAssertAllGesturesVarsUnset(
'The value of a gestures debug variable was changed by the test.',
));
assert(debugAssertAllRenderVarsUnset(
'The value of a rendering debug variable was changed by the test.',
debugCheckIntrinsicSizesOverride: checkIntrinsicSizes,
......
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