Unverified Commit 12eeb94c authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Compare SemanticsHandler# at end of test to value at beginning of test (#18183)

parent 57187b00
...@@ -822,7 +822,12 @@ class PipelineOwner { ...@@ -822,7 +822,12 @@ class PipelineOwner {
SemanticsOwner get semanticsOwner => _semanticsOwner; SemanticsOwner get semanticsOwner => _semanticsOwner;
SemanticsOwner _semanticsOwner; SemanticsOwner _semanticsOwner;
int _outstandingSemanticsHandle = 0; /// The number of clients registered to listen for semantics.
///
/// The number is increased whenever [ensureSemantics] is called and decreased
/// when [SemanticsHandle.dispose] is called.
int get debugOutstandingSemanticsHandles => _outstandingSemanticsHandles;
int _outstandingSemanticsHandles = 0;
/// Opens a [SemanticsHandle] and calls [listener] whenever the semantics tree /// Opens a [SemanticsHandle] and calls [listener] whenever the semantics tree
/// updates. /// updates.
...@@ -837,8 +842,8 @@ class PipelineOwner { ...@@ -837,8 +842,8 @@ class PipelineOwner {
/// objects for a given [PipelineOwner] are closed, the [PipelineOwner] stops /// objects for a given [PipelineOwner] are closed, the [PipelineOwner] stops
/// maintaining the semantics tree. /// maintaining the semantics tree.
SemanticsHandle ensureSemantics({ VoidCallback listener }) { SemanticsHandle ensureSemantics({ VoidCallback listener }) {
_outstandingSemanticsHandle += 1; _outstandingSemanticsHandles += 1;
if (_outstandingSemanticsHandle == 1) { if (_outstandingSemanticsHandles == 1) {
assert(_semanticsOwner == null); assert(_semanticsOwner == null);
_semanticsOwner = new SemanticsOwner(); _semanticsOwner = new SemanticsOwner();
if (onSemanticsOwnerCreated != null) if (onSemanticsOwnerCreated != null)
...@@ -849,8 +854,8 @@ class PipelineOwner { ...@@ -849,8 +854,8 @@ class PipelineOwner {
void _didDisposeSemanticsHandle() { void _didDisposeSemanticsHandle() {
assert(_semanticsOwner != null); assert(_semanticsOwner != null);
_outstandingSemanticsHandle -= 1; _outstandingSemanticsHandles -= 1;
if (_outstandingSemanticsHandle == 0) { if (_outstandingSemanticsHandles == 0) {
_semanticsOwner.dispose(); _semanticsOwner.dispose();
_semanticsOwner = null; _semanticsOwner = null;
if (onSemanticsOwnerDisposed != null) if (onSemanticsOwnerDisposed != null)
......
...@@ -57,9 +57,10 @@ void testWidgets(String description, WidgetTesterCallback callback, { ...@@ -57,9 +57,10 @@ void testWidgets(String description, WidgetTesterCallback callback, {
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
final WidgetTester tester = new WidgetTester._(binding); final WidgetTester tester = new WidgetTester._(binding);
timeout ??= binding.defaultTestTimeout; timeout ??= binding.defaultTestTimeout;
test_package.test( test_package.test(
description, description,
() { () {
tester._recordNumberOfSemanticsHandles();
test_package.addTearDown(binding.postTest); test_package.addTearDown(binding.postTest);
return binding.runTest( return binding.runTest(
() => callback(tester), () => callback(tester),
...@@ -125,6 +126,7 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) { ...@@ -125,6 +126,7 @@ Future<Null> benchmarkWidgets(WidgetTesterCallback callback) {
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
assert(binding is! AutomatedTestWidgetsFlutterBinding); assert(binding is! AutomatedTestWidgetsFlutterBinding);
final WidgetTester tester = new WidgetTester._(binding); final WidgetTester tester = new WidgetTester._(binding);
tester._recordNumberOfSemanticsHandles();
return binding.runTest( return binding.runTest(
() => callback(tester), () => callback(tester),
tester._endOfTestVerifications, tester._endOfTestVerifications,
...@@ -523,7 +525,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -523,7 +525,8 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
} }
void _verifySemanticsHandlesWereDisposed() { void _verifySemanticsHandlesWereDisposed() {
if (binding.pipelineOwner.semanticsOwner != null) { assert(_lastRecordedSemanticsHandles != null);
if (binding.pipelineOwner.debugOutstandingSemanticsHandles > _lastRecordedSemanticsHandles) {
throw new FlutterError( throw new FlutterError(
'A SemanticsHandle was active at the end of the test.\n' 'A SemanticsHandle was active at the end of the test.\n'
'All SemanticsHandle instances must be disposed by calling dispose() on ' 'All SemanticsHandle instances must be disposed by calling dispose() on '
...@@ -532,6 +535,13 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker ...@@ -532,6 +535,13 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
'existing handle will leak into another test and alter its behavior.' 'existing handle will leak into another test and alter its behavior.'
); );
} }
_lastRecordedSemanticsHandles = null;
}
int _lastRecordedSemanticsHandles;
void _recordNumberOfSemanticsHandles() {
_lastRecordedSemanticsHandles = binding.pipelineOwner.debugOutstandingSemanticsHandles;
} }
/// Returns the TestTextInput singleton. /// Returns the TestTextInput singleton.
......
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